Try AWS Native preview for resources not in the classic version.
aws.ec2transitgateway.InstanceState
Explore with Pulumi AI
Try AWS Native preview for resources not in the classic version.
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
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var ubuntu = Aws.Ec2.GetAmi.Invoke(new()
{
MostRecent = true,
Filters = new[]
{
new Aws.Ec2.Inputs.GetAmiFilterInputArgs
{
Name = "name",
Values = new[]
{
"ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*",
},
},
new Aws.Ec2.Inputs.GetAmiFilterInputArgs
{
Name = "virtualization-type",
Values = new[]
{
"hvm",
},
},
},
Owners = new[]
{
"099720109477",
},
});
var testInstance = new Aws.Ec2.Instance("testInstance", new()
{
Ami = ubuntu.Apply(getAmiResult => getAmiResult.Id),
InstanceType = "t3.micro",
Tags =
{
{ "Name", "HelloWorld" },
},
});
var testInstanceState = new Aws.Ec2TransitGateway.InstanceState("testInstanceState", new()
{
InstanceId = testInstance.Id,
State = "stopped",
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2transitgateway"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
ubuntu, err := ec2.LookupAmi(ctx, &ec2.LookupAmiArgs{
MostRecent: pulumi.BoolRef(true),
Filters: []ec2.GetAmiFilter{
{
Name: "name",
Values: []string{
"ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*",
},
},
{
Name: "virtualization-type",
Values: []string{
"hvm",
},
},
},
Owners: []string{
"099720109477",
},
}, nil)
if err != nil {
return err
}
testInstance, err := ec2.NewInstance(ctx, "testInstance", &ec2.InstanceArgs{
Ami: *pulumi.String(ubuntu.Id),
InstanceType: pulumi.String("t3.micro"),
Tags: pulumi.StringMap{
"Name": pulumi.String("HelloWorld"),
},
})
if err != nil {
return err
}
_, err = ec2transitgateway.NewInstanceState(ctx, "testInstanceState", &ec2transitgateway.InstanceStateArgs{
InstanceId: testInstance.ID(),
State: pulumi.String("stopped"),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.Ec2Functions;
import com.pulumi.aws.ec2.inputs.GetAmiArgs;
import com.pulumi.aws.ec2.Instance;
import com.pulumi.aws.ec2.InstanceArgs;
import com.pulumi.aws.ec2transitgateway.InstanceState;
import com.pulumi.aws.ec2transitgateway.InstanceStateArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var ubuntu = Ec2Functions.getAmi(GetAmiArgs.builder()
.mostRecent(true)
.filters(
GetAmiFilterArgs.builder()
.name("name")
.values("ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*")
.build(),
GetAmiFilterArgs.builder()
.name("virtualization-type")
.values("hvm")
.build())
.owners("099720109477")
.build());
var testInstance = new Instance("testInstance", InstanceArgs.builder()
.ami(ubuntu.applyValue(getAmiResult -> getAmiResult.id()))
.instanceType("t3.micro")
.tags(Map.of("Name", "HelloWorld"))
.build());
var testInstanceState = new InstanceState("testInstanceState", InstanceStateArgs.builder()
.instanceId(testInstance.id())
.state("stopped")
.build());
}
}
import pulumi
import pulumi_aws as aws
ubuntu = aws.ec2.get_ami(most_recent=True,
filters=[
aws.ec2.GetAmiFilterArgs(
name="name",
values=["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"],
),
aws.ec2.GetAmiFilterArgs(
name="virtualization-type",
values=["hvm"],
),
],
owners=["099720109477"])
test_instance = aws.ec2.Instance("testInstance",
ami=ubuntu.id,
instance_type="t3.micro",
tags={
"Name": "HelloWorld",
})
test_instance_state = aws.ec2transitgateway.InstanceState("testInstanceState",
instance_id=test_instance.id,
state="stopped")
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const ubuntu = aws.ec2.getAmi({
mostRecent: true,
filters: [
{
name: "name",
values: ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"],
},
{
name: "virtualization-type",
values: ["hvm"],
},
],
owners: ["099720109477"],
});
const testInstance = new aws.ec2.Instance("testInstance", {
ami: ubuntu.then(ubuntu => ubuntu.id),
instanceType: "t3.micro",
tags: {
Name: "HelloWorld",
},
});
const testInstanceState = new aws.ec2transitgateway.InstanceState("testInstanceState", {
instanceId: testInstance.id,
state: "stopped",
});
resources:
testInstance:
type: aws:ec2:Instance
properties:
ami: ${ubuntu.id}
instanceType: t3.micro
tags:
Name: HelloWorld
testInstanceState:
type: aws:ec2transitgateway:InstanceState
properties:
instanceId: ${testInstance.id}
state: stopped
variables:
ubuntu:
fn::invoke:
Function: aws:ec2:getAmi
Arguments:
mostRecent: true
filters:
- name: name
values:
- ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*
- name: virtualization-type
values:
- hvm
owners:
- '099720109477'
Create InstanceState Resource
new InstanceState(name: string, args: InstanceStateArgs, opts?: CustomResourceOptions);
@overload
def InstanceState(resource_name: str,
opts: Optional[ResourceOptions] = None,
force: Optional[bool] = None,
instance_id: Optional[str] = None,
state: Optional[str] = None)
@overload
def InstanceState(resource_name: str,
args: InstanceStateArgs,
opts: Optional[ResourceOptions] = None)
func NewInstanceState(ctx *Context, name string, args InstanceStateArgs, opts ...ResourceOption) (*InstanceState, error)
public InstanceState(string name, InstanceStateArgs args, CustomResourceOptions? opts = null)
public InstanceState(String name, InstanceStateArgs args)
public InstanceState(String name, InstanceStateArgs args, CustomResourceOptions options)
type: aws:ec2transitgateway:InstanceState
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args InstanceStateArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args InstanceStateArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args InstanceStateArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args InstanceStateArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args InstanceStateArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
InstanceState Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
The InstanceState resource accepts the following input properties:
- Instance
Id string ID of the instance.
- State string
State of the instance. Valid values are
stopped
,running
.The following arguments are optional:
- Force bool
Whether to request a forced stop when
state
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
.
- Instance
Id string ID of the instance.
- State string
State of the instance. Valid values are
stopped
,running
.The following arguments are optional:
- Force bool
Whether to request a forced stop when
state
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
.
- instance
Id String ID of the instance.
- state String
State of the instance. Valid values are
stopped
,running
.The following arguments are optional:
- force Boolean
Whether to request a forced stop when
state
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
.
- instance
Id string ID of the instance.
- state string
State of the instance. Valid values are
stopped
,running
.The following arguments are optional:
- force boolean
Whether to request a forced stop when
state
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
.
- instance_
id str ID of the instance.
- state str
State of the instance. Valid values are
stopped
,running
.The following arguments are optional:
- force bool
Whether to request a forced stop when
state
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
.
- instance
Id String ID of the instance.
- state String
State of the instance. Valid values are
stopped
,running
.The following arguments are optional:
- force Boolean
Whether to request a forced stop when
state
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
.
Outputs
All input properties are implicitly available as output properties. Additionally, the InstanceState resource produces the following output properties:
- Id string
The provider-assigned unique ID for this managed resource.
- Id string
The provider-assigned unique ID for this managed resource.
- id String
The provider-assigned unique ID for this managed resource.
- id string
The provider-assigned unique ID for this managed resource.
- id str
The provider-assigned unique ID for this managed resource.
- id String
The provider-assigned unique ID for this managed resource.
Look up Existing InstanceState Resource
Get an existing InstanceState resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: InstanceStateState, opts?: CustomResourceOptions): InstanceState
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
force: Optional[bool] = None,
instance_id: Optional[str] = None,
state: Optional[str] = None) -> InstanceState
func GetInstanceState(ctx *Context, name string, id IDInput, state *InstanceStateState, opts ...ResourceOption) (*InstanceState, error)
public static InstanceState Get(string name, Input<string> id, InstanceStateState? state, CustomResourceOptions? opts = null)
public static InstanceState get(String name, Output<String> id, InstanceStateState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- Force bool
Whether to request a forced stop when
state
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
.- Instance
Id string ID of the instance.
- State string
State of the instance. Valid values are
stopped
,running
.The following arguments are optional:
- Force bool
Whether to request a forced stop when
state
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
.- Instance
Id string ID of the instance.
- State string
State of the instance. Valid values are
stopped
,running
.The following arguments are optional:
- force Boolean
Whether to request a forced stop when
state
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
.- instance
Id String ID of the instance.
- state String
State of the instance. Valid values are
stopped
,running
.The following arguments are optional:
- force boolean
Whether to request a forced stop when
state
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
.- instance
Id string ID of the instance.
- state string
State of the instance. Valid values are
stopped
,running
.The following arguments are optional:
- force bool
Whether to request a forced stop when
state
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
.- instance_
id str ID of the instance.
- state str
State of the instance. Valid values are
stopped
,running
.The following arguments are optional:
- force Boolean
Whether to request a forced stop when
state
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
.- instance
Id String ID of the instance.
- state String
State of the instance. Valid values are
stopped
,running
.The following arguments are optional:
Import
Using pulumi import
, import aws_ec2_instance_state
using the instance_id
attribute. For example:
$ pulumi import aws:ec2transitgateway/instanceState:InstanceState test i-02cae6557dfcf2f96
Package Details
- Repository
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
This Pulumi package is based on the
aws
Terraform Provider.
Try AWS Native preview for resources not in the classic version.