1. Packages
  2. Alibaba Cloud Provider
  3. API Docs
  4. ots
  5. InstanceAttachment
Alibaba Cloud v3.76.0 published on Tuesday, Apr 8, 2025 by Pulumi

alicloud.ots.InstanceAttachment

Explore with Pulumi AI

This resource will help you to bind a VPC to an OTS instance.

NOTE: Available since v1.10.0.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as alicloud from "@pulumi/alicloud";
import * as random from "@pulumi/random";

const config = new pulumi.Config();
const name = config.get("name") || "tf-example";
const defaultInteger = new random.index.Integer("default", {
    min: 10000,
    max: 99999,
});
const defaultInstance = new alicloud.ots.Instance("default", {
    name: `${name}-${defaultInteger.result}`,
    description: name,
    accessedBy: "Vpc",
    tags: {
        Created: "TF",
        For: "example",
    },
});
const _default = alicloud.getZones({
    availableResourceCreation: "VSwitch",
});
const defaultNetwork = new alicloud.vpc.Network("default", {
    vpcName: name,
    cidrBlock: "10.4.0.0/16",
});
const defaultSwitch = new alicloud.vpc.Switch("default", {
    vswitchName: name,
    cidrBlock: "10.4.0.0/24",
    vpcId: defaultNetwork.id,
    zoneId: _default.then(_default => _default.zones?.[0]?.id),
});
const defaultInstanceAttachment = new alicloud.ots.InstanceAttachment("default", {
    instanceName: defaultInstance.name,
    vpcName: "examplename",
    vswitchId: defaultSwitch.id,
});
Copy
import pulumi
import pulumi_alicloud as alicloud
import pulumi_random as random

config = pulumi.Config()
name = config.get("name")
if name is None:
    name = "tf-example"
default_integer = random.index.Integer("default",
    min=10000,
    max=99999)
default_instance = alicloud.ots.Instance("default",
    name=f"{name}-{default_integer['result']}",
    description=name,
    accessed_by="Vpc",
    tags={
        "Created": "TF",
        "For": "example",
    })
default = alicloud.get_zones(available_resource_creation="VSwitch")
default_network = alicloud.vpc.Network("default",
    vpc_name=name,
    cidr_block="10.4.0.0/16")
default_switch = alicloud.vpc.Switch("default",
    vswitch_name=name,
    cidr_block="10.4.0.0/24",
    vpc_id=default_network.id,
    zone_id=default.zones[0].id)
default_instance_attachment = alicloud.ots.InstanceAttachment("default",
    instance_name=default_instance.name,
    vpc_name="examplename",
    vswitch_id=default_switch.id)
Copy
package main

import (
	"fmt"

	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud"
	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/ots"
	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/vpc"
	"github.com/pulumi/pulumi-random/sdk/v4/go/random"
	"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, "")
		name := "tf-example"
		if param := cfg.Get("name"); param != "" {
			name = param
		}
		defaultInteger, err := random.NewInteger(ctx, "default", &random.IntegerArgs{
			Min: 10000,
			Max: 99999,
		})
		if err != nil {
			return err
		}
		defaultInstance, err := ots.NewInstance(ctx, "default", &ots.InstanceArgs{
			Name:        pulumi.Sprintf("%v-%v", name, defaultInteger.Result),
			Description: pulumi.String(name),
			AccessedBy:  pulumi.String("Vpc"),
			Tags: pulumi.StringMap{
				"Created": pulumi.String("TF"),
				"For":     pulumi.String("example"),
			},
		})
		if err != nil {
			return err
		}
		_default, err := alicloud.GetZones(ctx, &alicloud.GetZonesArgs{
			AvailableResourceCreation: pulumi.StringRef("VSwitch"),
		}, nil)
		if err != nil {
			return err
		}
		defaultNetwork, err := vpc.NewNetwork(ctx, "default", &vpc.NetworkArgs{
			VpcName:   pulumi.String(name),
			CidrBlock: pulumi.String("10.4.0.0/16"),
		})
		if err != nil {
			return err
		}
		defaultSwitch, err := vpc.NewSwitch(ctx, "default", &vpc.SwitchArgs{
			VswitchName: pulumi.String(name),
			CidrBlock:   pulumi.String("10.4.0.0/24"),
			VpcId:       defaultNetwork.ID(),
			ZoneId:      pulumi.String(_default.Zones[0].Id),
		})
		if err != nil {
			return err
		}
		_, err = ots.NewInstanceAttachment(ctx, "default", &ots.InstanceAttachmentArgs{
			InstanceName: defaultInstance.Name,
			VpcName:      pulumi.String("examplename"),
			VswitchId:    defaultSwitch.ID(),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;
using Random = Pulumi.Random;

return await Deployment.RunAsync(() => 
{
    var config = new Config();
    var name = config.Get("name") ?? "tf-example";
    var defaultInteger = new Random.Index.Integer("default", new()
    {
        Min = 10000,
        Max = 99999,
    });

    var defaultInstance = new AliCloud.Ots.Instance("default", new()
    {
        Name = $"{name}-{defaultInteger.Result}",
        Description = name,
        AccessedBy = "Vpc",
        Tags = 
        {
            { "Created", "TF" },
            { "For", "example" },
        },
    });

    var @default = AliCloud.GetZones.Invoke(new()
    {
        AvailableResourceCreation = "VSwitch",
    });

    var defaultNetwork = new AliCloud.Vpc.Network("default", new()
    {
        VpcName = name,
        CidrBlock = "10.4.0.0/16",
    });

    var defaultSwitch = new AliCloud.Vpc.Switch("default", new()
    {
        VswitchName = name,
        CidrBlock = "10.4.0.0/24",
        VpcId = defaultNetwork.Id,
        ZoneId = @default.Apply(@default => @default.Apply(getZonesResult => getZonesResult.Zones[0]?.Id)),
    });

    var defaultInstanceAttachment = new AliCloud.Ots.InstanceAttachment("default", new()
    {
        InstanceName = defaultInstance.Name,
        VpcName = "examplename",
        VswitchId = defaultSwitch.Id,
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.random.integer;
import com.pulumi.random.IntegerArgs;
import com.pulumi.alicloud.ots.Instance;
import com.pulumi.alicloud.ots.InstanceArgs;
import com.pulumi.alicloud.AlicloudFunctions;
import com.pulumi.alicloud.inputs.GetZonesArgs;
import com.pulumi.alicloud.vpc.Network;
import com.pulumi.alicloud.vpc.NetworkArgs;
import com.pulumi.alicloud.vpc.Switch;
import com.pulumi.alicloud.vpc.SwitchArgs;
import com.pulumi.alicloud.ots.InstanceAttachment;
import com.pulumi.alicloud.ots.InstanceAttachmentArgs;
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 name = config.get("name").orElse("tf-example");
        var defaultInteger = new Integer("defaultInteger", IntegerArgs.builder()
            .min(10000)
            .max(99999)
            .build());

        var defaultInstance = new Instance("defaultInstance", InstanceArgs.builder()
            .name(String.format("%s-%s", name,defaultInteger.result()))
            .description(name)
            .accessedBy("Vpc")
            .tags(Map.ofEntries(
                Map.entry("Created", "TF"),
                Map.entry("For", "example")
            ))
            .build());

        final var default = AlicloudFunctions.getZones(GetZonesArgs.builder()
            .availableResourceCreation("VSwitch")
            .build());

        var defaultNetwork = new Network("defaultNetwork", NetworkArgs.builder()
            .vpcName(name)
            .cidrBlock("10.4.0.0/16")
            .build());

        var defaultSwitch = new Switch("defaultSwitch", SwitchArgs.builder()
            .vswitchName(name)
            .cidrBlock("10.4.0.0/24")
            .vpcId(defaultNetwork.id())
            .zoneId(default_.zones()[0].id())
            .build());

        var defaultInstanceAttachment = new InstanceAttachment("defaultInstanceAttachment", InstanceAttachmentArgs.builder()
            .instanceName(defaultInstance.name())
            .vpcName("examplename")
            .vswitchId(defaultSwitch.id())
            .build());

    }
}
Copy
configuration:
  name:
    type: string
    default: tf-example
resources:
  defaultInteger:
    type: random:integer
    name: default
    properties:
      min: 10000
      max: 99999
  defaultInstance:
    type: alicloud:ots:Instance
    name: default
    properties:
      name: ${name}-${defaultInteger.result}
      description: ${name}
      accessedBy: Vpc
      tags:
        Created: TF
        For: example
  defaultNetwork:
    type: alicloud:vpc:Network
    name: default
    properties:
      vpcName: ${name}
      cidrBlock: 10.4.0.0/16
  defaultSwitch:
    type: alicloud:vpc:Switch
    name: default
    properties:
      vswitchName: ${name}
      cidrBlock: 10.4.0.0/24
      vpcId: ${defaultNetwork.id}
      zoneId: ${default.zones[0].id}
  defaultInstanceAttachment:
    type: alicloud:ots:InstanceAttachment
    name: default
    properties:
      instanceName: ${defaultInstance.name}
      vpcName: examplename
      vswitchId: ${defaultSwitch.id}
variables:
  default:
    fn::invoke:
      function: alicloud:getZones
      arguments:
        availableResourceCreation: VSwitch
Copy

Create InstanceAttachment Resource

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

Constructor syntax

new InstanceAttachment(name: string, args: InstanceAttachmentArgs, opts?: CustomResourceOptions);
@overload
def InstanceAttachment(resource_name: str,
                       args: InstanceAttachmentArgs,
                       opts: Optional[ResourceOptions] = None)

@overload
def InstanceAttachment(resource_name: str,
                       opts: Optional[ResourceOptions] = None,
                       instance_name: Optional[str] = None,
                       vpc_name: Optional[str] = None,
                       vswitch_id: Optional[str] = None)
func NewInstanceAttachment(ctx *Context, name string, args InstanceAttachmentArgs, opts ...ResourceOption) (*InstanceAttachment, error)
public InstanceAttachment(string name, InstanceAttachmentArgs args, CustomResourceOptions? opts = null)
public InstanceAttachment(String name, InstanceAttachmentArgs args)
public InstanceAttachment(String name, InstanceAttachmentArgs args, CustomResourceOptions options)
type: alicloud:ots:InstanceAttachment
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. InstanceAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. InstanceAttachmentArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. InstanceAttachmentArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. InstanceAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. InstanceAttachmentArgs
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 exampleinstanceAttachmentResourceResourceFromOtsinstanceAttachment = new AliCloud.Ots.InstanceAttachment("exampleinstanceAttachmentResourceResourceFromOtsinstanceAttachment", new()
{
    InstanceName = "string",
    VpcName = "string",
    VswitchId = "string",
});
Copy
example, err := ots.NewInstanceAttachment(ctx, "exampleinstanceAttachmentResourceResourceFromOtsinstanceAttachment", &ots.InstanceAttachmentArgs{
	InstanceName: pulumi.String("string"),
	VpcName:      pulumi.String("string"),
	VswitchId:    pulumi.String("string"),
})
Copy
var exampleinstanceAttachmentResourceResourceFromOtsinstanceAttachment = new InstanceAttachment("exampleinstanceAttachmentResourceResourceFromOtsinstanceAttachment", InstanceAttachmentArgs.builder()
    .instanceName("string")
    .vpcName("string")
    .vswitchId("string")
    .build());
Copy
exampleinstance_attachment_resource_resource_from_otsinstance_attachment = alicloud.ots.InstanceAttachment("exampleinstanceAttachmentResourceResourceFromOtsinstanceAttachment",
    instance_name="string",
    vpc_name="string",
    vswitch_id="string")
Copy
const exampleinstanceAttachmentResourceResourceFromOtsinstanceAttachment = new alicloud.ots.InstanceAttachment("exampleinstanceAttachmentResourceResourceFromOtsinstanceAttachment", {
    instanceName: "string",
    vpcName: "string",
    vswitchId: "string",
});
Copy
type: alicloud:ots:InstanceAttachment
properties:
    instanceName: string
    vpcName: string
    vswitchId: string
Copy

InstanceAttachment 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 InstanceAttachment resource accepts the following input properties:

InstanceName
This property is required.
Changes to this property will trigger replacement.
string
The name of the OTS instance.
VpcName
This property is required.
Changes to this property will trigger replacement.
string
The name of attaching VPC to instance. It can only contain letters and numbers, must start with a letter, and is limited to 3-16 characters in length.
VswitchId
This property is required.
Changes to this property will trigger replacement.
string
The ID of attaching VSwitch to instance.
InstanceName
This property is required.
Changes to this property will trigger replacement.
string
The name of the OTS instance.
VpcName
This property is required.
Changes to this property will trigger replacement.
string
The name of attaching VPC to instance. It can only contain letters and numbers, must start with a letter, and is limited to 3-16 characters in length.
VswitchId
This property is required.
Changes to this property will trigger replacement.
string
The ID of attaching VSwitch to instance.
instanceName
This property is required.
Changes to this property will trigger replacement.
String
The name of the OTS instance.
vpcName
This property is required.
Changes to this property will trigger replacement.
String
The name of attaching VPC to instance. It can only contain letters and numbers, must start with a letter, and is limited to 3-16 characters in length.
vswitchId
This property is required.
Changes to this property will trigger replacement.
String
The ID of attaching VSwitch to instance.
instanceName
This property is required.
Changes to this property will trigger replacement.
string
The name of the OTS instance.
vpcName
This property is required.
Changes to this property will trigger replacement.
string
The name of attaching VPC to instance. It can only contain letters and numbers, must start with a letter, and is limited to 3-16 characters in length.
vswitchId
This property is required.
Changes to this property will trigger replacement.
string
The ID of attaching VSwitch to instance.
instance_name
This property is required.
Changes to this property will trigger replacement.
str
The name of the OTS instance.
vpc_name
This property is required.
Changes to this property will trigger replacement.
str
The name of attaching VPC to instance. It can only contain letters and numbers, must start with a letter, and is limited to 3-16 characters in length.
vswitch_id
This property is required.
Changes to this property will trigger replacement.
str
The ID of attaching VSwitch to instance.
instanceName
This property is required.
Changes to this property will trigger replacement.
String
The name of the OTS instance.
vpcName
This property is required.
Changes to this property will trigger replacement.
String
The name of attaching VPC to instance. It can only contain letters and numbers, must start with a letter, and is limited to 3-16 characters in length.
vswitchId
This property is required.
Changes to this property will trigger replacement.
String
The ID of attaching VSwitch to instance.

Outputs

All input properties are implicitly available as output properties. Additionally, the InstanceAttachment resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
VpcId string
The ID of attaching VPC to instance.
Id string
The provider-assigned unique ID for this managed resource.
VpcId string
The ID of attaching VPC to instance.
id String
The provider-assigned unique ID for this managed resource.
vpcId String
The ID of attaching VPC to instance.
id string
The provider-assigned unique ID for this managed resource.
vpcId string
The ID of attaching VPC to instance.
id str
The provider-assigned unique ID for this managed resource.
vpc_id str
The ID of attaching VPC to instance.
id String
The provider-assigned unique ID for this managed resource.
vpcId String
The ID of attaching VPC to instance.

Look up Existing InstanceAttachment Resource

Get an existing InstanceAttachment 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?: InstanceAttachmentState, opts?: CustomResourceOptions): InstanceAttachment
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        instance_name: Optional[str] = None,
        vpc_id: Optional[str] = None,
        vpc_name: Optional[str] = None,
        vswitch_id: Optional[str] = None) -> InstanceAttachment
func GetInstanceAttachment(ctx *Context, name string, id IDInput, state *InstanceAttachmentState, opts ...ResourceOption) (*InstanceAttachment, error)
public static InstanceAttachment Get(string name, Input<string> id, InstanceAttachmentState? state, CustomResourceOptions? opts = null)
public static InstanceAttachment get(String name, Output<String> id, InstanceAttachmentState state, CustomResourceOptions options)
resources:  _:    type: alicloud:ots:InstanceAttachment    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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:
InstanceName Changes to this property will trigger replacement. string
The name of the OTS instance.
VpcId string
The ID of attaching VPC to instance.
VpcName Changes to this property will trigger replacement. string
The name of attaching VPC to instance. It can only contain letters and numbers, must start with a letter, and is limited to 3-16 characters in length.
VswitchId Changes to this property will trigger replacement. string
The ID of attaching VSwitch to instance.
InstanceName Changes to this property will trigger replacement. string
The name of the OTS instance.
VpcId string
The ID of attaching VPC to instance.
VpcName Changes to this property will trigger replacement. string
The name of attaching VPC to instance. It can only contain letters and numbers, must start with a letter, and is limited to 3-16 characters in length.
VswitchId Changes to this property will trigger replacement. string
The ID of attaching VSwitch to instance.
instanceName Changes to this property will trigger replacement. String
The name of the OTS instance.
vpcId String
The ID of attaching VPC to instance.
vpcName Changes to this property will trigger replacement. String
The name of attaching VPC to instance. It can only contain letters and numbers, must start with a letter, and is limited to 3-16 characters in length.
vswitchId Changes to this property will trigger replacement. String
The ID of attaching VSwitch to instance.
instanceName Changes to this property will trigger replacement. string
The name of the OTS instance.
vpcId string
The ID of attaching VPC to instance.
vpcName Changes to this property will trigger replacement. string
The name of attaching VPC to instance. It can only contain letters and numbers, must start with a letter, and is limited to 3-16 characters in length.
vswitchId Changes to this property will trigger replacement. string
The ID of attaching VSwitch to instance.
instance_name Changes to this property will trigger replacement. str
The name of the OTS instance.
vpc_id str
The ID of attaching VPC to instance.
vpc_name Changes to this property will trigger replacement. str
The name of attaching VPC to instance. It can only contain letters and numbers, must start with a letter, and is limited to 3-16 characters in length.
vswitch_id Changes to this property will trigger replacement. str
The ID of attaching VSwitch to instance.
instanceName Changes to this property will trigger replacement. String
The name of the OTS instance.
vpcId String
The ID of attaching VPC to instance.
vpcName Changes to this property will trigger replacement. String
The name of attaching VPC to instance. It can only contain letters and numbers, must start with a letter, and is limited to 3-16 characters in length.
vswitchId Changes to this property will trigger replacement. String
The ID of attaching VSwitch to instance.

Package Details

Repository
Alibaba Cloud pulumi/pulumi-alicloud
License
Apache-2.0
Notes
This Pulumi package is based on the alicloud Terraform Provider.