forked from apache/cloudstack-terraform-provider
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource_cloudstack_autoscale_vm_profile_test.go
More file actions
233 lines (193 loc) · 6.76 KB
/
Copy pathresource_cloudstack_autoscale_vm_profile_test.go
File metadata and controls
233 lines (193 loc) · 6.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
package cloudstack
import (
"fmt"
"testing"
"github.com/apache/cloudstack-go/v2/cloudstack"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccCloudStackAutoscaleVMProfile_basic(t *testing.T) {
t.Skip("Skipping due to bug in cloudstack-go library")
var vmProfile cloudstack.AutoScaleVmProfile
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudStackAutoscaleVMProfileDestroy,
Steps: []resource.TestStep{
{
Config: testAccCloudStackAutoscaleVMProfile_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudStackAutoscaleVMProfileExists("cloudstack_autoscale_vm_profile.foo", &vmProfile),
testAccCheckCloudStackAutoscaleVMProfileBasicAttributes(&vmProfile),
resource.TestCheckResourceAttr(
"cloudstack_autoscale_vm_profile.foo", "zone", "Sandbox-simulator"),
testAccCheckResourceMetadata(&vmProfile),
),
},
},
})
}
func TestAccCloudStackAutoscaleVMProfile_update(t *testing.T) {
t.Skip("Skipping due to bug in cloudstack-go library")
var vmProfile cloudstack.AutoScaleVmProfile
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudStackAutoscaleVMProfileDestroy,
Steps: []resource.TestStep{
{
Config: testAccCloudStackAutoscaleVMProfile_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudStackAutoscaleVMProfileExists("cloudstack_autoscale_vm_profile.foo", &vmProfile),
testAccCheckCloudStackAutoscaleVMProfileBasicAttributes(&vmProfile),
),
},
{
Config: testAccCloudStackAutoscaleVMProfile_update,
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudStackAutoscaleVMProfileExists(
"cloudstack_autoscale_vm_profile.foo", &vmProfile),
testAccCheckCloudStackAutoscaleVMProfileUpdatedAttributes(&vmProfile),
resource.TestCheckResourceAttr(
"cloudstack_autoscale_vm_profile.foo", "zone", "Sandbox-simulator"),
),
},
},
})
}
func testAccCheckResourceMetadata(vmProfile *cloudstack.AutoScaleVmProfile) resource.TestCheckFunc {
return func(s *terraform.State) error {
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
p := cs.Resourcemetadata.NewListResourceDetailsParams("AutoScaleVmProfile")
p.SetResourceid(vmProfile.Id)
response, err := cs.Resourcemetadata.ListResourceDetails(p)
if err != nil {
return err
}
metadata := make(map[string]string)
for _, item := range response.ResourceDetails {
metadata[item.Key] = item.Value
}
return testAccCheckTags(metadata, "terraform-meta", "true")
}
}
func testAccCheckCloudStackAutoscaleVMProfileExists(
n string, vmProfile *cloudstack.AutoScaleVmProfile) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No vmProfile ID is set")
}
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
avp, _, err := cs.AutoScale.GetAutoScaleVmProfileByID(rs.Primary.ID)
if err != nil {
return err
}
if avp.Id != rs.Primary.ID {
return fmt.Errorf("AutoScaleVMProfile not found")
}
*vmProfile = *avp
return nil
}
}
func testAccCheckCloudStackAutoscaleVMProfileBasicAttributes(
vmProfile *cloudstack.AutoScaleVmProfile) resource.TestCheckFunc {
return func(s *terraform.State) error {
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
serviceofferingid, e := retrieveID(cs, "service_offering", "Small Instance")
if e != nil {
return e.Error()
}
zoneid, e := retrieveID(cs, "zone", "Sandbox-simulator")
if e != nil {
return e.Error()
}
templateid, e := retrieveTemplateID(cs, zoneid, "CentOS 5.6 (64-bit) no GUI (Simulator)")
if e != nil {
return e.Error()
}
if vmProfile.Serviceofferingid != serviceofferingid {
return fmt.Errorf("Bad offering: %s", vmProfile.Serviceofferingid)
}
if vmProfile.Templateid != templateid {
return fmt.Errorf("Bad template: %s", vmProfile.Templateid)
}
if vmProfile.Zoneid != zoneid {
return fmt.Errorf("Bad zone: %s", vmProfile.Zoneid)
}
if vmProfile.Otherdeployparams != "displayname=display1&networkids=net1" {
return fmt.Errorf("Bad otherdeployparams: %s", vmProfile.Otherdeployparams)
}
return nil
}
}
func testAccCheckCloudStackAutoscaleVMProfileUpdatedAttributes(
vmProfile *cloudstack.AutoScaleVmProfile) resource.TestCheckFunc {
return func(s *terraform.State) error {
if vmProfile.Destroyvmgraceperiod != 10 {
return fmt.Errorf("Bad destroy_vm_grace_period: %d", vmProfile.Destroyvmgraceperiod)
}
return nil
}
}
func testAccCheckCloudStackAutoscaleVMProfileDestroy(s *terraform.State) error {
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
for _, rs := range s.RootModule().Resources {
if rs.Type != "cloudstack_autoscale_vm_profile" {
continue
}
if rs.Primary.ID == "" {
return fmt.Errorf("No vmProfile ID is set")
}
_, _, err := cs.AutoScale.GetAutoScaleVmProfileByID(rs.Primary.ID)
if err == nil {
return fmt.Errorf("AutoScaleVMProfile %s still exists", rs.Primary.ID)
}
}
return nil
}
var testAccCloudStackAutoscaleVMProfile_basic = `
resource "cloudstack_autoscale_vm_profile" "foo" {
service_offering = "Small Instance"
template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
zone = "Sandbox-simulator"
other_deploy_params = {
networkids = "net1"
displayname = "display1"
}
metadata = {
terraform-meta = "true"
}
}`
var testAccCloudStackAutoscaleVMProfile_update = `
resource "cloudstack_autoscale_vm_profile" "foo" {
service_offering = "Small Instance"
template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
zone = "Sandbox-simulator"
destroy_vm_grace_period = "10s"
other_deploy_params = {
networkids = "net1"
displayname = "display1"
}
}`