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

alicloud.ens.InstanceSecurityGroupAttachment

Explore with Pulumi AI

Provides a ENS Instance Security Group Attachment resource.

Bind instance and security group.

For information about ENS Instance Security Group Attachment and how to use it, see What is Instance Security Group Attachment.

NOTE: Available since v1.216.0.

Example Usage

Basic Usage

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

const config = new pulumi.Config();
const name = config.get("name") || "terraform-example";
const _default = new alicloud.ens.Instance("default", {
    systemDisk: {
        size: 20,
    },
    scheduleAreaLevel: "Region",
    imageId: "centos_6_08_64_20G_alibase_20171208",
    paymentType: "Subscription",
    instanceType: "ens.sn1.stiny",
    password: "12345678ABCabc",
    amount: 1,
    period: 1,
    internetMaxBandwidthOut: 10,
    publicIpIdentification: true,
    ensRegionId: "cn-chenzhou-telecom_unicom_cmcc",
    periodUnit: "Month",
});
const defaultSecurityGroup = new alicloud.ens.SecurityGroup("default", {
    description: "InstanceSecurityGroupAttachment_Description",
    securityGroupName: name,
});
const defaultInstanceSecurityGroupAttachment = new alicloud.ens.InstanceSecurityGroupAttachment("default", {
    instanceId: _default.id,
    securityGroupId: defaultSecurityGroup.id,
});
Copy
import pulumi
import pulumi_alicloud as alicloud

config = pulumi.Config()
name = config.get("name")
if name is None:
    name = "terraform-example"
default = alicloud.ens.Instance("default",
    system_disk={
        "size": 20,
    },
    schedule_area_level="Region",
    image_id="centos_6_08_64_20G_alibase_20171208",
    payment_type="Subscription",
    instance_type="ens.sn1.stiny",
    password="12345678ABCabc",
    amount=1,
    period=1,
    internet_max_bandwidth_out=10,
    public_ip_identification=True,
    ens_region_id="cn-chenzhou-telecom_unicom_cmcc",
    period_unit="Month")
default_security_group = alicloud.ens.SecurityGroup("default",
    description="InstanceSecurityGroupAttachment_Description",
    security_group_name=name)
default_instance_security_group_attachment = alicloud.ens.InstanceSecurityGroupAttachment("default",
    instance_id=default.id,
    security_group_id=default_security_group.id)
Copy
package main

import (
	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/ens"
	"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 := "terraform-example"
		if param := cfg.Get("name"); param != "" {
			name = param
		}
		_default, err := ens.NewInstance(ctx, "default", &ens.InstanceArgs{
			SystemDisk: &ens.InstanceSystemDiskArgs{
				Size: pulumi.Int(20),
			},
			ScheduleAreaLevel:       pulumi.String("Region"),
			ImageId:                 pulumi.String("centos_6_08_64_20G_alibase_20171208"),
			PaymentType:             pulumi.String("Subscription"),
			InstanceType:            pulumi.String("ens.sn1.stiny"),
			Password:                pulumi.String("12345678ABCabc"),
			Amount:                  pulumi.Int(1),
			Period:                  pulumi.Int(1),
			InternetMaxBandwidthOut: pulumi.Int(10),
			PublicIpIdentification:  pulumi.Bool(true),
			EnsRegionId:             pulumi.String("cn-chenzhou-telecom_unicom_cmcc"),
			PeriodUnit:              pulumi.String("Month"),
		})
		if err != nil {
			return err
		}
		defaultSecurityGroup, err := ens.NewSecurityGroup(ctx, "default", &ens.SecurityGroupArgs{
			Description:       pulumi.String("InstanceSecurityGroupAttachment_Description"),
			SecurityGroupName: pulumi.String(name),
		})
		if err != nil {
			return err
		}
		_, err = ens.NewInstanceSecurityGroupAttachment(ctx, "default", &ens.InstanceSecurityGroupAttachmentArgs{
			InstanceId:      _default.ID(),
			SecurityGroupId: defaultSecurityGroup.ID(),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;

return await Deployment.RunAsync(() => 
{
    var config = new Config();
    var name = config.Get("name") ?? "terraform-example";
    var @default = new AliCloud.Ens.Instance("default", new()
    {
        SystemDisk = new AliCloud.Ens.Inputs.InstanceSystemDiskArgs
        {
            Size = 20,
        },
        ScheduleAreaLevel = "Region",
        ImageId = "centos_6_08_64_20G_alibase_20171208",
        PaymentType = "Subscription",
        InstanceType = "ens.sn1.stiny",
        Password = "12345678ABCabc",
        Amount = 1,
        Period = 1,
        InternetMaxBandwidthOut = 10,
        PublicIpIdentification = true,
        EnsRegionId = "cn-chenzhou-telecom_unicom_cmcc",
        PeriodUnit = "Month",
    });

    var defaultSecurityGroup = new AliCloud.Ens.SecurityGroup("default", new()
    {
        Description = "InstanceSecurityGroupAttachment_Description",
        SecurityGroupName = name,
    });

    var defaultInstanceSecurityGroupAttachment = new AliCloud.Ens.InstanceSecurityGroupAttachment("default", new()
    {
        InstanceId = @default.Id,
        SecurityGroupId = defaultSecurityGroup.Id,
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.alicloud.ens.Instance;
import com.pulumi.alicloud.ens.InstanceArgs;
import com.pulumi.alicloud.ens.inputs.InstanceSystemDiskArgs;
import com.pulumi.alicloud.ens.SecurityGroup;
import com.pulumi.alicloud.ens.SecurityGroupArgs;
import com.pulumi.alicloud.ens.InstanceSecurityGroupAttachment;
import com.pulumi.alicloud.ens.InstanceSecurityGroupAttachmentArgs;
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("terraform-example");
        var default_ = new Instance("default", InstanceArgs.builder()
            .systemDisk(InstanceSystemDiskArgs.builder()
                .size("20")
                .build())
            .scheduleAreaLevel("Region")
            .imageId("centos_6_08_64_20G_alibase_20171208")
            .paymentType("Subscription")
            .instanceType("ens.sn1.stiny")
            .password("12345678ABCabc")
            .amount("1")
            .period("1")
            .internetMaxBandwidthOut("10")
            .publicIpIdentification(true)
            .ensRegionId("cn-chenzhou-telecom_unicom_cmcc")
            .periodUnit("Month")
            .build());

        var defaultSecurityGroup = new SecurityGroup("defaultSecurityGroup", SecurityGroupArgs.builder()
            .description("InstanceSecurityGroupAttachment_Description")
            .securityGroupName(name)
            .build());

        var defaultInstanceSecurityGroupAttachment = new InstanceSecurityGroupAttachment("defaultInstanceSecurityGroupAttachment", InstanceSecurityGroupAttachmentArgs.builder()
            .instanceId(default_.id())
            .securityGroupId(defaultSecurityGroup.id())
            .build());

    }
}
Copy
configuration:
  name:
    type: string
    default: terraform-example
resources:
  default:
    type: alicloud:ens:Instance
    properties:
      systemDisk:
        size: '20'
      scheduleAreaLevel: Region
      imageId: centos_6_08_64_20G_alibase_20171208
      paymentType: Subscription
      instanceType: ens.sn1.stiny
      password: 12345678ABCabc
      amount: '1'
      period: '1'
      internetMaxBandwidthOut: '10'
      publicIpIdentification: true
      ensRegionId: cn-chenzhou-telecom_unicom_cmcc
      periodUnit: Month
  defaultSecurityGroup:
    type: alicloud:ens:SecurityGroup
    name: default
    properties:
      description: InstanceSecurityGroupAttachment_Description
      securityGroupName: ${name}
  defaultInstanceSecurityGroupAttachment:
    type: alicloud:ens:InstanceSecurityGroupAttachment
    name: default
    properties:
      instanceId: ${default.id}
      securityGroupId: ${defaultSecurityGroup.id}
Copy

Create InstanceSecurityGroupAttachment Resource

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

Constructor syntax

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

@overload
def InstanceSecurityGroupAttachment(resource_name: str,
                                    opts: Optional[ResourceOptions] = None,
                                    security_group_id: Optional[str] = None,
                                    instance_id: Optional[str] = None)
func NewInstanceSecurityGroupAttachment(ctx *Context, name string, args InstanceSecurityGroupAttachmentArgs, opts ...ResourceOption) (*InstanceSecurityGroupAttachment, error)
public InstanceSecurityGroupAttachment(string name, InstanceSecurityGroupAttachmentArgs args, CustomResourceOptions? opts = null)
public InstanceSecurityGroupAttachment(String name, InstanceSecurityGroupAttachmentArgs args)
public InstanceSecurityGroupAttachment(String name, InstanceSecurityGroupAttachmentArgs args, CustomResourceOptions options)
type: alicloud:ens:InstanceSecurityGroupAttachment
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. InstanceSecurityGroupAttachmentArgs
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. InstanceSecurityGroupAttachmentArgs
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. InstanceSecurityGroupAttachmentArgs
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. InstanceSecurityGroupAttachmentArgs
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. InstanceSecurityGroupAttachmentArgs
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 instanceSecurityGroupAttachmentResource = new AliCloud.Ens.InstanceSecurityGroupAttachment("instanceSecurityGroupAttachmentResource", new()
{
    SecurityGroupId = "string",
    InstanceId = "string",
});
Copy
example, err := ens.NewInstanceSecurityGroupAttachment(ctx, "instanceSecurityGroupAttachmentResource", &ens.InstanceSecurityGroupAttachmentArgs{
	SecurityGroupId: pulumi.String("string"),
	InstanceId:      pulumi.String("string"),
})
Copy
var instanceSecurityGroupAttachmentResource = new InstanceSecurityGroupAttachment("instanceSecurityGroupAttachmentResource", InstanceSecurityGroupAttachmentArgs.builder()
    .securityGroupId("string")
    .instanceId("string")
    .build());
Copy
instance_security_group_attachment_resource = alicloud.ens.InstanceSecurityGroupAttachment("instanceSecurityGroupAttachmentResource",
    security_group_id="string",
    instance_id="string")
Copy
const instanceSecurityGroupAttachmentResource = new alicloud.ens.InstanceSecurityGroupAttachment("instanceSecurityGroupAttachmentResource", {
    securityGroupId: "string",
    instanceId: "string",
});
Copy
type: alicloud:ens:InstanceSecurityGroupAttachment
properties:
    instanceId: string
    securityGroupId: string
Copy

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

SecurityGroupId
This property is required.
Changes to this property will trigger replacement.
string
Security group ID.
InstanceId Changes to this property will trigger replacement. string
Instance ID.
SecurityGroupId
This property is required.
Changes to this property will trigger replacement.
string
Security group ID.
InstanceId Changes to this property will trigger replacement. string
Instance ID.
securityGroupId
This property is required.
Changes to this property will trigger replacement.
String
Security group ID.
instanceId Changes to this property will trigger replacement. String
Instance ID.
securityGroupId
This property is required.
Changes to this property will trigger replacement.
string
Security group ID.
instanceId Changes to this property will trigger replacement. string
Instance ID.
security_group_id
This property is required.
Changes to this property will trigger replacement.
str
Security group ID.
instance_id Changes to this property will trigger replacement. str
Instance ID.
securityGroupId
This property is required.
Changes to this property will trigger replacement.
String
Security group ID.
instanceId Changes to this property will trigger replacement. String
Instance ID.

Outputs

All input properties are implicitly available as output properties. Additionally, the InstanceSecurityGroupAttachment 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 InstanceSecurityGroupAttachment Resource

Get an existing InstanceSecurityGroupAttachment 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?: InstanceSecurityGroupAttachmentState, opts?: CustomResourceOptions): InstanceSecurityGroupAttachment
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        instance_id: Optional[str] = None,
        security_group_id: Optional[str] = None) -> InstanceSecurityGroupAttachment
func GetInstanceSecurityGroupAttachment(ctx *Context, name string, id IDInput, state *InstanceSecurityGroupAttachmentState, opts ...ResourceOption) (*InstanceSecurityGroupAttachment, error)
public static InstanceSecurityGroupAttachment Get(string name, Input<string> id, InstanceSecurityGroupAttachmentState? state, CustomResourceOptions? opts = null)
public static InstanceSecurityGroupAttachment get(String name, Output<String> id, InstanceSecurityGroupAttachmentState state, CustomResourceOptions options)
resources:  _:    type: alicloud:ens:InstanceSecurityGroupAttachment    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:
InstanceId Changes to this property will trigger replacement. string
Instance ID.
SecurityGroupId Changes to this property will trigger replacement. string
Security group ID.
InstanceId Changes to this property will trigger replacement. string
Instance ID.
SecurityGroupId Changes to this property will trigger replacement. string
Security group ID.
instanceId Changes to this property will trigger replacement. String
Instance ID.
securityGroupId Changes to this property will trigger replacement. String
Security group ID.
instanceId Changes to this property will trigger replacement. string
Instance ID.
securityGroupId Changes to this property will trigger replacement. string
Security group ID.
instance_id Changes to this property will trigger replacement. str
Instance ID.
security_group_id Changes to this property will trigger replacement. str
Security group ID.
instanceId Changes to this property will trigger replacement. String
Instance ID.
securityGroupId Changes to this property will trigger replacement. String
Security group ID.

Import

ENS Instance Security Group Attachment can be imported using the id, e.g.

$ pulumi import alicloud:ens/instanceSecurityGroupAttachment:InstanceSecurityGroupAttachment example <instance_id>:<security_group_id>
Copy

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

Package Details

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