Skip to content

Commit 479cb46

Browse files
committed
Enhancing zone resource
Adding resource importer adding resource cloudstack_physical_network zone wizard resources Adding traffic type resource Zone formatting Adding resource pod Adding resource pod fixing zone allocations tate field Adding resource cluster Adding primary and secondary storage Update params options updating website docs
1 parent ea87939 commit 479cb46

25 files changed

+2161
-42
lines changed

cloudstack/data_source_cloudstack_zone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func dataSourceCloudstackZoneRead(d *schema.ResourceData, meta interface{}) erro
8787
}
8888

8989
func zoneDescriptionAttributes(d *schema.ResourceData, zone *cloudstack.Zone) error {
90-
d.SetId(zone.Name)
90+
d.SetId(zone.Id)
9191
d.Set("name", zone.Name)
9292
d.Set("dns1", zone.Dns1)
9393
d.Set("internal_dns1", zone.Internaldns1)

cloudstack/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func Provider() terraform.ResourceProvider {
9494
ResourcesMap: map[string]*schema.Resource{
9595
"cloudstack_affinity_group": resourceCloudStackAffinityGroup(),
9696
"cloudstack_autoscale_vm_profile": resourceCloudStackAutoScaleVMProfile(),
97+
"cloudstack_cluster": resourceCloudStackCluster(),
9798
"cloudstack_disk": resourceCloudStackDisk(),
9899
"cloudstack_egress_firewall": resourceCloudStackEgressFirewall(),
99100
"cloudstack_firewall": resourceCloudStackFirewall(),
@@ -106,15 +107,20 @@ func Provider() terraform.ResourceProvider {
106107
"cloudstack_network_acl": resourceCloudStackNetworkACL(),
107108
"cloudstack_network_acl_rule": resourceCloudStackNetworkACLRule(),
108109
"cloudstack_nic": resourceCloudStackNIC(),
110+
"cloudstack_physical_network": resourceCloudStackPhysicalNetwork(),
111+
"cloudstack_pod": resourceCloudStackPod(),
109112
"cloudstack_port_forward": resourceCloudStackPortForward(),
110113
"cloudstack_private_gateway": resourceCloudStackPrivateGateway(),
111114
"cloudstack_secondary_ipaddress": resourceCloudStackSecondaryIPAddress(),
115+
"cloudstack_secondary_storage": resourceCloudStackSecondaryStorage(),
112116
"cloudstack_security_group": resourceCloudStackSecurityGroup(),
113117
"cloudstack_security_group_rule": resourceCloudStackSecurityGroupRule(),
114118
"cloudstack_ssh_keypair": resourceCloudStackSSHKeyPair(),
115119
"cloudstack_static_nat": resourceCloudStackStaticNAT(),
116120
"cloudstack_static_route": resourceCloudStackStaticRoute(),
121+
"cloudstack_storage_pool": resourceCloudStackStoragePool(),
117122
"cloudstack_template": resourceCloudStackTemplate(),
123+
"cloudstack_traffic_type": resourceCloudStackTrafficType(),
118124
"cloudstack_vpc": resourceCloudStackVPC(),
119125
"cloudstack_vpn_connection": resourceCloudStackVPNConnection(),
120126
"cloudstack_vpn_customer_gateway": resourceCloudStackVPNCustomerGateway(),
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package cloudstack
21+
22+
import (
23+
"github.com/apache/cloudstack-go/v2/cloudstack"
24+
"github.com/hashicorp/terraform/helper/schema"
25+
)
26+
27+
func resourceCloudStackCluster() *schema.Resource {
28+
return &schema.Resource{
29+
Create: resourceCloudStackClusterCreate,
30+
Read: resourceCloudStackClusterRead,
31+
Update: resourceCloudStackClusterUpdate,
32+
Delete: resourceCloudStackClusterDelete,
33+
Importer: &schema.ResourceImporter{
34+
State: schema.ImportStatePassthrough,
35+
},
36+
Schema: map[string]*schema.Schema{
37+
"allocation_state": {
38+
Type: schema.TypeString,
39+
Optional: true,
40+
Computed: true,
41+
},
42+
"cluster_name": {
43+
Type: schema.TypeString,
44+
Required: true,
45+
},
46+
"cluster_type": {
47+
Type: schema.TypeString,
48+
Required: true,
49+
},
50+
"guest_vswitch_name": {
51+
Type: schema.TypeString,
52+
Optional: true,
53+
ForceNew: true,
54+
},
55+
"guest_vswitch_type": {
56+
Type: schema.TypeString,
57+
Optional: true,
58+
ForceNew: true,
59+
},
60+
"hypervisor": {
61+
Type: schema.TypeString,
62+
Required: true,
63+
},
64+
"ovm3_cluster": {
65+
Type: schema.TypeString,
66+
Optional: true,
67+
ForceNew: true,
68+
},
69+
"ovm3_pool": {
70+
Type: schema.TypeString,
71+
Optional: true,
72+
ForceNew: true,
73+
},
74+
"ovm3_vip": {
75+
Type: schema.TypeString,
76+
Optional: true,
77+
ForceNew: true,
78+
},
79+
"password": {
80+
Type: schema.TypeString,
81+
Optional: true,
82+
ForceNew: true,
83+
},
84+
"public_vswitch_name": {
85+
Type: schema.TypeString,
86+
Optional: true,
87+
ForceNew: true,
88+
},
89+
"public_vswitch_type": {
90+
Type: schema.TypeString,
91+
Optional: true,
92+
ForceNew: true,
93+
},
94+
"pod_id": {
95+
Type: schema.TypeString,
96+
Required: true,
97+
},
98+
"url": {
99+
Type: schema.TypeString,
100+
Optional: true,
101+
ForceNew: true,
102+
},
103+
"username": {
104+
Type: schema.TypeString,
105+
Optional: true,
106+
ForceNew: true,
107+
},
108+
"vsm_ip_address": {
109+
Type: schema.TypeString,
110+
Optional: true,
111+
ForceNew: true,
112+
},
113+
"vsm_password": {
114+
Type: schema.TypeString,
115+
Optional: true,
116+
ForceNew: true,
117+
},
118+
"vsm_username": {
119+
Type: schema.TypeString,
120+
Optional: true,
121+
ForceNew: true,
122+
},
123+
"zone_id": {
124+
Type: schema.TypeString,
125+
Required: true,
126+
},
127+
},
128+
}
129+
}
130+
131+
func resourceCloudStackClusterCreate(d *schema.ResourceData, meta interface{}) error {
132+
cs := meta.(*cloudstack.CloudStackClient)
133+
134+
p := cs.Cluster.NewAddClusterParams(d.Get("cluster_name").(string), d.Get("cluster_type").(string), d.Get("hypervisor").(string), d.Get("pod_id").(string), d.Get("zone_id").(string))
135+
if v, ok := d.GetOk("allocation_state"); ok {
136+
p.SetAllocationstate(v.(string))
137+
}
138+
if v, ok := d.GetOk("guest_vswitch_name"); ok {
139+
p.SetGuestvswitchname(v.(string))
140+
}
141+
if v, ok := d.GetOk("guest_vswitch_type"); ok {
142+
p.SetGuestvswitchtype(v.(string))
143+
}
144+
if v, ok := d.GetOk("hypervisor"); ok {
145+
p.SetHypervisor(v.(string))
146+
}
147+
if v, ok := d.GetOk("ovm3_cluster"); ok {
148+
p.SetOvm3cluster(v.(string))
149+
}
150+
if v, ok := d.GetOk("ovm3_pool"); ok {
151+
p.SetOvm3pool(v.(string))
152+
}
153+
if v, ok := d.GetOk("ovm3_vip"); ok {
154+
p.SetOvm3vip(v.(string))
155+
}
156+
if v, ok := d.GetOk("password"); ok {
157+
p.SetPassword(v.(string))
158+
}
159+
if v, ok := d.GetOk("public_vswitch_name"); ok {
160+
p.SetPublicvswitchname(v.(string))
161+
}
162+
if v, ok := d.GetOk("public_vswitch_type"); ok {
163+
p.SetPublicvswitchtype(v.(string))
164+
}
165+
if v, ok := d.GetOk("url"); ok {
166+
p.SetUrl(v.(string))
167+
}
168+
if v, ok := d.GetOk("username"); ok {
169+
p.SetUsername(v.(string))
170+
}
171+
if v, ok := d.GetOk("vsm_ip_address"); ok {
172+
p.SetVsmipaddress(v.(string))
173+
}
174+
if v, ok := d.GetOk("vsm_password"); ok {
175+
p.SetVsmpassword(v.(string))
176+
}
177+
if v, ok := d.GetOk("vsm_username"); ok {
178+
p.SetVsmusername(v.(string))
179+
}
180+
181+
r, err := cs.Cluster.AddCluster(p)
182+
if err != nil {
183+
return err
184+
}
185+
d.SetId(r.Id)
186+
187+
return resourceCloudStackClusterRead(d, meta)
188+
}
189+
190+
func resourceCloudStackClusterRead(d *schema.ResourceData, meta interface{}) error {
191+
cs := meta.(*cloudstack.CloudStackClient)
192+
193+
r, _, err := cs.Cluster.GetClusterByID(d.Id())
194+
if err != nil {
195+
return err
196+
}
197+
198+
d.Set("allocation_state", r.Allocationstate)
199+
d.Set("cluster_type", r.Clustertype)
200+
d.Set("hypervisor", r.Hypervisortype)
201+
d.Set("cluster_name", r.Name)
202+
d.Set("ovm3_vip", r.Ovm3vip)
203+
d.Set("pod_id", r.Podid)
204+
d.Set("zone_id", r.Zoneid)
205+
206+
return nil
207+
}
208+
209+
func resourceCloudStackClusterUpdate(d *schema.ResourceData, meta interface{}) error {
210+
cs := meta.(*cloudstack.CloudStackClient)
211+
212+
p := cs.Cluster.NewUpdateClusterParams(d.Id())
213+
if v, ok := d.GetOk("allocation_state"); ok {
214+
p.SetAllocationstate(v.(string))
215+
}
216+
if v, ok := d.GetOk("cluster_name"); ok {
217+
p.SetClustername(v.(string))
218+
}
219+
if v, ok := d.GetOk("cluster_type"); ok {
220+
p.SetClustertype(v.(string))
221+
}
222+
if v, ok := d.GetOk("hypervisor"); ok {
223+
p.SetHypervisor(v.(string))
224+
}
225+
226+
_, err := cs.Cluster.UpdateCluster(p)
227+
if err != nil {
228+
return err
229+
}
230+
231+
return resourceCloudStackClusterRead(d, meta)
232+
}
233+
234+
func resourceCloudStackClusterDelete(d *schema.ResourceData, meta interface{}) error {
235+
cs := meta.(*cloudstack.CloudStackClient)
236+
237+
_, err := cs.Cluster.DeleteCluster(cs.Cluster.NewDeleteClusterParams(d.Id()))
238+
if err != nil {
239+
return err
240+
}
241+
242+
return nil
243+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package cloudstack
21+
22+
import (
23+
"testing"
24+
25+
"github.com/hashicorp/terraform/helper/resource"
26+
)
27+
28+
func TestAccCloudStackCluster_basic(t *testing.T) {
29+
resource.Test(t, resource.TestCase{
30+
PreCheck: func() { testAccPreCheck(t) },
31+
Providers: testAccProviders,
32+
Steps: []resource.TestStep{
33+
{
34+
Config: testAccCloudStackCluster_basic,
35+
},
36+
// {
37+
// Config: testAccCloudStackCluster_update,
38+
// Check: resource.ComposeTestCheckFunc(
39+
// resource.TestCheckResourceAttr("cloudstack_cluster.test", "name", "acctestupdated"),
40+
// ),
41+
// },
42+
},
43+
})
44+
}
45+
46+
const testAccCloudStackCluster_basic = `
47+
resource "cloudstack_zone" "test" {
48+
name = "acctest"
49+
dns1 = "8.8.8.8"
50+
dns2 = "8.8.8.8"
51+
internal_dns1 = "8.8.4.4"
52+
internal_dns2 = "8.8.4.4"
53+
network_type = "Advanced"
54+
domain = "cloudstack.apache.org"
55+
}
56+
resource "cloudstack_pod" "test" {
57+
allocation_state = "Disabled"
58+
gateway = "172.29.0.1"
59+
name = "accpod"
60+
netmask = "255.255.240.0"
61+
start_ip = "172.29.0.2"
62+
zone_id = cloudstack_zone.test.id
63+
}
64+
resource "cloudstack_cluster" "test" {
65+
cluster_name = "acccluster"
66+
cluster_type = "CloudManaged"
67+
hypervisor = "KVM"
68+
pod_id = cloudstack_pod.test.id
69+
zone_id = cloudstack_zone.test.id
70+
}
71+
`
72+
73+
const testAccCloudStackCluster_update = `
74+
75+
`

0 commit comments

Comments
 (0)