Cloudstack Provider: Example Usage
Cloudstack Provider: Example Usage
The CloudStack provider is used to interact with the many resources supported by CloudStack. The provider needs to be
con gured with a URL pointing to a running CloudStack API and the proper credentials before it can be used.
In order to provide the required con guration options you can either supply values for the api_url , api_key and
secret_key elds, or for the config and profile elds. A combination of both is not allowed and will not work.
Use the navigation to the left to read about the available resources.
Example Usage
provider "cloudstack" {
api_url = "${var.cloudstack_api_url}"
api_key = "${var.cloudstack_api_key}"
secret_key = "${var.cloudstack_secret_key}"
}
Argument Reference
The following arguments are supported:
api_url - (Optional) This is the CloudStack API URL. It can also be sourced from the CLOUDSTACK_API_URL
environment variable.
api_key - (Optional) This is the CloudStack API key. It can also be sourced from the CLOUDSTACK_API_KEY
environment variable.
secret_key - (Optional) This is the CloudStack secret key. It can also be sourced from the CLOUDSTACK_SECRET_KEY
environment variable.
config - (Optional) The path to a CloudMonkey con g le. If set the API URL, key and secret will be retrieved from
this le.
profile - (Optional) Used together with the config option. Speci es which CloudMonkey pro le in the con g le to
use.
http_get_only - (Optional) Some cloud providers only allow HTTP GET calls to their CloudStack API. If using such a
provider, you need to set this to true in order for the provider to only make GET calls and no POST calls. It can also be
sourced from the CLOUDSTACK_HTTP_GET_ONLY environment variable.
timeout - (Optional) A value in seconds. This is the time allowed for Cloudstack to complete each asynchronous job
triggered. If unset, this can be sourced from the CLOUDSTACK_TIMEOUT environment variable. Otherwise, this will
default to 300 seconds.
cloudstack_template
Use this datasource to get the ID of a template for use in other resources.
Example Usage
filter {
name = "name"
value = "CentOS 7\\.1"
}
filter {
name = "hypervisor"
value = "KVM"
}
}
Argument Reference
template_filter - (Required) The template lter. Possible values are featured , self , selfexecutable ,
sharedexecutable , executable and community (see the Cloudstack API listTemplate command documentation).
filter - (Required) One or more name/value pairs to lter o of. You can apply lters on any exported attributes.
Attributes Reference
The following attributes are exported:
Example Usage
Argument Reference
The following arguments are supported:
name - (Required) The name of the a nity group. Changing this forces a new resource to be created.
type - (Required) The a nity group type. Changing this forces a new resource to be created.
project - (Optional) The name or ID of the project to register this a nity group to. Changing this forces a new
resource to be created.
Attributes Reference
The following attributes are exported:
Import
A nity groups can be imported; use <AFFINITY GROUP ID> as the import ID. For example:
When importing into a project you need to pre x the import ID with the project name:
Example Usage
Argument Reference
The following arguments are supported:
name - (Required) The name of the disk volume. Changing this forces a new resource to be created.
attach - (Optional) Determines whether or not to attach the disk volume to a virtual machine (defaults false).
device_id - (Optional) The device ID to map the disk volume to within the guest OS.
disk_offering - (Required) The name or ID of the disk o ering to use for this disk volume.
shrink_ok - (Optional) Veri es if the disk volume is allowed to shrink when resizing (defaults false).
virtual_machine_id - (Optional) The ID of the virtual machine to which you want to attach the disk volume.
project - (Optional) The name or ID of the project to deploy this instance to. Changing this forces a new resource to
be created.
zone - (Required) The name or ID of the zone where this disk volume will be available. Changing this forces a new
resource to be created.
Attributes Reference
The following attributes are exported:
device_id - The device ID the disk volume is mapped to within the guest OS.
Import
Disks can be imported; use <DISK ID> as the import ID. For example:
When importing into a project you need to pre x the import ID with the project name:
Example Usage
rule {
cidr_list = ["10.0.0.0/8"]
protocol = "tcp"
ports = ["80", "1000-2000"]
}
}
Argument Reference
The following arguments are supported:
network_id - (Required) The network ID for which to create the egress rewall rules. Changing this forces a new
resource to be created.
managed - (Optional) USE WITH CAUTION! If enabled all the egress rewall rules for this network will be managed by
this resource. This means it will delete all rewall rules that are not in your con g! (defaults false)
rule - (Optional) Can be speci ed multiple times. Each rule block supports elds documented below. If managed =
false at least one rule is required!
parallelism (Optional) Speci es how much rules will be created or deleted concurrently. (defaults 2)
protocol - (Required) The name of the protocol to allow. Valid options are: tcp , udp and icmp .
icmp_type - (Optional) The ICMP type to allow. This can only be speci ed if the protocol is ICMP.
icmp_code - (Optional) The ICMP code to allow. This can only be speci ed if the protocol is ICMP.
ports - (Optional) List of ports and/or port ranges to allow. This can only be speci ed if the protocol is TCP or UDP.
Attributes Reference
The following attributes are exported:
id - The network ID for which the egress rewall rules are created.
cloudstack_ rewall
Creates rewall rules for a given IP address.
Example Usage
rule {
cidr_list = ["10.0.0.0/8"]
protocol = "tcp"
ports = ["80", "1000-2000"]
}
}
Argument Reference
The following arguments are supported:
ip_address_id - (Required) The IP address ID for which to create the rewall rules. Changing this forces a new
resource to be created.
managed - (Optional) USE WITH CAUTION! If enabled all the rewall rules for this IP address will be managed by this
resource. This means it will delete all rewall rules that are not in your con g! (defaults false)
rule - (Optional) Can be speci ed multiple times. Each rule block supports elds documented below. If managed =
false at least one rule is required!
parallelism (Optional) Speci es how much rules will be created or deleted concurrently. (defaults 2)
protocol - (Required) The name of the protocol to allow. Valid options are: tcp , udp and icmp .
icmp_type - (Optional) The ICMP type to allow. This can only be speci ed if the protocol is ICMP.
icmp_code - (Optional) The ICMP code to allow. This can only be speci ed if the protocol is ICMP.
ports - (Optional) List of ports and/or port ranges to allow. This can only be speci ed if the protocol is TCP or UDP.
Attributes Reference
The following attributes are exported:
Example Usage
Argument Reference
The following arguments are supported:
service_offering - (Required) The name or ID of the service o ering used for this instance.
network_id - (Optional) The ID of the network to connect this instance to. Changing this forces a new resource to be
created.
ip_address - (Optional) The IP address to assign to this instance. Changing this forces a new resource to be created.
template - (Required) The name or ID of the template used for this instance. Changing this forces a new resource to
be created.
root_disk_size - (Optional) The size of the root disk in gigabytes. The root disk is resized on deploy. Only applies to
template-based deployments. Changing this forces a new resource to be created.
security_group_ids - (Optional) List of security group IDs to apply to this instance. Changing this forces a new
resource to be created.
security_group_names - (Optional) List of security group names to apply to this instance. Changing this forces a new
resource to be created.
project - (Optional) The name or ID of the project to deploy this instance to. Changing this forces a new resource to
be created.
zone - (Required) The name or ID of the zone where this instance will be created. Changing this forces a new resource
to be created.
start_vm - (Optional) This determines if the instances is started after it is created (defaults true)
user_data - (Optional) The user data to provide when launching the instance. This can be either plain text or base64
encoded text.
keypair - (Optional) The name of the SSH key pair that will be used to access this instance.
expunge - (Optional) This determines if the instance is expunged when it is destroyed (defaults false)
Attributes Reference
The following attributes are exported:
Import
Instances can be imported; use <INSTANCE ID> as the import ID. For example:
When importing into a project you need to pre x the import ID with the project name:
Example Usage
Argument Reference
The following arguments are supported:
is_portable - (Optional) This determines if the IP address should be transferable across zones (defaults false)
network_id - (Optional) The ID of the network for which an IP address should be acquired and associated. Changing
this forces a new resource to be created.
vpc_id - (Optional) The ID of the VPC for which an IP address should be acquired and associated. Changing this forces
a new resource to be created.
zone - (Optional) The name or ID of the zone for which an IP address should be acquired and associated. Changing
this forces a new resource to be created.
project - (Optional) The name or ID of the project to deploy this instance to. Changing this forces a new resource to
be created.
NOTE: network_id and/or zone should have a value when is_portable is false ! NOTE: Either network_id or vpc_id
should have a value when is_portable is true !
Attributes Reference
The following attributes are exported:
Example Usage
Argument Reference
The following arguments are supported:
name - (Required) Name of the loadbalancer rule. Changing this forces a new resource to be created.
ip_address_id - (Required) Public IP address ID from where the network tra c will be load balanced from. Changing
this forces a new resource to be created.
network_id - (Optional) The network ID this rule will be created for. Required when public IP address is not
associated with any network yet (VPC case).
algorithm - (Required) Load balancer rule algorithm (source, roundrobin, leastconn). Changing this forces a new
resource to be created.
private_port - (Required) The private port of the private IP address (virtual machine) where the network tra c will
be load balanced to. Changing this forces a new resource to be created.
public_port - (Required) The public port from where the network tra c will be load balanced from. Changing this
forces a new resource to be created.
protocol - (Optional) Load balancer protocol (tcp, udp, tcp-proxy). Changing this forces a new resource to be created.
member_ids - (Required) List of instance IDs to assign to the load balancer rule. Changing this forces a new resource
to be created.
project - (Optional) The name or ID of the project to deploy this instance to. Changing this forces a new resource to
be created.
Attributes Reference
The following attributes are exported:
Example Usage
Argument Reference
The following arguments are supported:
name - (Required) The name of the ACL. Changing this forces a new resource to be created.
description - (Optional) The description of the ACL. Changing this forces a new resource to be created.
project - (Optional) The name or ID of the project to deploy this instance to. Changing this forces a new resource to
be created.
vpc_id - (Required) The ID of the VPC to create this ACL for. Changing this forces a new resource to be created.
Attributes Reference
The following attributes are exported:
Import
Network ACLs can be imported; use <NETWORK ACL ID> as the import ID. For example:
When importing into a project you need to pre x the import ID with the project name:
Example Usage
rule {
action = "allow"
cidr_list = ["10.0.0.0/8"]
protocol = "tcp"
ports = ["80", "1000-2000"]
traffic_type = "ingress"
}
}
Argument Reference
The following arguments are supported:
acl_id - (Required) The network ACL ID for which to create the rules. Changing this forces a new resource to be
created.
managed - (Optional) USE WITH CAUTION! If enabled all the rewall rules for this network ACL will be managed by this
resource. This means it will delete all rewall rules that are not in your con g! (defaults false)
rule - (Optional) Can be speci ed multiple times. Each rule block supports elds documented below. If managed =
false at least one rule is required!
project - (Optional) The name or ID of the project to deploy this instance to. Changing this forces a new resource to
be created.
parallelism (Optional) Speci es how much rules will be created or deleted concurrently. (defaults 2)
action - (Optional) The action for the rule. Valid options are: allow and deny (defaults allow).
protocol - (Required) The name of the protocol to allow. Valid options are: tcp , udp , icmp , all or a valid protocol
number.
icmp_type - (Optional) The ICMP type to allow, or -1 to allow any . This can only be speci ed if the protocol is ICMP.
(defaults 0)
icmp_code - (Optional) The ICMP code to allow, or -1 to allow any . This can only be speci ed if the protocol is ICMP.
(defaults 0)
ports - (Optional) List of ports and/or port ranges to allow. This can only be speci ed if the protocol is TCP, UDP, ALL
or a valid protocol number.
traffic_type - (Optional) The tra c type for the rule. Valid options are: ingress or egress (defaults ingress).
Attributes Reference
The following attributes are exported:
Example Usage
Basic usage:
Argument Reference
The following arguments are supported:
cidr - (Required) The CIDR block for the network. Changing this forces a new resource to be created.
gateway - (Optional) Gateway that will be provided to the instances in this network. Defaults to the rst usable IP in
the range.
startip - (Optional) Start of the IP block that will be available on the network. Defaults to the second available IP in
the range.
endip - (Optional) End of the IP block that will be available on the network. Defaults to the last available IP in the
range.
network_offering - (Required) The name or ID of the network o ering to use for this network.
vlan - (Optional) The VLAN number (1-4095) the network will use. This might be required by the Network O ering if
specifyVlan=true is set. Only the ROOT admin can set this value.
vpc_id - (Optional) The VPC ID in which to create this network. Changing this forces a new resource to be created.
acl_id - (Optional) The ACL ID that should be attached to the network or none if you do not want to attach an ACL.
You can dynamically attach and swap ACL's, but if you want to detach an attached ACL and revert to using none , this
will force a new resource to be created. (defaults none )
project - (Optional) The name or ID of the project to deploy this instance to. Changing this forces a new resource to
be created.
source_nat_ip - (Optional) If set to true a public IP will be associated with the network. This is mainly used when
the network supports the source NAT service which claims the rst associated IP address. This prevents the ability to
manage the IP address as an independent entity.
zone - (Required) The name or ID of the zone where this network will be available. Changing this forces a new
resource to be created.
Attributes Reference
The following attributes are exported:
Import
Networks can be imported; use <NETWORK ID> as the import ID. For example:
When importing into a project you need to pre x the import ID with the project name:
Example Usage
Basic usage:
Argument Reference
The following arguments are supported:
network_id - (Required) The ID of the network to plug the NIC into. Changing this forces a new resource to be
created.
ip_address - (Optional) The IP address to assign to the NIC. Changing this forces a new resource to be created.
virtual_machine_id - (Required) The ID of the virtual machine to which to attach the NIC. Changing this forces a
new resource to be created.
Attributes Reference
The following attributes are exported:
Example Usage
forward {
protocol = "tcp"
private_port = 80
public_port = 8080
virtual_machine_id = "f8141e2f-4e7e-4c63-9362-986c908b7ea7"
}
}
Argument Reference
The following arguments are supported:
ip_address_id - (Required) The IP address ID for which to create the port forwards. Changing this forces a new
resource to be created.
managed - (Optional) USE WITH CAUTION! If enabled all the port forwards for this IP address will be managed by this
resource. This means it will delete all port forwards that are not in your con g! (defaults false)
project - (Optional) The name or ID of the project to create this port forward in. Changing this forces a new resource
to be created.
forward - (Required) Can be speci ed multiple times. Each forward block supports elds documented below.
protocol - (Required) The name of the protocol to allow. Valid options are: tcp and udp .
vm_guest_ip - (Optional) The virtual machine IP address for the port forwarding rule (useful when the virtual
machine has secondairy NICs or IP addresses).
Attributes Reference
The following attributes are exported:
id - The ID of the IP address for which the port forwards are created.
vm_guest_ip - The IP address of the virtual machine that is used for the port forwarding rule.
cloudstack_private_gateway
Creates a private gateway for the given VPC.
Example Usage
Argument Reference
The following arguments are supported:
gateway - (Required) the gateway of the Private gateway. Changing this forces a new resource to be created.
ip_address - (Required) the IP address of the Private gateway. Changing this forces a new resource to be created.
netmask - (Required) The netmask of the Private gateway. Changing this forces a new resource to be created.
vlan - (Required) The VLAN number (1-4095) the network will use.
physical_network_id - (Optional) The ID of the physical network this private gateway belongs to.
network_offering - (Optional) The name or ID of the network o ering to use for the private gateways network
connection.
vpc_id - (Required) The VPC ID in which to create this Private gateway. Changing this forces a new resource to be
created.
Attributes Reference
The following attributes are exported:
Import
Private gateways can be imported; use <PRIVATE GATEWAY ID> as the import ID. For example:
terraform import cloudstack_private_gateway.default e42a24d2-46cb-4b18-9d41-382582fad309
cloudstack_secondary_ipaddress
Assigns a secondary IP to a NIC.
Example Usage
Argument Reference
The following arguments are supported:
ip_address - (Optional) The IP address to bind the to NIC. If not supplied an IP address will be selected randomly.
Changing this forces a new resource to be created.
nic_id - (Optional) The NIC ID to which you want to attach the secondary IP address. Changing this forces a new
resource to be created (defaults to the ID of the primary NIC)
virtual_machine_id - (Required) The ID of the virtual machine to which you want to attach the secondary IP
address. Changing this forces a new resource to be created.
Attributes Reference
The following attributes are exported:
Example Usage
Argument Reference
The following arguments are supported:
name - (Required) The name of the security group. Changing this forces a new resource to be created.
description - (Optional) The description of the security group. Changing this forces a new resource to be created.
project - (Optional) The name or ID of the project to create this security group in. Changing this forces a new
resource to be created.
Attributes Reference
The following attributes are exported:
Import
Security groups can be imported; use <SECURITY GROUP ID> as the import ID. For example:
When importing into a project you need to pre x the import ID with the project name:
Example Usage
rule {
cidr_list = ["0.0.0.0/0"]
protocol = "tcp"
ports = ["80", "443"]
}
rule {
cidr_list = ["192.168.0.0/24", "192.168.1.0/25"]
protocol = "tcp"
ports = ["80-90", "443"]
traffic_type = "egress"
user_security_group_list = ["group01", "group02"]
}
}
Argument Reference
The following arguments are supported:
security_group_id - (Required) The security group ID for which to create the rules. Changing this forces a new
resource to be created.
rule - (Required) Can be speci ed multiple times. Each rule block supports elds documented below.
project - (Optional) The name or ID of the project in which the security group is created. Changing this forces a new
resource to be created.
parallelism (Optional) Speci es how much rules will be created or deleted concurrently. (defaults 2)
protocol - (Required) The name of the protocol to allow. Valid options are: tcp , udp , icmp , all or a valid protocol
number.
icmp_type - (Optional) The ICMP type to allow, or -1 to allow any . This can only be speci ed if the protocol is ICMP.
(defaults 0)
icmp_code - (Optional) The ICMP code to allow, or -1 to allow any . This can only be speci ed if the protocol is ICMP.
(defaults 0)
ports - (Optional) List of ports and/or port ranges to allow. This can only be speci ed if the protocol is TCP, UDP, ALL
or a valid protocol number.
traffic_type - (Optional) The tra c type for the rule. Valid options are: ingress or egress . (defaults ingress)
Attributes Reference
The following attributes are exported:
Example Usage
Argument Reference
The following arguments are supported:
name - (Required) The name of the SSH key pair. This is a unique value within a CloudStack account. Changing this
forces a new resource to be created.
public_key - (Optional) The public key to register with CloudStack. If this is omitted, CloudStack will generate a new
key pair. The key can be loaded from a le on disk using the file() function
(https://www.terraform.io/docs/con guration/functions/ le.html). Changing this forces a new resource to be created.
project - (Optional) The name or ID of the project to register this key to. Changing this forces a new resource to be
created.
Attributes Reference
The following attributes are exported:
private_key - The private key generated by CloudStack. Only available if CloudStack generated the key pair.
cloudstack_static_nat
Enables static NAT for a given IP address
Example Usage
Argument Reference
The following arguments are supported:
ip_address_id - (Required) The public IP address ID for which static NAT will be enabled. Changing this forces a new
resource to be created.
virtual_machine_id - (Required) The virtual machine ID to enable the static NAT feature for. Changing this forces a
new resource to be created.
vm_guest_ip - (Optional) The virtual machine IP address to forward the static NAT tra c to (useful when the virtual
machine has secondary NICs or IP addresses). Changing this forces a new resource to be created.
project - (Optional) The name or ID of the project to deploy this instance to. Changing this forces a new resource to
be created.
Attributes Reference
The following attributes are exported:
vm_guest_ip - The IP address of the virtual machine that is used to forward the static NAT tra c to.
cloudstack_static_route
Creates a static route for the given private gateway or VPC.
Example Usage
Argument Reference
The following arguments are supported:
cidr - (Required) The CIDR for the static route. Changing this forces a new resource to be created.
gateway_id - (Required) The ID of the Private gateway. Changing this forces a new resource to be created.
Attributes Reference
The following attributes are exported:
Example Usage
Argument Reference
The following arguments are supported:
format - (Required) The format of the template. Valid values are QCOW2 , RAW , and VHD .
hypervisor - (Required) The target hypervisor for the template. Changing this forces a new resource to be created.
os_type - (Required) The OS Type that best represents the OS of this template.
url - (Required) The URL of where the template is hosted. Changing this forces a new resource to be created.
project - (Optional) The name or ID of the project to create this template for. Changing this forces a new resource to
be created.
zone - (Optional) The name or ID of the zone where this template will be created. Changing this forces a new resource
to be created.
is_dynamically_scalable - (Optional) Set to indicate if the template contains tools to support dynamic scaling of
VM cpu/memory (defaults false)
is_public - (Optional) Set to indicate if the template is available for all accounts (defaults true)
password_enabled - (Optional) Set to indicate if the template should be password enabled (defaults false)
is_ready_timeout - (Optional) The maximum time in seconds to wait until the template is ready for use (defaults 300
seconds)
Attributes Reference
The following attributes are exported:
Example Usage
Basic usage:
Argument Reference
The following arguments are supported:
cidr - (Required) The CIDR block for the VPC. Changing this forces a new resource to be created.
vpc_offering - (Required) The name or ID of the VPC o ering to use for this VPC. Changing this forces a new
resource to be created.
network_domain - (Optional) The default DNS domain for networks created in this VPC. Changing this forces a new
resource to be created.
project - (Optional) The name or ID of the project to deploy this instance to. Changing this forces a new resource to
be created.
zone - (Required) The name or ID of the zone where this disk volume will be available. Changing this forces a new
resource to be created.
Attributes Reference
The following attributes are exported:
When importing into a project you need to pre x the import ID with the project name:
Example Usage
Basic usage:
Argument Reference
The following arguments are supported:
customer_gateway_id - (Required) The Customer Gateway ID to connect. Changing this forces a new resource to be
created.
vpn_gateway_id - (Required) The VPN Gateway ID to connect. Changing this forces a new resource to be created.
Attributes Reference
The following attributes are exported:
Example Usage
Basic usage:
Argument Reference
The following arguments are supported:
cidr - (Required) The CIDR block that needs to be routed through this gateway.
esp_policy - (Required) The ESP policy to use for this VPN Customer Gateway.
ike_policy - (Required) The IKE policy to use for this VPN Customer Gateway.
ipsec_psk - (Required) The IPSEC pre-shared key used for this gateway.
dpd - (Optional) If DPD is enabled for the related VPN connection (defaults false)
esp_lifetime - (Optional) The ESP lifetime of phase 2 VPN connection to this VPN Customer Gateway in seconds
(defaults 86400)
ike_lifetime - (Optional) The IKE lifetime of phase 2 VPN connection to this VPN Customer Gateway in seconds
(defaults 86400)
project - (Optional) The name or ID of the project to create this VPN Customer Gateway in. Changing this forces a
new resource to be created.
Attributes Reference
The following attributes are exported:
esp_lifetime - The ESP lifetime of phase 2 VPN connection to this VPN Customer Gateway.
ike_lifetime - The IKE lifetime of phase 2 VPN connection to this VPN Customer Gateway.
Import
VPN customer gateways can be imported; use <VPN CUSTOMER GATEWAY ID> as the import ID. For example:
When importing into a project you need to pre x the import ID with the project name:
Example Usage
Basic usage:
Argument Reference
The following arguments are supported:
vpc_id - (Required) The ID of the VPC for which to create the VPN Gateway. Changing this forces a new resource to be
created.
Attributes Reference
The following attributes are exported:
Import
VPC gateways can be imported; use <VPN GATEWAY ID> as the import ID. For example: