1. Packages
  2. Ucloud Provider
  3. API Docs
  4. InstanceState
ucloud 1.39.1 published on Monday, Apr 14, 2025 by ucloud

ucloud.InstanceState

Explore with Pulumi AI

ucloud logo
ucloud 1.39.1 published on Monday, Apr 14, 2025 by ucloud

    Provides an UHost Instance State resource. This allows managing an instance power state.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as ucloud from "@pulumi/ucloud";
    
    const config = new pulumi.Config();
    const availabilityZone = config.get("availabilityZone") || "cn-bj2-05";
    const _default = ucloud.getImages({
        availabilityZone: availabilityZone,
        nameRegex: "^CentOS 7.[1-2] 64",
        imageType: "base",
    });
    const fooInstance = new ucloud.Instance("fooInstance", {
        availabilityZone: availabilityZone,
        imageId: _default.then(_default => _default.images?.[0]?.id),
        instanceType: "n-highcpu-1",
        rootPassword: "wA1234567",
        chargeType: "month",
        duration: 0,
        tag: "tf-acc",
    });
    const fooInstanceState = new ucloud.InstanceState("fooInstanceState", {
        instanceId: fooInstance.instanceId,
        force: true,
        state: "Stopped",
    });
    
    import pulumi
    import pulumi_ucloud as ucloud
    
    config = pulumi.Config()
    availability_zone = config.get("availabilityZone")
    if availability_zone is None:
        availability_zone = "cn-bj2-05"
    default = ucloud.get_images(availability_zone=availability_zone,
        name_regex="^CentOS 7.[1-2] 64",
        image_type="base")
    foo_instance = ucloud.Instance("fooInstance",
        availability_zone=availability_zone,
        image_id=default.images[0].id,
        instance_type="n-highcpu-1",
        root_password="wA1234567",
        charge_type="month",
        duration=0,
        tag="tf-acc")
    foo_instance_state = ucloud.InstanceState("fooInstanceState",
        instance_id=foo_instance.instance_id,
        force=True,
        state="Stopped")
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-terraform-provider/sdks/go/ucloud/ucloud"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		cfg := config.New(ctx, "")
    		availabilityZone := "cn-bj2-05"
    		if param := cfg.Get("availabilityZone"); param != "" {
    			availabilityZone = param
    		}
    		_default, err := ucloud.GetImages(ctx, &ucloud.GetImagesArgs{
    			AvailabilityZone: pulumi.StringRef(availabilityZone),
    			NameRegex:        pulumi.StringRef("^CentOS 7.[1-2] 64"),
    			ImageType:        pulumi.StringRef("base"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		fooInstance, err := ucloud.NewInstance(ctx, "fooInstance", &ucloud.InstanceArgs{
    			AvailabilityZone: pulumi.String(availabilityZone),
    			ImageId:          pulumi.String(_default.Images[0].Id),
    			InstanceType:     pulumi.String("n-highcpu-1"),
    			RootPassword:     pulumi.String("wA1234567"),
    			ChargeType:       pulumi.String("month"),
    			Duration:         pulumi.Float64(0),
    			Tag:              pulumi.String("tf-acc"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = ucloud.NewInstanceState(ctx, "fooInstanceState", &ucloud.InstanceStateArgs{
    			InstanceId: fooInstance.InstanceId,
    			Force:      pulumi.Bool(true),
    			State:      pulumi.String("Stopped"),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Ucloud = Pulumi.Ucloud;
    
    return await Deployment.RunAsync(() => 
    {
        var config = new Config();
        var availabilityZone = config.Get("availabilityZone") ?? "cn-bj2-05";
        var @default = Ucloud.GetImages.Invoke(new()
        {
            AvailabilityZone = availabilityZone,
            NameRegex = "^CentOS 7.[1-2] 64",
            ImageType = "base",
        });
    
        var fooInstance = new Ucloud.Instance("fooInstance", new()
        {
            AvailabilityZone = availabilityZone,
            ImageId = @default.Apply(@default => @default.Apply(getImagesResult => getImagesResult.Images[0]?.Id)),
            InstanceType = "n-highcpu-1",
            RootPassword = "wA1234567",
            ChargeType = "month",
            Duration = 0,
            Tag = "tf-acc",
        });
    
        var fooInstanceState = new Ucloud.InstanceState("fooInstanceState", new()
        {
            InstanceId = fooInstance.InstanceId,
            Force = true,
            State = "Stopped",
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.ucloud.UcloudFunctions;
    import com.pulumi.ucloud.inputs.GetImagesArgs;
    import com.pulumi.ucloud.Instance;
    import com.pulumi.ucloud.InstanceArgs;
    import com.pulumi.ucloud.InstanceState;
    import com.pulumi.ucloud.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 config = ctx.config();
            final var availabilityZone = config.get("availabilityZone").orElse("cn-bj2-05");
            final var default = UcloudFunctions.getImages(GetImagesArgs.builder()
                .availabilityZone(availabilityZone)
                .nameRegex("^CentOS 7.[1-2] 64")
                .imageType("base")
                .build());
    
            var fooInstance = new Instance("fooInstance", InstanceArgs.builder()
                .availabilityZone(availabilityZone)
                .imageId(default_.images()[0].id())
                .instanceType("n-highcpu-1")
                .rootPassword("wA1234567")
                .chargeType("month")
                .duration(0)
                .tag("tf-acc")
                .build());
    
            var fooInstanceState = new InstanceState("fooInstanceState", InstanceStateArgs.builder()
                .instanceId(fooInstance.instanceId())
                .force(true)
                .state("Stopped")
                .build());
    
        }
    }
    
    configuration:
      availabilityZone:
        type: string
        default: cn-bj2-05
    resources:
      fooInstance:
        type: ucloud:Instance
        properties:
          availabilityZone: ${availabilityZone}
          imageId: ${default.images[0].id}
          instanceType: n-highcpu-1
          rootPassword: wA1234567
          chargeType: month
          duration: 0
          tag: tf-acc
      fooInstanceState:
        type: ucloud:InstanceState
        properties:
          instanceId: ${fooInstance.instanceId}
          force: true
          state: Stopped
    variables:
      default:
        fn::invoke:
          function: ucloud:getImages
          arguments:
            availabilityZone: ${availabilityZone}
            nameRegex: ^CentOS 7.[1-2] 64
            imageType: base
    

    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,
                      instance_state_id: Optional[str] = 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: ucloud: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.

    Constructor example

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

    var instanceStateResource = new Ucloud.InstanceState("instanceStateResource", new()
    {
        InstanceId = "string",
        State = "string",
        Force = false,
        InstanceStateId = "string",
    });
    
    example, err := ucloud.NewInstanceState(ctx, "instanceStateResource", &ucloud.InstanceStateArgs{
    	InstanceId:      pulumi.String("string"),
    	State:           pulumi.String("string"),
    	Force:           pulumi.Bool(false),
    	InstanceStateId: pulumi.String("string"),
    })
    
    var instanceStateResource = new InstanceState("instanceStateResource", InstanceStateArgs.builder()
        .instanceId("string")
        .state("string")
        .force(false)
        .instanceStateId("string")
        .build());
    
    instance_state_resource = ucloud.InstanceState("instanceStateResource",
        instance_id="string",
        state="string",
        force=False,
        instance_state_id="string")
    
    const instanceStateResource = new ucloud.InstanceState("instanceStateResource", {
        instanceId: "string",
        state: "string",
        force: false,
        instanceStateId: "string",
    });
    
    type: ucloud:InstanceState
    properties:
        force: false
        instanceId: string
        instanceStateId: 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

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    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 system caches and buffer. Defaults to false.
    InstanceStateId string
    ID of the instance (matches instance_id).
    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 system caches and buffer. Defaults to false.
    InstanceStateId string
    ID of the instance (matches instance_id).
    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 system caches and buffer. Defaults to false.
    instanceStateId String
    ID of the instance (matches instance_id).
    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 system caches and buffer. Defaults to false.
    instanceStateId string
    ID of the instance (matches instance_id).
    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 system caches and buffer. Defaults to false.
    instance_state_id str
    ID of the instance (matches instance_id).
    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 system caches and buffer. Defaults to false.
    instanceStateId String
    ID of the instance (matches instance_id).

    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,
            instance_state_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)
    resources:  _:    type: ucloud:InstanceState    get:      id: ${id}
    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 system caches and buffer. Defaults to false.
    InstanceId string
    ID of the instance.
    InstanceStateId string
    ID of the instance (matches instance_id).
    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 system caches and buffer. Defaults to false.
    InstanceId string
    ID of the instance.
    InstanceStateId string
    ID of the instance (matches instance_id).
    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 system caches and buffer. Defaults to false.
    instanceId String
    ID of the instance.
    instanceStateId String
    ID of the instance (matches instance_id).
    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 system caches and buffer. Defaults to false.
    instanceId string
    ID of the instance.
    instanceStateId string
    ID of the instance (matches instance_id).
    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 system caches and buffer. Defaults to false.
    instance_id str
    ID of the instance.
    instance_state_id str
    ID of the instance (matches instance_id).
    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 system caches and buffer. Defaults to false.
    instanceId String
    ID of the instance.
    instanceStateId String
    ID of the instance (matches instance_id).
    state String

    State of the instance. Valid values are Stopped, Running.

    The following arguments are optional:

    Import

    Using pulumi import, import ucloud_instance_state using the instance_id attribute. For example:

    $ pulumi import ucloud:index/instanceState:InstanceState test uhost-xyz
    

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

    Package Details

    Repository
    ucloud ucloud/terraform-provider-ucloud
    License
    Notes
    This Pulumi package is based on the ucloud Terraform Provider.
    ucloud logo
    ucloud 1.39.1 published on Monday, Apr 14, 2025 by ucloud