Class 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());
     
         }
     }
     
     
    <!--End PulumiCodeChooser --> In this example, `instance` is provided by the `aws.ec2.Instance` data source, fetching an external instance, possibly not managed by this provider. `sg_attachment` then attaches to the output instance's `network_interface_id`: <!--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.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());
     
         }
     }
     
     
    <!--End PulumiCodeChooser --> ## 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 ```
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.pulumi.resources.CustomResource

        com.pulumi.resources.CustomResource.CustomResourceInternal
      • Nested classes/interfaces inherited from class com.pulumi.resources.Resource

        com.pulumi.resources.Resource.LazyField<T extends java.lang.Object>, com.pulumi.resources.Resource.LazyFields, com.pulumi.resources.Resource.ResourceInternal
    • Field Summary

      • Fields inherited from class com.pulumi.resources.Resource

        childResources, remote
    • 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()  
      • Methods inherited from class com.pulumi.resources.CustomResource

        getId, id, idFuture
      • Methods inherited from class com.pulumi.resources.Resource

        getChildResources, getResourceName, getResourceType, getUrn, pulumiChildResources, pulumiResourceName, pulumiResourceType, urn
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.