Skip to content

Commit 9bc01da

Browse files
committed
Reorder a few params to match the ordering in the docs
1 parent 4122210 commit 9bc01da

File tree

2 files changed

+37
-34
lines changed

2 files changed

+37
-34
lines changed

cloudstack/resource_cloudstack_autoscale_vm_profile.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,34 @@ func resourceCloudStackAutoScaleVMProfile() *schema.Resource {
1919
Delete: resourceCloudStackAutoScaleVMProfileDelete,
2020

2121
Schema: map[string]*schema.Schema{
22-
"zone": {
22+
"service_offering": {
2323
Type: schema.TypeString,
2424
Required: true,
2525
ForceNew: true,
2626
},
2727

28-
"service_offering": {
28+
"template": {
2929
Type: schema.TypeString,
3030
Required: true,
31-
ForceNew: true,
3231
},
3332

34-
"template": {
33+
"zone": {
3534
Type: schema.TypeString,
3635
Required: true,
36+
ForceNew: true,
3737
},
3838

39-
"other_deploy_params": {
40-
Type: schema.TypeMap,
39+
"destroy_vm_grace_period": {
40+
Type: schema.TypeString,
4141
Optional: true,
4242
Computed: true,
43-
ForceNew: true,
4443
},
4544

46-
"destroy_vm_grace_period": {
47-
Type: schema.TypeString,
45+
"other_deploy_params": {
46+
Type: schema.TypeMap,
4847
Optional: true,
4948
Computed: true,
49+
ForceNew: true,
5050
},
5151

5252
"metadata": metadataSchema(),
@@ -77,6 +77,14 @@ func resourceCloudStackAutoScaleVMProfileCreate(d *schema.ResourceData, meta int
7777

7878
p := cs.AutoScale.NewCreateAutoScaleVmProfileParams(serviceofferingid, templateid, zoneid)
7979

80+
if v, ok := d.GetOk("destroy_vm_grace_period"); ok {
81+
duration, err := time.ParseDuration(v.(string))
82+
if err != nil {
83+
return err
84+
}
85+
p.SetDestroyvmgraceperiod(int(duration.Seconds()))
86+
}
87+
8088
if v, ok := d.GetOk("other_deploy_params"); ok {
8189
otherMap := v.(map[string]interface{})
8290
result := url.Values{}
@@ -86,14 +94,6 @@ func resourceCloudStackAutoScaleVMProfileCreate(d *schema.ResourceData, meta int
8694
p.SetOtherdeployparams(result.Encode())
8795
}
8896

89-
if v, ok := d.GetOk("destroy_vm_grace_period"); ok {
90-
duration, err := time.ParseDuration(v.(string))
91-
if err != nil {
92-
return err
93-
}
94-
p.SetDestroyvmgraceperiod(int(duration.Seconds()))
95-
}
96-
9797
// Create the new vm profile
9898
r, err := cs.AutoScale.CreateAutoScaleVmProfile(p)
9999
if err != nil {
@@ -141,9 +141,11 @@ func resourceCloudStackAutoScaleVMProfileRead(d *schema.ResourceData, meta inter
141141
return err
142142
}
143143

144-
setValueOrID(d, "zone", zone.Name, p.Zoneid)
145144
setValueOrID(d, "service_offering", offering.Name, p.Serviceofferingid)
146145
setValueOrID(d, "template", template.Name, p.Templateid)
146+
setValueOrID(d, "zone", zone.Name, p.Zoneid)
147+
148+
d.Set("destroy_vm_grace_period", (time.Duration(p.Destroyvmgraceperiod) * time.Second).String())
147149

148150
if p.Otherdeployparams != "" {
149151
var values url.Values
@@ -158,8 +160,6 @@ func resourceCloudStackAutoScaleVMProfileRead(d *schema.ResourceData, meta inter
158160
d.Set("other_deploy_params", otherParams)
159161
}
160162

161-
d.Set("destroy_vm_grace_period", (time.Duration(p.Destroyvmgraceperiod) * time.Second).String())
162-
163163
metadata, err := getMetadata(cs, d, "AutoScaleVmProfile")
164164
if err != nil {
165165
return err

cloudstack/resource_cloudstack_autoscale_vm_profile_test.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ func testAccCheckCloudStackAutoscaleVMProfileExists(
110110
func testAccCheckCloudStackAutoscaleVMProfileBasicAttributes(
111111
vmProfile *cloudstack.AutoScaleVmProfile) resource.TestCheckFunc {
112112
return func(s *terraform.State) error {
113-
114113
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
115-
zoneid, e := retrieveID(cs, "zone", "Sandbox-simulator")
114+
115+
serviceofferingid, e := retrieveID(cs, "service_offering", "Small Instance")
116116
if e != nil {
117117
return e.Error()
118118
}
119119

120-
serviceofferingid, e := retrieveID(cs, "service_offering", "Small Instance")
120+
zoneid, e := retrieveID(cs, "zone", "Sandbox-simulator")
121121
if e != nil {
122122
return e.Error()
123123
}
@@ -127,10 +127,6 @@ func testAccCheckCloudStackAutoscaleVMProfileBasicAttributes(
127127
return e.Error()
128128
}
129129

130-
if vmProfile.Zoneid != zoneid {
131-
return fmt.Errorf("Bad zone: %s", vmProfile.Zoneid)
132-
}
133-
134130
if vmProfile.Serviceofferingid != serviceofferingid {
135131
return fmt.Errorf("Bad offering: %s", vmProfile.Serviceofferingid)
136132
}
@@ -139,6 +135,10 @@ func testAccCheckCloudStackAutoscaleVMProfileBasicAttributes(
139135
return fmt.Errorf("Bad template: %s", vmProfile.Templateid)
140136
}
141137

138+
if vmProfile.Zoneid != zoneid {
139+
return fmt.Errorf("Bad zone: %s", vmProfile.Zoneid)
140+
}
141+
142142
if vmProfile.Otherdeployparams != "displayname=display1&networkids=net1" {
143143
return fmt.Errorf("Bad otherdeployparams: %s", vmProfile.Otherdeployparams)
144144
}
@@ -182,26 +182,29 @@ func testAccCheckCloudStackAutoscaleVMProfileDestroy(s *terraform.State) error {
182182

183183
var testAccCloudStackAutoscaleVMProfile_basic = `
184184
resource "cloudstack_autoscale_vm_profile" "foo" {
185-
zone = "Sandbox-simulator"
186185
service_offering = "Small Instance"
187-
template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
186+
template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
187+
zone = "Sandbox-simulator"
188+
188189
other_deploy_params = {
189-
networkids = "net1"
190+
networkids = "net1"
190191
displayname = "display1"
191192
}
193+
192194
metadata = {
193195
terraform-meta = "true"
194196
}
195197
}`
196198

197199
var testAccCloudStackAutoscaleVMProfile_update = `
198200
resource "cloudstack_autoscale_vm_profile" "foo" {
199-
zone = "Sandbox-simulator"
200-
service_offering = "Small Instance"
201-
template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
201+
service_offering = "Small Instance"
202+
template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
203+
zone = "Sandbox-simulator"
202204
destroy_vm_grace_period = "10s"
205+
203206
other_deploy_params = {
204-
networkids = "net1"
207+
networkids = "net1"
205208
displayname = "display1"
206209
}
207210
}`

0 commit comments

Comments
 (0)