Skip to content

Commit

Permalink
Enhancing zone resource
Browse files Browse the repository at this point in the history
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
  • Loading branch information
poddm committed Aug 18, 2023
1 parent ea87939 commit 479cb46
Show file tree
Hide file tree
Showing 25 changed files with 2,161 additions and 42 deletions.
2 changes: 1 addition & 1 deletion cloudstack/data_source_cloudstack_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func dataSourceCloudstackZoneRead(d *schema.ResourceData, meta interface{}) erro
}

func zoneDescriptionAttributes(d *schema.ResourceData, zone *cloudstack.Zone) error {
d.SetId(zone.Name)
d.SetId(zone.Id)
d.Set("name", zone.Name)
d.Set("dns1", zone.Dns1)
d.Set("internal_dns1", zone.Internaldns1)
Expand Down
6 changes: 6 additions & 0 deletions cloudstack/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func Provider() terraform.ResourceProvider {
ResourcesMap: map[string]*schema.Resource{
"cloudstack_affinity_group": resourceCloudStackAffinityGroup(),
"cloudstack_autoscale_vm_profile": resourceCloudStackAutoScaleVMProfile(),
"cloudstack_cluster": resourceCloudStackCluster(),
"cloudstack_disk": resourceCloudStackDisk(),
"cloudstack_egress_firewall": resourceCloudStackEgressFirewall(),
"cloudstack_firewall": resourceCloudStackFirewall(),
Expand All @@ -106,15 +107,20 @@ func Provider() terraform.ResourceProvider {
"cloudstack_network_acl": resourceCloudStackNetworkACL(),
"cloudstack_network_acl_rule": resourceCloudStackNetworkACLRule(),
"cloudstack_nic": resourceCloudStackNIC(),
"cloudstack_physical_network": resourceCloudStackPhysicalNetwork(),
"cloudstack_pod": resourceCloudStackPod(),
"cloudstack_port_forward": resourceCloudStackPortForward(),
"cloudstack_private_gateway": resourceCloudStackPrivateGateway(),
"cloudstack_secondary_ipaddress": resourceCloudStackSecondaryIPAddress(),
"cloudstack_secondary_storage": resourceCloudStackSecondaryStorage(),
"cloudstack_security_group": resourceCloudStackSecurityGroup(),
"cloudstack_security_group_rule": resourceCloudStackSecurityGroupRule(),
"cloudstack_ssh_keypair": resourceCloudStackSSHKeyPair(),
"cloudstack_static_nat": resourceCloudStackStaticNAT(),
"cloudstack_static_route": resourceCloudStackStaticRoute(),
"cloudstack_storage_pool": resourceCloudStackStoragePool(),
"cloudstack_template": resourceCloudStackTemplate(),
"cloudstack_traffic_type": resourceCloudStackTrafficType(),
"cloudstack_vpc": resourceCloudStackVPC(),
"cloudstack_vpn_connection": resourceCloudStackVPNConnection(),
"cloudstack_vpn_customer_gateway": resourceCloudStackVPNCustomerGateway(),
Expand Down
243 changes: 243 additions & 0 deletions cloudstack/resource_cloudstack_cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
//
// 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 (
"github.com/apache/cloudstack-go/v2/cloudstack"
"github.com/hashicorp/terraform/helper/schema"
)

func resourceCloudStackCluster() *schema.Resource {
return &schema.Resource{
Create: resourceCloudStackClusterCreate,
Read: resourceCloudStackClusterRead,
Update: resourceCloudStackClusterUpdate,
Delete: resourceCloudStackClusterDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"allocation_state": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"cluster_name": {
Type: schema.TypeString,
Required: true,
},
"cluster_type": {
Type: schema.TypeString,
Required: true,
},
"guest_vswitch_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"guest_vswitch_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"hypervisor": {
Type: schema.TypeString,
Required: true,
},
"ovm3_cluster": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"ovm3_pool": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"ovm3_vip": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"password": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"public_vswitch_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"public_vswitch_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"pod_id": {
Type: schema.TypeString,
Required: true,
},
"url": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"username": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"vsm_ip_address": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"vsm_password": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"vsm_username": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"zone_id": {
Type: schema.TypeString,
Required: true,
},
},
}
}

func resourceCloudStackClusterCreate(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient)

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))
if v, ok := d.GetOk("allocation_state"); ok {
p.SetAllocationstate(v.(string))
}
if v, ok := d.GetOk("guest_vswitch_name"); ok {
p.SetGuestvswitchname(v.(string))
}
if v, ok := d.GetOk("guest_vswitch_type"); ok {
p.SetGuestvswitchtype(v.(string))
}
if v, ok := d.GetOk("hypervisor"); ok {
p.SetHypervisor(v.(string))
}
if v, ok := d.GetOk("ovm3_cluster"); ok {
p.SetOvm3cluster(v.(string))
}
if v, ok := d.GetOk("ovm3_pool"); ok {
p.SetOvm3pool(v.(string))
}
if v, ok := d.GetOk("ovm3_vip"); ok {
p.SetOvm3vip(v.(string))
}
if v, ok := d.GetOk("password"); ok {
p.SetPassword(v.(string))
}
if v, ok := d.GetOk("public_vswitch_name"); ok {
p.SetPublicvswitchname(v.(string))
}
if v, ok := d.GetOk("public_vswitch_type"); ok {
p.SetPublicvswitchtype(v.(string))
}
if v, ok := d.GetOk("url"); ok {
p.SetUrl(v.(string))
}
if v, ok := d.GetOk("username"); ok {
p.SetUsername(v.(string))
}
if v, ok := d.GetOk("vsm_ip_address"); ok {
p.SetVsmipaddress(v.(string))
}
if v, ok := d.GetOk("vsm_password"); ok {
p.SetVsmpassword(v.(string))
}
if v, ok := d.GetOk("vsm_username"); ok {
p.SetVsmusername(v.(string))
}

r, err := cs.Cluster.AddCluster(p)
if err != nil {
return err
}
d.SetId(r.Id)

return resourceCloudStackClusterRead(d, meta)
}

func resourceCloudStackClusterRead(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient)

r, _, err := cs.Cluster.GetClusterByID(d.Id())
if err != nil {
return err
}

d.Set("allocation_state", r.Allocationstate)
d.Set("cluster_type", r.Clustertype)
d.Set("hypervisor", r.Hypervisortype)
d.Set("cluster_name", r.Name)
d.Set("ovm3_vip", r.Ovm3vip)
d.Set("pod_id", r.Podid)
d.Set("zone_id", r.Zoneid)

return nil
}

func resourceCloudStackClusterUpdate(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient)

p := cs.Cluster.NewUpdateClusterParams(d.Id())
if v, ok := d.GetOk("allocation_state"); ok {
p.SetAllocationstate(v.(string))
}
if v, ok := d.GetOk("cluster_name"); ok {
p.SetClustername(v.(string))
}
if v, ok := d.GetOk("cluster_type"); ok {
p.SetClustertype(v.(string))
}
if v, ok := d.GetOk("hypervisor"); ok {
p.SetHypervisor(v.(string))
}

_, err := cs.Cluster.UpdateCluster(p)
if err != nil {
return err
}

return resourceCloudStackClusterRead(d, meta)
}

func resourceCloudStackClusterDelete(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient)

_, err := cs.Cluster.DeleteCluster(cs.Cluster.NewDeleteClusterParams(d.Id()))
if err != nil {
return err
}

return nil
}
75 changes: 75 additions & 0 deletions cloudstack/resource_cloudstack_cluster_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// 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 (
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestAccCloudStackCluster_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudStackCluster_basic,
},
// {
// Config: testAccCloudStackCluster_update,
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr("cloudstack_cluster.test", "name", "acctestupdated"),
// ),
// },
},
})
}

const testAccCloudStackCluster_basic = `
resource "cloudstack_zone" "test" {
name = "acctest"
dns1 = "8.8.8.8"
dns2 = "8.8.8.8"
internal_dns1 = "8.8.4.4"
internal_dns2 = "8.8.4.4"
network_type = "Advanced"
domain = "cloudstack.apache.org"
}
resource "cloudstack_pod" "test" {
allocation_state = "Disabled"
gateway = "172.29.0.1"
name = "accpod"
netmask = "255.255.240.0"
start_ip = "172.29.0.2"
zone_id = cloudstack_zone.test.id
}
resource "cloudstack_cluster" "test" {
cluster_name = "acccluster"
cluster_type = "CloudManaged"
hypervisor = "KVM"
pod_id = cloudstack_pod.test.id
zone_id = cloudstack_zone.test.id
}
`

const testAccCloudStackCluster_update = `
`
Loading

0 comments on commit 479cb46

Please sign in to comment.