Skip to main content
Providers

Ec2Instance

A resource of the AWS provider, version 0.3.0, in its Compute group. Import it with:

import Ec2Instance from "aws/compute"

Example

resource Ec2Instance example {
    ami                             = "example-value"
    instanceType                    = "example-value"
    subnetId                        = "example-value"
    securityGroupIds                = "..."
    keyName                         = "example-value"
    associatePublicIpAddress        = false
    iamInstanceProfile              = "example-value"
    userData                        = "example-value"
    availabilityZone                = "example-value"
    monitoring                      = false
    tenancy                         = "default"
    rootVolumeSize                  = 3.14
    rootVolumeType                  = "gp3"
    deleteRootVolumeOnTermination   = true
    tags                            = "..."
    ebsOptimized                    = false
    cpuCredits                      = "standard"
    hibernation                     = false
    placementGroup                  = "example-value"
    metadataHttpTokens              = "optional"
    metadataHttpPutResponseHopLimit = 1
}

Properties

Set by your code in the resource block. A required one must be set; any other you leave out takes the value under Default, if it has one.

NameTypeDefaultRequiredDescription
amistring—NoThe AMI ID to use for the instance
instanceTypestring—NoThe instance type (e.g., t3.micro, m5.large)
subnetIdstring—NoThe subnet ID to launch the instance in
securityGroupIdsany[]—NoList of security group IDs to attach
keyNamestring—NoThe name of the key pair for SSH access
associatePublicIpAddressbooleanfalseNoWhether to associate a public IP address
iamInstanceProfilestring—NoThe IAM instance profile name or ARN
userDatastring—NoUser data script for instance initialization (base64 encoded)
availabilityZonestring—NoThe availability zone to launch in
monitoringbooleanfalseNoEnable detailed monitoring
tenancystring"default"NoInstance tenancy option Allowed: "default", "dedicated", "host"
rootVolumeSizenumber—NoRoot volume size in GiB
rootVolumeTypestring"gp3"NoRoot volume type Allowed: "gp2", "gp3", "io1", "io2", "st1", "sc1"
deleteRootVolumeOnTerminationbooleantrueNoDelete root volume on termination
tagsobject—NoTags to apply to the instance
ebsOptimizedbooleanfalseNoWhether the instance is optimized for Amazon EBS I/O
cpuCreditsstring—NoCPU credit option for burstable instances Allowed: "standard", "unlimited"
hibernationbooleanfalseNoWhether instance hibernation is enabled
placementGroupstring—NoThe name of the placement group for cluster networking
metadataHttpTokensstring"optional"NoHTTP tokens requirement for instance metadata service (IMDSv2) Allowed: "optional", "required"
metadataHttpPutResponseHopLimitnumber1NoHTTP PUT response hop limit for instance metadata requests (1-64)

Set by AWS after the resource is created: your code can read them but not set them. An importable one identifies an existing resource.

NameTypeImportableDescription
instanceIdstringNoThe instance ID assigned by AWS
statestringNoInstance state: pending, running, stopping, stopped, terminated
publicIpstringNoThe public IP address (if assigned)
privateIpstringNoThe private IP address
publicDnsNamestringNoThe public DNS name
privateDnsNamestringNoThe private DNS name
vpcIdstringNoThe VPC ID the instance is in
architecturestringNoThe architecture: x86_64 or arm64
rootDeviceNamestringNoThe root device name

On this page