Resource
dcloud_instance
A virtual machine. Created running; terraform destroy terminates it and deletes its machine.
Example Usage
data "dcloud_images" "x86" {
architecture = "x86_64"
}
resource "dcloud_key_pair" "me" {
name = "me"
public_key = file("~/.ssh/id_ed25519.pub")
}
resource "dcloud_instance" "web" {
name = "web-1"
server_type = "standard-2"
image_id = [for i in data.dcloud_images.x86.items : i.id if i.name == "debian-13"][0]
vpc_id = dcloud_vpc.main.id
ssh_key_pair_id = dcloud_key_pair.me.id
security_group_ids = [dcloud_security_group.web.id]
user_data = file("cloud-init.yaml")
tags = { role = "web" }
}Schema
Optional
availability_zone_id(String) Zone to run in (de1a = Falkenstein, de1b = Nuremberg); default the subnet’s, else de1a. Must match^[a-z]+[0-9]+[a-z]$. Changing it replaces the resource.connect(Boolean) Deutsche Cloud Connect (default true): the machine keeps one outbound SSH connection to Deutsche Cloud so the console terminal and adding keys work with no inbound port. false: nothing is installed. Changing it replaces the resource.enable_public_ipv4(Boolean) Give the machine a public IPv4 (default true); false: IPv6 only, IPv4 out through the VPC’s NAT gateway if it has one Never returned by the API: not read back, and empty after an import. Changing it replaces the resource.iam_role_name(String) IAM role the machine acts as (needs iam:PassRole on it): it gets 60-minute credentials for it through its instance identity (ews-instance credentials), with no key in user data. Up to 64 characters. Must match^[\w+=,.@-]+$. Changing it replaces the resource.idle_suspend_minutes(Number) Own hosts only: suspend the machine (memory saved) after this many idle minutes; the next HTTPS request or SSH connection through the front wakes it. From 10 to 10080. Changing it replaces the resource.image_id(Number) Image id (see thedcloud_imagesdata source). Changing it replaces the resource.key_pair_id(String) Instead of sshKeyPairId: a Compute key pair (ec2 key-pairs); not both. A UUID. Changing it replaces the resource.machine_image_id(String) One of your machine images (ewi-…), to launch a copy of a snapshot. Must match^ewi-[0-9a-f]{6,32}$. Changing it replaces the resource.name(String) A display name; omitted: none. Up to 64 characters.os_patching(Boolean) Keep OS patched: install the platform patch reporter; security updates install nightly and reboots happen in the 02:00–05:00 UTC window. Ubuntu images only. Changing it replaces the resource.project(String) The project (its slug) the resource lives in. At create: this, else the provider'sproject, else Default. Changing it moves the resource and its parts; it is never replaced.public_hostname(String) Own hosts only: a name in one of your DNS zones (and *.name) that reaches this machine through the site’s front: HTTPS by SNI, SSH through the jump on port 2222. Needs dns:ChangeRecords on that zone; removed at terminate. Changing it replaces the resource.region_id(String) The region to launch in, e.g. de1 Defaults to the provider'sregion. Changing it replaces the resource.required_host_tags(List of String) Own hosts only: capability tags the machine’s host must carry (a name or name:value, e.g. fsync:high, cpu:a); only hosts with every one take it, else it waits saying which tag is missing. CLI: --required-host-tags fsync:high Changing it replaces the resource.security_group_ids(Set of String) Security groups to attach; omitted: none, so the instance is not filteredserver_type(String) Server type (see thedcloud_server_typesdata source). Changing it stops the instance, resizes it and starts it again.size_class(String) A size class instead of a provider type: s-2 (2 vCPU / 4 GiB), s-4 (4 / 8), s-8 (8 / 16), s-16 (16 / 32), m-4 (4 / 32), d-2 (2 dedicated / 8), d-8 (8 dedicated / 32), a-2, a-4, a-8, a-16 (ARM, as s-*); it becomes the smallest type of your provider that fits One of:s-2,s-4,s-8,s-16,m-4,d-2,d-8,a-2,a-4,a-8,a-16. Changing it replaces the resource.ssh_key_pair_id(String) A KMS SSH key pair (kms ssh-key-pairs). A UUID. Changing it replaces the resource.subnet_id(String) A subnet of the VPC: the instance gets a fixed private address in its range and runs in its zone. A UUID. Changing it replaces the resource.tags(Map of String) Tags, key → value. Once set here, only these keys are managed; tags Deutsche Cloud adds itself are left alone.user_data(String) Cloud-init user data, run once at first boot. Never returned by the API: not read back, and empty after an import. Changing it replaces the resource.volumes(String) Up to 4 extra volumes made with the instance in its zone, attached once it runs (needs ec2:CreateVolume and ec2:AttachVolume); encrypted and deleted with the instance unless told otherwise. CLI: --volumes '{"sizeGib":40}' Changing it replaces the resource.vpc_id(String) The VPC to join; omitted: the region’s default VPC, created the first time it is needed. A UUID. Changing it replaces the resource.
Read-Only
id(String) The resource's id.private_ip(String) Address in the VPC.public_ip(String) Public IPv4 address, when the instance has one.state(String)pending,running,stopping,stopped,shutting-downorterminated.
Import
Import is supported using the following syntax:
The terraform import command can be used, for example:
# user_data and enable_public_ipv4 are never returned by the API and are empty after an import.
terraform import dcloud_instance.web i-0123abcdGenerated from the provider's schema.
Related