NetworkInterfaceAttachment
Provides an Alicloud ECS Elastic Network Interface Attachment as a resource to attach ENI to or detach ENI from ECS Instances.
For information about Elastic Network Interface and how to use it, see Elastic Network Interface.
Example Usage
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;
class MyStack : Stack
{
public MyStack()
{
var config = new Config();
var name = config.Get("name") ?? "networkInterfaceAttachment";
var number = config.Get("number") ?? "2";
var vpc = new AliCloud.Vpc.Network("vpc", new AliCloud.Vpc.NetworkArgs
{
CidrBlock = "192.168.0.0/24",
});
var defaultZones = Output.Create(AliCloud.GetZones.InvokeAsync(new AliCloud.GetZonesArgs
{
AvailableResourceCreation = "VSwitch",
}));
var vswitch = new AliCloud.Vpc.Switch("vswitch", new AliCloud.Vpc.SwitchArgs
{
AvailabilityZone = defaultZones.Apply(defaultZones => defaultZones.Zones[0].Id),
CidrBlock = "192.168.0.0/24",
VpcId = vpc.Id,
});
var @group = new AliCloud.Ecs.SecurityGroup("group", new AliCloud.Ecs.SecurityGroupArgs
{
VpcId = vpc.Id,
});
var instanceType = defaultZones.Apply(defaultZones => Output.Create(AliCloud.Ecs.GetInstanceTypes.InvokeAsync(new AliCloud.Ecs.GetInstanceTypesArgs
{
AvailabilityZone = defaultZones.Zones[0].Id,
EniAmount = 2,
})));
var defaultImages = Output.Create(AliCloud.Ecs.GetImages.InvokeAsync(new AliCloud.Ecs.GetImagesArgs
{
MostRecent = true,
NameRegex = "^ubuntu_18.*64",
Owners = "system",
}));
var instance = new List<AliCloud.Ecs.Instance>();
for (var rangeIndex = 0; rangeIndex < number; rangeIndex++)
{
var range = new { Value = rangeIndex };
instance.Add(new AliCloud.Ecs.Instance($"instance-{range.Value}", new AliCloud.Ecs.InstanceArgs
{
AvailabilityZone = defaultZones.Apply(defaultZones => defaultZones.Zones[0].Id),
ImageId = defaultImages.Apply(defaultImages => defaultImages.Images[0].Id),
InstanceName = name,
InstanceType = instanceType.Apply(instanceType => instanceType.InstanceTypes[0].Id),
InternetMaxBandwidthOut = 10,
SecurityGroups =
{
@group.Id,
},
SystemDiskCategory = "cloud_efficiency",
VswitchId = vswitch.Id,
}));
}
var @interface = new List<AliCloud.Vpc.NetworkInterface>();
for (var rangeIndex = 0; rangeIndex < number; rangeIndex++)
{
var range = new { Value = rangeIndex };
@interface.Add(new AliCloud.Vpc.NetworkInterface($"interface-{range.Value}", new AliCloud.Vpc.NetworkInterfaceArgs
{
SecurityGroups =
{
@group.Id,
},
VswitchId = vswitch.Id,
}));
}
var attachment = new List<AliCloud.Vpc.NetworkInterfaceAttachment>();
for (var rangeIndex = 0; rangeIndex < number; rangeIndex++)
{
var range = new { Value = rangeIndex };
attachment.Add(new AliCloud.Vpc.NetworkInterfaceAttachment($"attachment-{range.Value}", new AliCloud.Vpc.NetworkInterfaceAttachmentArgs
{
InstanceId = instance.Select(__item => __item.Id).ToList()[range.Index],
NetworkInterfaceId = @interface.Select(__item => __item.Id).ToList()[range.Index],
}));
}
}
}
Coming soon!
import pulumi
import pulumi_alicloud as alicloud
config = pulumi.Config()
name = config.get("name")
if name is None:
name = "networkInterfaceAttachment"
number = config.get("number")
if number is None:
number = "2"
vpc = alicloud.vpc.Network("vpc", cidr_block="192.168.0.0/24")
default_zones = alicloud.get_zones(available_resource_creation="VSwitch")
vswitch = alicloud.vpc.Switch("vswitch",
availability_zone=default_zones.zones[0]["id"],
cidr_block="192.168.0.0/24",
vpc_id=vpc.id)
group = alicloud.ecs.SecurityGroup("group", vpc_id=vpc.id)
instance_type = alicloud.ecs.get_instance_types(availability_zone=default_zones.zones[0]["id"],
eni_amount=2)
default_images = alicloud.ecs.get_images(most_recent=True,
name_regex="^ubuntu_18.*64",
owners="system")
instance = []
for range in [{"value": i} for i in range(0, number)]:
instance.append(alicloud.ecs.Instance(f"instance-{range['value']}",
availability_zone=default_zones.zones[0]["id"],
image_id=default_images.images[0]["id"],
instance_name=name,
instance_type=instance_type.instance_types[0]["id"],
internet_max_bandwidth_out=10,
security_groups=[group.id],
system_disk_category="cloud_efficiency",
vswitch_id=vswitch.id))
interface = []
for range in [{"value": i} for i in range(0, number)]:
interface.append(alicloud.vpc.NetworkInterface(f"interface-{range['value']}",
security_groups=[group.id],
vswitch_id=vswitch.id))
attachment = []
for range in [{"value": i} for i in range(0, number)]:
attachment.append(alicloud.vpc.NetworkInterfaceAttachment(f"attachment-{range['value']}",
instance_id=[__item.id for __item in instance][range["index"]],
network_interface_id=[__item.id for __item in interface][range["index"]]))import * as pulumi from "@pulumi/pulumi";
import * as alicloud from "@pulumi/alicloud";
const config = new pulumi.Config();
const name = config.get("name") || "networkInterfaceAttachment";
const number = config.get("number") || "2";
const vpc = new alicloud.vpc.Network("vpc", {
cidrBlock: "192.168.0.0/24",
});
const defaultZones = pulumi.output(alicloud.getZones({
availableResourceCreation: "VSwitch",
}, { async: true }));
const vswitch = new alicloud.vpc.Switch("vswitch", {
availabilityZone: defaultZones.zones[0].id,
cidrBlock: "192.168.0.0/24",
vpcId: vpc.id,
});
const group = new alicloud.ecs.SecurityGroup("group", {
vpcId: vpc.id,
});
const instanceType = defaultZones.apply(defaultZones => alicloud.ecs.getInstanceTypes({
availabilityZone: defaultZones.zones[0].id,
eniAmount: 2,
}, { async: true }));
const defaultImages = pulumi.output(alicloud.ecs.getImages({
mostRecent: true,
nameRegex: "^ubuntu_18.*64",
owners: "system",
}, { async: true }));
const instance: alicloud.ecs.Instance[] = [];
for (let i = 0; i < number; i++) {
instance.push(new alicloud.ecs.Instance(`instance-${i}`, {
availabilityZone: defaultZones.zones[0].id,
imageId: defaultImages.images[0].id,
instanceName: name,
instanceType: instanceType.instanceTypes[0].id,
internetMaxBandwidthOut: 10,
securityGroups: [group.id],
systemDiskCategory: "cloud_efficiency",
vswitchId: vswitch.id,
}));
}
const interfaceNetworkInterface: alicloud.vpc.NetworkInterface[] = [];
for (let i = 0; i < number; i++) {
interfaceNetworkInterface.push(new alicloud.vpc.NetworkInterface(`interface-${i}`, {
securityGroups: [group.id],
vswitchId: vswitch.id,
}));
}
const attachment: alicloud.vpc.NetworkInterfaceAttachment[] = [];
for (let i = 0; i < number; i++) {
attachment.push(new alicloud.vpc.NetworkInterfaceAttachment(`attachment-${i}`, {
instanceId: pulumi.all(instance.map(v => v.id)).apply(id => id.map(v => v)[i]),
networkInterfaceId: pulumi.all(interfaceNetworkInterface.map(v => v.id)).apply(id => id.map(v => v)[i]),
}));
}Create a NetworkInterfaceAttachment Resource
new NetworkInterfaceAttachment(name: string, args: NetworkInterfaceAttachmentArgs, opts?: CustomResourceOptions);def NetworkInterfaceAttachment(resource_name, opts=None, instance_id=None, network_interface_id=None, __props__=None);func NewNetworkInterfaceAttachment(ctx *Context, name string, args NetworkInterfaceAttachmentArgs, opts ...ResourceOption) (*NetworkInterfaceAttachment, error)public NetworkInterfaceAttachment(string name, NetworkInterfaceAttachmentArgs args, CustomResourceOptions? opts = null)- name string
- The unique name of the resource.
- args NetworkInterfaceAttachmentArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- opts ResourceOptions
- A bag of options that control this resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args NetworkInterfaceAttachmentArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args NetworkInterfaceAttachmentArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
NetworkInterfaceAttachment Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.
Inputs
The NetworkInterfaceAttachment resource accepts the following input properties:
- Instance
Id string The instance ID to attach.
- Network
Interface stringId The ENI ID to attach.
- Instance
Id string The instance ID to attach.
- Network
Interface stringId The ENI ID to attach.
- instance
Id string The instance ID to attach.
- network
Interface stringId The ENI ID to attach.
- instance_
id str The instance ID to attach.
- network_
interface_ strid The ENI ID to attach.
Outputs
All input properties are implicitly available as output properties. Additionally, the NetworkInterfaceAttachment resource produces the following output properties:
Look up an Existing NetworkInterfaceAttachment Resource
Get an existing NetworkInterfaceAttachment 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?: NetworkInterfaceAttachmentState, opts?: CustomResourceOptions): NetworkInterfaceAttachmentstatic get(resource_name, id, opts=None, instance_id=None, network_interface_id=None, __props__=None);func GetNetworkInterfaceAttachment(ctx *Context, name string, id IDInput, state *NetworkInterfaceAttachmentState, opts ...ResourceOption) (*NetworkInterfaceAttachment, error)public static NetworkInterfaceAttachment Get(string name, Input<string> id, NetworkInterfaceAttachmentState? state, CustomResourceOptions? opts = null)- 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.
The following state arguments are supported:
- Instance
Id string The instance ID to attach.
- Network
Interface stringId The ENI ID to attach.
- Instance
Id string The instance ID to attach.
- Network
Interface stringId The ENI ID to attach.
- instance
Id string The instance ID to attach.
- network
Interface stringId The ENI ID to attach.
- instance_
id str The instance ID to attach.
- network_
interface_ strid The ENI ID to attach.
Package Details
- Repository
- https://github.com/pulumi/pulumi-alicloud
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
alicloudTerraform Provider.