Expand description
Provides an EC2 instance resource. This allows instances to be created, updated, and deleted.
§Example Usage
§Basic example using AMI lookup
resources:
web:
type: aws:ec2:Instance
properties:
ami: ${ubuntu.id}
instanceType: t3.micro
tags:
Name: HelloWorld
variables:
ubuntu:
fn::invoke:
function: aws:ec2:getAmi
arguments:
mostRecent: true
filters:
- name: name
values:
- ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*
- name: virtualization-type
values:
- hvm
owners:
- '099720109477'
§Spot instance example
resources:
thisInstance:
type: aws:ec2:Instance
name: this
properties:
ami: ${this.id}
instanceMarketOptions:
marketType: spot
spotOptions:
maxPrice: 0.0031
instanceType: t4g.nano
tags:
Name: test-spot
variables:
this:
fn::invoke:
function: aws:ec2:getAmi
arguments:
mostRecent: true
owners:
- amazon
filters:
- name: architecture
values:
- arm64
- name: name
values:
- al2023-ami-2023*
§Network and credit specification example
resources:
myVpc:
type: aws:ec2:Vpc
name: my_vpc
properties:
cidrBlock: 172.16.0.0/16
tags:
Name: tf-example
mySubnet:
type: aws:ec2:Subnet
name: my_subnet
properties:
vpcId: ${myVpc.id}
cidrBlock: 172.16.10.0/24
availabilityZone: us-west-2a
tags:
Name: tf-example
foo:
type: aws:ec2:NetworkInterface
properties:
subnetId: ${mySubnet.id}
privateIps:
- 172.16.10.100
tags:
Name: primary_network_interface
fooInstance:
type: aws:ec2:Instance
name: foo
properties:
ami: ami-005e54dee72cc1d00
instanceType: t2.micro
networkInterfaces:
- networkInterfaceId: ${foo.id}
deviceIndex: 0
creditSpecification:
cpuCredits: unlimited
§CPU options example
resources:
example:
type: aws:ec2:Vpc
properties:
cidrBlock: 172.16.0.0/16
tags:
Name: tf-example
exampleSubnet:
type: aws:ec2:Subnet
name: example
properties:
vpcId: ${example.id}
cidrBlock: 172.16.10.0/24
availabilityZone: us-east-2a
tags:
Name: tf-example
exampleInstance:
type: aws:ec2:Instance
name: example
properties:
ami: ${["amzn-linux-2023-ami"].id}
instanceType: c6a.2xlarge
subnetId: ${exampleSubnet.id}
cpuOptions:
coreCount: 2
threadsPerCore: 2
tags:
Name: tf-example
variables:
amzn-linux-2023-ami:
fn::invoke:
function: aws:ec2:getAmi
arguments:
mostRecent: true
owners:
- amazon
filters:
- name: name
values:
- al2023-ami-2023.*-x86_64
§Host resource group or License Manager registered AMI example
A host resource group is a collection of Dedicated Hosts that you can manage as a single entity. As you launch instances, License Manager allocates the hosts and launches instances on them based on the settings that you configured. You can add existing Dedicated Hosts to a host resource group and take advantage of automated host management through License Manager.
NOTE: A dedicated host is automatically associated with a License Manager host resource group if Allocate hosts automatically is enabled. Otherwise, use the
host_resource_group_arn
argument to explicitly associate the instance with the host resource group.
use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
let this = instance::create(
"this",
InstanceArgs::builder()
.ami("ami-0dcc1e21636832c5d")
.host_resource_group_arn(
"arn:aws:resource-groups:us-west-2:123456789012:group/win-testhost",
)
.instance_type("m5.large")
.tenancy("host")
.build_struct(),
);
}
§Tag Guide
These are the five types of tags you might encounter relative to an aws.ec2.Instance
:
- Instance tags: Applied to instances but not to
ebs_block_device
androot_block_device
volumes. - Default tags: Applied to the instance and to
ebs_block_device
androot_block_device
volumes. - Volume tags: Applied during creation to
ebs_block_device
androot_block_device
volumes. - Root block device tags: Applied only to the
root_block_device
volume. These conflict withvolume_tags
. - EBS block device tags: Applied only to the specific
ebs_block_device
volume you configure them for and cannot be updated. These conflict withvolume_tags
.
Do not use volume_tags
if you plan to manage block device tags outside the aws.ec2.Instance
configuration, such as using tags
in an aws.ebs.Volume
resource attached via aws.ec2.VolumeAttachment
. Doing so will result in resource cycling and inconsistent behavior.
§Import
Using pulumi import
, import instances using the id
. For example:
$ pulumi import aws:ec2/instance:Instance web i-12345678
Structs§
- Use builder syntax to set the inputs and finish with
build_struct()
.
Functions§
- Registers a new resource with the given unique name and arguments