Package com.pulumi.aws.ec2
Class NetworkInterfaceSecurityGroupAttachment
- java.lang.Object
-
- com.pulumi.resources.Resource
-
- com.pulumi.resources.CustomResource
-
- com.pulumi.aws.ec2.NetworkInterfaceSecurityGroupAttachment
-
public class NetworkInterfaceSecurityGroupAttachment extends com.pulumi.resources.CustomResource
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 `sg_attachment`: <!--Start PulumiCodeChooser -->package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.aws.ec2.Ec2Functions; import com.pulumi.aws.ec2.inputs.GetAmiArgs; import com.pulumi.aws.ec2.Instance; import com.pulumi.aws.ec2.InstanceArgs; import com.pulumi.aws.ec2.SecurityGroup; import com.pulumi.aws.ec2.SecurityGroupArgs; import com.pulumi.aws.ec2.NetworkInterfaceSecurityGroupAttachment; import com.pulumi.aws.ec2.NetworkInterfaceSecurityGroupAttachmentArgs; 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 ami = Ec2Functions.getAmi(GetAmiArgs.builder() .mostRecent(true) .filters(GetAmiFilterArgs.builder() .name("name") .values("amzn-ami-hvm-*") .build()) .owners("amazon") .build()); var instance = new Instance("instance", InstanceArgs.builder() .instanceType("t2.micro") .ami(ami.applyValue(getAmiResult -> getAmiResult.id())) .tags(Map.of("type", "test-instance")) .build()); var sg = new SecurityGroup("sg", SecurityGroupArgs.builder() .tags(Map.of("type", "test-security-group")) .build()); var sgAttachment = new NetworkInterfaceSecurityGroupAttachment("sgAttachment", NetworkInterfaceSecurityGroupAttachmentArgs.builder() .securityGroupId(sg.id()) .networkInterfaceId(instance.primaryNetworkInterfaceId()) .build()); } }
package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.aws.ec2.Ec2Functions; import com.pulumi.aws.ec2.inputs.GetInstanceArgs; import com.pulumi.aws.ec2.SecurityGroup; import com.pulumi.aws.ec2.SecurityGroupArgs; import com.pulumi.aws.ec2.NetworkInterfaceSecurityGroupAttachment; import com.pulumi.aws.ec2.NetworkInterfaceSecurityGroupAttachmentArgs; 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 instance = Ec2Functions.getInstance(GetInstanceArgs.builder() .instanceId("i-1234567890abcdef0") .build()); var sg = new SecurityGroup("sg", SecurityGroupArgs.builder() .tags(Map.of("type", "test-security-group")) .build()); var sgAttachment = new NetworkInterfaceSecurityGroupAttachment("sgAttachment", NetworkInterfaceSecurityGroupAttachmentArgs.builder() .securityGroupId(sg.id()) .networkInterfaceId(instance.applyValue(getInstanceResult -> getInstanceResult.networkInterfaceId())) .build()); } }
-
-
Constructor Summary
Constructors Constructor Description NetworkInterfaceSecurityGroupAttachment(java.lang.String name)
NetworkInterfaceSecurityGroupAttachment(java.lang.String name, NetworkInterfaceSecurityGroupAttachmentArgs args)
NetworkInterfaceSecurityGroupAttachment(java.lang.String name, NetworkInterfaceSecurityGroupAttachmentArgs args, com.pulumi.resources.CustomResourceOptions options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static NetworkInterfaceSecurityGroupAttachment
get(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, NetworkInterfaceSecurityGroupAttachmentState state, com.pulumi.resources.CustomResourceOptions options)
Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.com.pulumi.core.Output<java.lang.String>
networkInterfaceId()
com.pulumi.core.Output<java.lang.String>
securityGroupId()
-
-
-
Constructor Detail
-
NetworkInterfaceSecurityGroupAttachment
public NetworkInterfaceSecurityGroupAttachment(java.lang.String name)
- Parameters:
name
- The _unique_ name of the resulting resource.
-
NetworkInterfaceSecurityGroupAttachment
public NetworkInterfaceSecurityGroupAttachment(java.lang.String name, NetworkInterfaceSecurityGroupAttachmentArgs args)
- Parameters:
name
- The _unique_ name of the resulting resource.args
- The arguments to use to populate this resource's properties.
-
NetworkInterfaceSecurityGroupAttachment
public NetworkInterfaceSecurityGroupAttachment(java.lang.String name, NetworkInterfaceSecurityGroupAttachmentArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options)
- Parameters:
name
- The _unique_ name of the resulting resource.args
- The arguments to use to populate this resource's properties.options
- A bag of options that control this resource's behavior.
-
-
Method Detail
-
networkInterfaceId
public com.pulumi.core.Output<java.lang.String> networkInterfaceId()
- Returns:
- The ID of the network interface to attach to.
-
securityGroupId
public com.pulumi.core.Output<java.lang.String> securityGroupId()
- Returns:
- The ID of the security group.
-
get
public static NetworkInterfaceSecurityGroupAttachment get(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, @Nullable NetworkInterfaceSecurityGroupAttachmentState state, @Nullable com.pulumi.resources.CustomResourceOptions options)
Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.- Parameters:
name
- The _unique_ name of the resulting resource.id
- The _unique_ provider ID of the resource to lookup.state
-options
- Optional settings to control the behavior of the CustomResource.
-
-