1. Packages
  2. AWS Classic
  3. API Docs
  4. ec2transitgateway
  5. InstanceState

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.32.0 published on Friday, Apr 19, 2024 by Pulumi

aws.ec2transitgateway.InstanceState

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.32.0 published on Friday, Apr 19, 2024 by Pulumi

    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

    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 test = new aws.ec2.Instance("test", {
        ami: ubuntu.then(ubuntu => ubuntu.id),
        instanceType: aws.ec2.InstanceType.T3_Micro,
        tags: {
            Name: "HelloWorld",
        },
    });
    const testInstanceState = new aws.ec2transitgateway.InstanceState("test", {
        instanceId: test.id,
        state: "stopped",
    });
    
    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 = aws.ec2.Instance("test",
        ami=ubuntu.id,
        instance_type=aws.ec2.InstanceType.T3_MICRO,
        tags={
            "Name": "HelloWorld",
        })
    test_instance_state = aws.ec2transitgateway.InstanceState("test",
        instance_id=test.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
    		}
    		test, err := ec2.NewInstance(ctx, "test", &ec2.InstanceArgs{
    			Ami:          pulumi.String(ubuntu.Id),
    			InstanceType: pulumi.String(ec2.InstanceType_T3_Micro),
    			Tags: pulumi.StringMap{
    				"Name": pulumi.String("HelloWorld"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		_, err = ec2transitgateway.NewInstanceState(ctx, "test", &ec2transitgateway.InstanceStateArgs{
    			InstanceId: test.ID(),
    			State:      pulumi.String("stopped"),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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 test = new Aws.Ec2.Instance("test", new()
        {
            Ami = ubuntu.Apply(getAmiResult => getAmiResult.Id),
            InstanceType = Aws.Ec2.InstanceType.T3_Micro,
            Tags = 
            {
                { "Name", "HelloWorld" },
            },
        });
    
        var testInstanceState = new Aws.Ec2TransitGateway.InstanceState("test", new()
        {
            InstanceId = test.Id,
            State = "stopped",
        });
    
    });
    
    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 test = new Instance("test", 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(test.id())
                .state("stopped")
                .build());
    
        }
    }
    
    resources:
      test:
        type: aws:ec2:Instance
        properties:
          ami: ${ubuntu.id}
          instanceType: t3.micro
          tags:
            Name: HelloWorld
      testInstanceState:
        type: aws:ec2transitgateway:InstanceState
        name: test
        properties:
          instanceId: ${test.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

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new InstanceState(name: string, args: InstanceStateArgs, opts?: CustomResourceOptions);
    @overload
    def InstanceState(resource_name: str,
                      args: InstanceStateArgs,
                      opts: Optional[ResourceOptions] = None)
    
    @overload
    def InstanceState(resource_name: str,
                      opts: Optional[ResourceOptions] = None,
                      instance_id: Optional[str] = None,
                      state: Optional[str] = None,
                      force: Optional[bool] = 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.
    
    

    Parameters

    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.

    Example

    The following reference example uses placeholder values for all input properties.

    var instanceStateResource = new Aws.Ec2TransitGateway.InstanceState("instanceStateResource", new()
    {
        InstanceId = "string",
        State = "string",
        Force = false,
    });
    
    example, err := ec2transitgateway.NewInstanceState(ctx, "instanceStateResource", &ec2transitgateway.InstanceStateArgs{
    	InstanceId: pulumi.String("string"),
    	State:      pulumi.String("string"),
    	Force:      pulumi.Bool(false),
    })
    
    var instanceStateResource = new InstanceState("instanceStateResource", InstanceStateArgs.builder()        
        .instanceId("string")
        .state("string")
        .force(false)
        .build());
    
    instance_state_resource = aws.ec2transitgateway.InstanceState("instanceStateResource",
        instance_id="string",
        state="string",
        force=False)
    
    const instanceStateResource = new aws.ec2transitgateway.InstanceState("instanceStateResource", {
        instanceId: "string",
        state: "string",
        force: false,
    });
    
    type: aws:ec2transitgateway:InstanceState
    properties:
        force: false
        instanceId: string
        state: string
    

    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:

    InstanceId 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 is stopped. Otherwise (i.e., state is running), 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 to false.
    InstanceId 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 is stopped. Otherwise (i.e., state is running), 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 to false.
    instanceId 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 is stopped. Otherwise (i.e., state is running), 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 to false.
    instanceId 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 is stopped. Otherwise (i.e., state is running), 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 to false.
    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 is stopped. Otherwise (i.e., state is running), 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 to false.
    instanceId 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 is stopped. Otherwise (i.e., state is running), 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 to false.

    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.
    The following state arguments are supported:
    Force bool
    Whether to request a forced stop when state is stopped. Otherwise (i.e., state is running), 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 to false.
    InstanceId 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 is stopped. Otherwise (i.e., state is running), 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 to false.
    InstanceId 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 is stopped. Otherwise (i.e., state is running), 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 to false.
    instanceId 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 is stopped. Otherwise (i.e., state is running), 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 to false.
    instanceId 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 is stopped. Otherwise (i.e., state is running), 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 to false.
    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 is stopped. Otherwise (i.e., state is running), 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 to false.
    instanceId 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
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.32.0 published on Friday, Apr 19, 2024 by Pulumi