Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zonewizard #67

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 45 additions & 37 deletions cloudstack/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,43 +93,51 @@ func Provider() *schema.Provider {
},

ResourcesMap: map[string]*schema.Resource{
"cloudstack_affinity_group": resourceCloudStackAffinityGroup(),
"cloudstack_attach_volume": resourceCloudStackAttachVolume(),
"cloudstack_autoscale_vm_profile": resourceCloudStackAutoScaleVMProfile(),
"cloudstack_disk": resourceCloudStackDisk(),
"cloudstack_egress_firewall": resourceCloudStackEgressFirewall(),
"cloudstack_firewall": resourceCloudStackFirewall(),
"cloudstack_host": resourceCloudStackHost(),
"cloudstack_instance": resourceCloudStackInstance(),
"cloudstack_ipaddress": resourceCloudStackIPAddress(),
"cloudstack_kubernetes_cluster": resourceCloudStackKubernetesCluster(),
"cloudstack_kubernetes_version": resourceCloudStackKubernetesVersion(),
"cloudstack_loadbalancer_rule": resourceCloudStackLoadBalancerRule(),
"cloudstack_network": resourceCloudStackNetwork(),
"cloudstack_network_acl": resourceCloudStackNetworkACL(),
"cloudstack_network_acl_rule": resourceCloudStackNetworkACLRule(),
"cloudstack_nic": resourceCloudStackNIC(),
"cloudstack_port_forward": resourceCloudStackPortForward(),
"cloudstack_private_gateway": resourceCloudStackPrivateGateway(),
"cloudstack_secondary_ipaddress": resourceCloudStackSecondaryIPAddress(),
"cloudstack_security_group": resourceCloudStackSecurityGroup(),
"cloudstack_security_group_rule": resourceCloudStackSecurityGroupRule(),
"cloudstack_ssh_keypair": resourceCloudStackSSHKeyPair(),
"cloudstack_static_nat": resourceCloudStackStaticNAT(),
"cloudstack_static_route": resourceCloudStackStaticRoute(),
"cloudstack_template": resourceCloudStackTemplate(),
"cloudstack_vpc": resourceCloudStackVPC(),
"cloudstack_vpn_connection": resourceCloudStackVPNConnection(),
"cloudstack_vpn_customer_gateway": resourceCloudStackVPNCustomerGateway(),
"cloudstack_vpn_gateway": resourceCloudStackVPNGateway(),
"cloudstack_network_offering": resourceCloudStackNetworkOffering(),
"cloudstack_disk_offering": resourceCloudStackDiskOffering(),
"cloudstack_volume": resourceCloudStackVolume(),
"cloudstack_zone": resourceCloudStackZone(),
"cloudstack_service_offering": resourceCloudStackServiceOffering(),
"cloudstack_account": resourceCloudStackAccount(),
"cloudstack_user": resourceCloudStackUser(),
"cloudstack_domain": resourceCloudStackDomain(),
"cloudstack_affinity_group": resourceCloudStackAffinityGroup(),
"cloudstack_attach_volume": resourceCloudStackAttachVolume(),
"cloudstack_autoscale_vm_profile": resourceCloudStackAutoScaleVMProfile(),
"cloudstack_cluster": resourceCloudStackCluster(),
"cloudstack_disk": resourceCloudStackDisk(),
"cloudstack_egress_firewall": resourceCloudStackEgressFirewall(),
"cloudstack_firewall": resourceCloudStackFirewall(),
"cloudstack_host": resourceCloudStackHost(),
"cloudstack_instance": resourceCloudStackInstance(),
"cloudstack_ipaddress": resourceCloudStackIPAddress(),
"cloudstack_kubernetes_cluster": resourceCloudStackKubernetesCluster(),
"cloudstack_kubernetes_version": resourceCloudStackKubernetesVersion(),
"cloudstack_loadbalancer_rule": resourceCloudStackLoadBalancerRule(),
"cloudstack_network": resourceCloudStackNetwork(),
"cloudstack_network_acl": resourceCloudStackNetworkACL(),
"cloudstack_network_acl_rule": resourceCloudStackNetworkACLRule(),
"cloudstack_network_service_provider_state": resourceCloudStackNetworkServiceProviderState(),
"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(),
"cloudstack_vpn_gateway": resourceCloudStackVPNGateway(),
"cloudstack_network_offering": resourceCloudStackNetworkOffering(),
"cloudstack_disk_offering": resourceCloudStackDiskOffering(),
"cloudstack_vlan_ip_range": resourceCloudstackVlanIpRange(),
"cloudstack_volume": resourceCloudStackVolume(),
"cloudstack_zone": resourceCloudStackZone(),
"cloudstack_service_offering": resourceCloudStackServiceOffering(),
"cloudstack_account": resourceCloudStackAccount(),
"cloudstack_user": resourceCloudStackUser(),
"cloudstack_domain": resourceCloudStackDomain(),
},

ConfigureFunc: providerConfigure,
Expand Down
262 changes: 262 additions & 0 deletions cloudstack/resource_cloudstack_cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
//
// 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-plugin-sdk/v2/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": {
Description: "Allocation state of this cluster for allocation of new resources",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"cluster_name": {
Description: "the cluster name",
Type: schema.TypeString,
Required: true,
},
"cluster_type": {
Description: "ype of the cluster: CloudManaged, ExternalManaged",
Type: schema.TypeString,
Required: true,
},
"guest_vswitch_name": {
Description: "Name of virtual switch used for guest traffic in the cluster. This would override zone wide traffic label setting.",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"guest_vswitch_type": {
Description: "Type of virtual switch used for guest traffic in the cluster. Allowed values are, vmwaresvs (for VMware standard vSwitch) and vmwaredvs (for VMware distributed vSwitch)",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"hypervisor": {
Description: "hypervisor type of the cluster: XenServer,KVM,VMware,Hyperv,BareMetal,Simulator,Ovm3",
Type: schema.TypeString,
Required: true,
},
"ovm3_cluster": {
Description: "Ovm3 native OCFS2 clustering enabled for cluster",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"ovm3_pool": {
Description: "Ovm3 native pooling enabled for cluster",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"ovm3_vip": {
Description: "Ovm3 vip to use for pool (and cluster)",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"password": {
Description: "the password for the host",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"public_vswitch_name": {
Description: "Name of virtual switch used for public traffic in the cluster. This would override zone wide traffic label setting.",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"public_vswitch_type": {
Description: "Type of virtual switch used for public traffic in the cluster. Allowed values are, vmwaresvs (for VMware standard vSwitch) and vmwaredvs (for VMware distributed vSwitch)",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"pod_id": {
Description: "Type of virtual switch used for public traffic in the cluster. Allowed values are, vmwaresvs (for VMware standard vSwitch) and vmwaredvs (for VMware distributed vSwitch)",
Type: schema.TypeString,
Required: true,
},
"url": {
Description: "the URL",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"username": {
Description: "the username for the cluster",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"vsm_ip_address": {
Description: "the ipaddress of the VSM associated with this cluster",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"vsm_password": {
Description: "the password for the VSM associated with this cluster",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"vsm_username": {
Description: "the username for the VSM associated with this cluster",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"zone_id": {
Description: "the Zone ID for the cluster",
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
}
Loading
Loading