@pulumi/aws
Version:
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
135 lines • 6 kB
JavaScript
;
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
Object.defineProperty(exports, "__esModule", { value: true });
exports.NetworkInterfaceSecurityGroupAttachment = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* This resource attaches a security group to an Elastic Network Interface (ENI).
* It can be used to attach a security group to any existing ENI, be it a
* secondary ENI or one attached as the primary interface on an instance.
*
* > **NOTE on instances, interfaces, and security groups:** This provider currently
* provides the capability to assign security groups via the [`aws.ec2.Instance`][1]
* and the [`aws.ec2.NetworkInterface`][2] resources. Using this resource in
* conjunction with security groups provided in-line in those resources will cause
* conflicts, and will lead to spurious diffs and undefined behavior - please use
* one or the other.
*
* ## Example Usage
*
* The following provides a very basic example of setting up an instance (provided
* by `instance`) in the default security group, creating a security group
* (provided by `sg`) and then attaching the security group to the instance's
* primary network interface via the `aws.ec2.NetworkInterfaceSecurityGroupAttachment` resource,
* named `sgAttachment`:
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const ami = aws.ec2.getAmi({
* mostRecent: true,
* filters: [{
* name: "name",
* values: ["amzn-ami-hvm-*"],
* }],
* owners: ["amazon"],
* });
* const instance = new aws.ec2.Instance("instance", {
* instanceType: aws.ec2.InstanceType.T2_Micro,
* ami: ami.then(ami => ami.id),
* tags: {
* type: "test-instance",
* },
* });
* const sg = new aws.ec2.SecurityGroup("sg", {tags: {
* type: "test-security-group",
* }});
* const sgAttachment = new aws.ec2.NetworkInterfaceSecurityGroupAttachment("sg_attachment", {
* securityGroupId: sg.id,
* networkInterfaceId: instance.primaryNetworkInterfaceId,
* });
* ```
*
* In this example, `instance` is provided by the `aws.ec2.Instance` data source,
* fetching an external instance, possibly not managed by this provider.
* `sgAttachment` then attaches to the output instance's `networkInterfaceId`:
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const instance = aws.ec2.getInstance({
* instanceId: "i-1234567890abcdef0",
* });
* const sg = new aws.ec2.SecurityGroup("sg", {tags: {
* type: "test-security-group",
* }});
* const sgAttachment = new aws.ec2.NetworkInterfaceSecurityGroupAttachment("sg_attachment", {
* securityGroupId: sg.id,
* networkInterfaceId: instance.then(instance => instance.networkInterfaceId),
* });
* ```
*
* ## Import
*
* Using `pulumi import`, import Network Interface Security Group attachments using the associated network interface ID and security group ID, separated by an underscore (`_`). For example:
*
* ```sh
* $ pulumi import aws:ec2/networkInterfaceSecurityGroupAttachment:NetworkInterfaceSecurityGroupAttachment sg_attachment eni-1234567890abcdef0_sg-1234567890abcdef0
* ```
*/
class NetworkInterfaceSecurityGroupAttachment extends pulumi.CustomResource {
/**
* Get an existing NetworkInterfaceSecurityGroupAttachment resource's state with the given name, ID, and optional extra
* properties used to qualify the lookup.
*
* @param name The _unique_ name of the resulting resource.
* @param id The _unique_ provider ID of the resource to lookup.
* @param state Any extra arguments used during the lookup.
* @param opts Optional settings to control the behavior of the CustomResource.
*/
static get(name, id, state, opts) {
return new NetworkInterfaceSecurityGroupAttachment(name, state, { ...opts, id: id });
}
/**
* Returns true if the given object is an instance of NetworkInterfaceSecurityGroupAttachment. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
static isInstance(obj) {
if (obj === undefined || obj === null) {
return false;
}
return obj['__pulumiType'] === NetworkInterfaceSecurityGroupAttachment.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["networkInterfaceId"] = state?.networkInterfaceId;
resourceInputs["region"] = state?.region;
resourceInputs["securityGroupId"] = state?.securityGroupId;
}
else {
const args = argsOrState;
if (args?.networkInterfaceId === undefined && !opts.urn) {
throw new Error("Missing required property 'networkInterfaceId'");
}
if (args?.securityGroupId === undefined && !opts.urn) {
throw new Error("Missing required property 'securityGroupId'");
}
resourceInputs["networkInterfaceId"] = args?.networkInterfaceId;
resourceInputs["region"] = args?.region;
resourceInputs["securityGroupId"] = args?.securityGroupId;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(NetworkInterfaceSecurityGroupAttachment.__pulumiType, name, resourceInputs, opts);
}
}
exports.NetworkInterfaceSecurityGroupAttachment = NetworkInterfaceSecurityGroupAttachment;
/** @internal */
NetworkInterfaceSecurityGroupAttachment.__pulumiType = 'aws:ec2/networkInterfaceSecurityGroupAttachment:NetworkInterfaceSecurityGroupAttachment';
//# sourceMappingURL=networkInterfaceSecurityGroupAttachment.js.map