Resource: awsEc2InstanceState
Provides an EC2 instance state resource. This allows managing an instance power state.
\~> NOTE on Instance State Management: AWS does not currently have an EC2 API operation to determine an instance has finished processing user data. As a result, this resource can interfere with user data processing. For example, this resource may stop an instance while the user data script is in mid run.
Example Usage
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const dataAwsAmiUbuntu = new aws.dataAwsAmi.DataAwsAmi(this, "ubuntu", {
filter: [
{
name: "name",
values: ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"],
},
{
name: "virtualization-type",
values: ["hvm"],
},
],
mostRecent: true,
owners: ["099720109477"],
});
const awsInstanceTest = new aws.instance.Instance(this, "test", {
ami: dataAwsAmiUbuntu.id,
instanceType: "t3.micro",
tags: {
Name: "HelloWorld",
},
});
const awsEc2InstanceStateTest = new aws.ec2InstanceState.Ec2InstanceState(
this,
"test_2",
{
instanceId: awsInstanceTest.id,
state: "stopped",
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsEc2InstanceStateTest.overrideLogicalId("test");
Argument Reference
The following arguments are required:
instanceId
- (Required) ID of the instance.state
- (Required) - State of the instance. Valid values arestopped
,running
.
The following arguments are optional:
force
- (Optional) Whether to request a forced stop whenstate
isstopped
. Otherwise (i.e.,state
isrunning
), ignored. When an instance is forced to stop, it does not flush file system caches or file system metadata, and you must subsequently perform file system check and repair. Not recommended for Windows instances. Defaults tofalse
.
Attributes Reference
In addition to all arguments above, the following attributes are exported:
id
- ID of the instance (matchesinstanceId
).
Timeouts
create
- (Default10M
)update
- (Default10M
)delete
- (Default1M
)
Import
awsEc2InstanceState
can be imported by using the instanceId
attribute, e.g.,