github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/ec2/networkInterfaceSecurityGroupAttachment.go (about)

     1  // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
     2  // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  package ec2
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	"errors"
    11  	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
    12  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    13  )
    14  
    15  // This resource attaches a security group to an Elastic Network Interface (ENI).
    16  // It can be used to attach a security group to any existing ENI, be it a
    17  // secondary ENI or one attached as the primary interface on an instance.
    18  //
    19  // > **NOTE on instances, interfaces, and security groups:** This provider currently
    20  // provides the capability to assign security groups via the [`ec2.Instance`][1]
    21  // and the [`ec2.NetworkInterface`][2] resources. Using this resource in
    22  // conjunction with security groups provided in-line in those resources will cause
    23  // conflicts, and will lead to spurious diffs and undefined behavior - please use
    24  // one or the other.
    25  //
    26  // ## Example Usage
    27  //
    28  // The following provides a very basic example of setting up an instance (provided
    29  // by `instance`) in the default security group, creating a security group
    30  // (provided by `sg`) and then attaching the security group to the instance's
    31  // primary network interface via the `ec2.NetworkInterfaceSecurityGroupAttachment` resource,
    32  // named `sgAttachment`:
    33  //
    34  // <!--Start PulumiCodeChooser -->
    35  // ```go
    36  // package main
    37  //
    38  // import (
    39  //
    40  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    41  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    42  //
    43  // )
    44  //
    45  //	func main() {
    46  //		pulumi.Run(func(ctx *pulumi.Context) error {
    47  //			ami, err := ec2.LookupAmi(ctx, &ec2.LookupAmiArgs{
    48  //				MostRecent: pulumi.BoolRef(true),
    49  //				Filters: []ec2.GetAmiFilter{
    50  //					{
    51  //						Name: "name",
    52  //						Values: []string{
    53  //							"amzn-ami-hvm-*",
    54  //						},
    55  //					},
    56  //				},
    57  //				Owners: []string{
    58  //					"amazon",
    59  //				},
    60  //			}, nil)
    61  //			if err != nil {
    62  //				return err
    63  //			}
    64  //			instance, err := ec2.NewInstance(ctx, "instance", &ec2.InstanceArgs{
    65  //				InstanceType: pulumi.String(ec2.InstanceType_T2_Micro),
    66  //				Ami:          pulumi.String(ami.Id),
    67  //				Tags: pulumi.StringMap{
    68  //					"type": pulumi.String("test-instance"),
    69  //				},
    70  //			})
    71  //			if err != nil {
    72  //				return err
    73  //			}
    74  //			sg, err := ec2.NewSecurityGroup(ctx, "sg", &ec2.SecurityGroupArgs{
    75  //				Tags: pulumi.StringMap{
    76  //					"type": pulumi.String("test-security-group"),
    77  //				},
    78  //			})
    79  //			if err != nil {
    80  //				return err
    81  //			}
    82  //			_, err = ec2.NewNetworkInterfaceSecurityGroupAttachment(ctx, "sg_attachment", &ec2.NetworkInterfaceSecurityGroupAttachmentArgs{
    83  //				SecurityGroupId:    sg.ID(),
    84  //				NetworkInterfaceId: instance.PrimaryNetworkInterfaceId,
    85  //			})
    86  //			if err != nil {
    87  //				return err
    88  //			}
    89  //			return nil
    90  //		})
    91  //	}
    92  //
    93  // ```
    94  // <!--End PulumiCodeChooser -->
    95  //
    96  // In this example, `instance` is provided by the `ec2.Instance` data source,
    97  // fetching an external instance, possibly not managed by this provider.
    98  // `sgAttachment` then attaches to the output instance's `networkInterfaceId`:
    99  //
   100  // <!--Start PulumiCodeChooser -->
   101  // ```go
   102  // package main
   103  //
   104  // import (
   105  //
   106  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
   107  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
   108  //
   109  // )
   110  //
   111  //	func main() {
   112  //		pulumi.Run(func(ctx *pulumi.Context) error {
   113  //			instance, err := ec2.LookupInstance(ctx, &ec2.LookupInstanceArgs{
   114  //				InstanceId: pulumi.StringRef("i-1234567890abcdef0"),
   115  //			}, nil)
   116  //			if err != nil {
   117  //				return err
   118  //			}
   119  //			sg, err := ec2.NewSecurityGroup(ctx, "sg", &ec2.SecurityGroupArgs{
   120  //				Tags: pulumi.StringMap{
   121  //					"type": pulumi.String("test-security-group"),
   122  //				},
   123  //			})
   124  //			if err != nil {
   125  //				return err
   126  //			}
   127  //			_, err = ec2.NewNetworkInterfaceSecurityGroupAttachment(ctx, "sg_attachment", &ec2.NetworkInterfaceSecurityGroupAttachmentArgs{
   128  //				SecurityGroupId:    sg.ID(),
   129  //				NetworkInterfaceId: pulumi.String(instance.NetworkInterfaceId),
   130  //			})
   131  //			if err != nil {
   132  //				return err
   133  //			}
   134  //			return nil
   135  //		})
   136  //	}
   137  //
   138  // ```
   139  // <!--End PulumiCodeChooser -->
   140  //
   141  // ## Import
   142  //
   143  // 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:
   144  //
   145  // ```sh
   146  // $ pulumi import aws:ec2/networkInterfaceSecurityGroupAttachment:NetworkInterfaceSecurityGroupAttachment sg_attachment eni-1234567890abcdef0_sg-1234567890abcdef0
   147  // ```
   148  type NetworkInterfaceSecurityGroupAttachment struct {
   149  	pulumi.CustomResourceState
   150  
   151  	// The ID of the network interface to attach to.
   152  	NetworkInterfaceId pulumi.StringOutput `pulumi:"networkInterfaceId"`
   153  	// The ID of the security group.
   154  	SecurityGroupId pulumi.StringOutput `pulumi:"securityGroupId"`
   155  }
   156  
   157  // NewNetworkInterfaceSecurityGroupAttachment registers a new resource with the given unique name, arguments, and options.
   158  func NewNetworkInterfaceSecurityGroupAttachment(ctx *pulumi.Context,
   159  	name string, args *NetworkInterfaceSecurityGroupAttachmentArgs, opts ...pulumi.ResourceOption) (*NetworkInterfaceSecurityGroupAttachment, error) {
   160  	if args == nil {
   161  		return nil, errors.New("missing one or more required arguments")
   162  	}
   163  
   164  	if args.NetworkInterfaceId == nil {
   165  		return nil, errors.New("invalid value for required argument 'NetworkInterfaceId'")
   166  	}
   167  	if args.SecurityGroupId == nil {
   168  		return nil, errors.New("invalid value for required argument 'SecurityGroupId'")
   169  	}
   170  	opts = internal.PkgResourceDefaultOpts(opts)
   171  	var resource NetworkInterfaceSecurityGroupAttachment
   172  	err := ctx.RegisterResource("aws:ec2/networkInterfaceSecurityGroupAttachment:NetworkInterfaceSecurityGroupAttachment", name, args, &resource, opts...)
   173  	if err != nil {
   174  		return nil, err
   175  	}
   176  	return &resource, nil
   177  }
   178  
   179  // GetNetworkInterfaceSecurityGroupAttachment gets an existing NetworkInterfaceSecurityGroupAttachment resource's state with the given name, ID, and optional
   180  // state properties that are used to uniquely qualify the lookup (nil if not required).
   181  func GetNetworkInterfaceSecurityGroupAttachment(ctx *pulumi.Context,
   182  	name string, id pulumi.IDInput, state *NetworkInterfaceSecurityGroupAttachmentState, opts ...pulumi.ResourceOption) (*NetworkInterfaceSecurityGroupAttachment, error) {
   183  	var resource NetworkInterfaceSecurityGroupAttachment
   184  	err := ctx.ReadResource("aws:ec2/networkInterfaceSecurityGroupAttachment:NetworkInterfaceSecurityGroupAttachment", name, id, state, &resource, opts...)
   185  	if err != nil {
   186  		return nil, err
   187  	}
   188  	return &resource, nil
   189  }
   190  
   191  // Input properties used for looking up and filtering NetworkInterfaceSecurityGroupAttachment resources.
   192  type networkInterfaceSecurityGroupAttachmentState struct {
   193  	// The ID of the network interface to attach to.
   194  	NetworkInterfaceId *string `pulumi:"networkInterfaceId"`
   195  	// The ID of the security group.
   196  	SecurityGroupId *string `pulumi:"securityGroupId"`
   197  }
   198  
   199  type NetworkInterfaceSecurityGroupAttachmentState struct {
   200  	// The ID of the network interface to attach to.
   201  	NetworkInterfaceId pulumi.StringPtrInput
   202  	// The ID of the security group.
   203  	SecurityGroupId pulumi.StringPtrInput
   204  }
   205  
   206  func (NetworkInterfaceSecurityGroupAttachmentState) ElementType() reflect.Type {
   207  	return reflect.TypeOf((*networkInterfaceSecurityGroupAttachmentState)(nil)).Elem()
   208  }
   209  
   210  type networkInterfaceSecurityGroupAttachmentArgs struct {
   211  	// The ID of the network interface to attach to.
   212  	NetworkInterfaceId string `pulumi:"networkInterfaceId"`
   213  	// The ID of the security group.
   214  	SecurityGroupId string `pulumi:"securityGroupId"`
   215  }
   216  
   217  // The set of arguments for constructing a NetworkInterfaceSecurityGroupAttachment resource.
   218  type NetworkInterfaceSecurityGroupAttachmentArgs struct {
   219  	// The ID of the network interface to attach to.
   220  	NetworkInterfaceId pulumi.StringInput
   221  	// The ID of the security group.
   222  	SecurityGroupId pulumi.StringInput
   223  }
   224  
   225  func (NetworkInterfaceSecurityGroupAttachmentArgs) ElementType() reflect.Type {
   226  	return reflect.TypeOf((*networkInterfaceSecurityGroupAttachmentArgs)(nil)).Elem()
   227  }
   228  
   229  type NetworkInterfaceSecurityGroupAttachmentInput interface {
   230  	pulumi.Input
   231  
   232  	ToNetworkInterfaceSecurityGroupAttachmentOutput() NetworkInterfaceSecurityGroupAttachmentOutput
   233  	ToNetworkInterfaceSecurityGroupAttachmentOutputWithContext(ctx context.Context) NetworkInterfaceSecurityGroupAttachmentOutput
   234  }
   235  
   236  func (*NetworkInterfaceSecurityGroupAttachment) ElementType() reflect.Type {
   237  	return reflect.TypeOf((**NetworkInterfaceSecurityGroupAttachment)(nil)).Elem()
   238  }
   239  
   240  func (i *NetworkInterfaceSecurityGroupAttachment) ToNetworkInterfaceSecurityGroupAttachmentOutput() NetworkInterfaceSecurityGroupAttachmentOutput {
   241  	return i.ToNetworkInterfaceSecurityGroupAttachmentOutputWithContext(context.Background())
   242  }
   243  
   244  func (i *NetworkInterfaceSecurityGroupAttachment) ToNetworkInterfaceSecurityGroupAttachmentOutputWithContext(ctx context.Context) NetworkInterfaceSecurityGroupAttachmentOutput {
   245  	return pulumi.ToOutputWithContext(ctx, i).(NetworkInterfaceSecurityGroupAttachmentOutput)
   246  }
   247  
   248  // NetworkInterfaceSecurityGroupAttachmentArrayInput is an input type that accepts NetworkInterfaceSecurityGroupAttachmentArray and NetworkInterfaceSecurityGroupAttachmentArrayOutput values.
   249  // You can construct a concrete instance of `NetworkInterfaceSecurityGroupAttachmentArrayInput` via:
   250  //
   251  //	NetworkInterfaceSecurityGroupAttachmentArray{ NetworkInterfaceSecurityGroupAttachmentArgs{...} }
   252  type NetworkInterfaceSecurityGroupAttachmentArrayInput interface {
   253  	pulumi.Input
   254  
   255  	ToNetworkInterfaceSecurityGroupAttachmentArrayOutput() NetworkInterfaceSecurityGroupAttachmentArrayOutput
   256  	ToNetworkInterfaceSecurityGroupAttachmentArrayOutputWithContext(context.Context) NetworkInterfaceSecurityGroupAttachmentArrayOutput
   257  }
   258  
   259  type NetworkInterfaceSecurityGroupAttachmentArray []NetworkInterfaceSecurityGroupAttachmentInput
   260  
   261  func (NetworkInterfaceSecurityGroupAttachmentArray) ElementType() reflect.Type {
   262  	return reflect.TypeOf((*[]*NetworkInterfaceSecurityGroupAttachment)(nil)).Elem()
   263  }
   264  
   265  func (i NetworkInterfaceSecurityGroupAttachmentArray) ToNetworkInterfaceSecurityGroupAttachmentArrayOutput() NetworkInterfaceSecurityGroupAttachmentArrayOutput {
   266  	return i.ToNetworkInterfaceSecurityGroupAttachmentArrayOutputWithContext(context.Background())
   267  }
   268  
   269  func (i NetworkInterfaceSecurityGroupAttachmentArray) ToNetworkInterfaceSecurityGroupAttachmentArrayOutputWithContext(ctx context.Context) NetworkInterfaceSecurityGroupAttachmentArrayOutput {
   270  	return pulumi.ToOutputWithContext(ctx, i).(NetworkInterfaceSecurityGroupAttachmentArrayOutput)
   271  }
   272  
   273  // NetworkInterfaceSecurityGroupAttachmentMapInput is an input type that accepts NetworkInterfaceSecurityGroupAttachmentMap and NetworkInterfaceSecurityGroupAttachmentMapOutput values.
   274  // You can construct a concrete instance of `NetworkInterfaceSecurityGroupAttachmentMapInput` via:
   275  //
   276  //	NetworkInterfaceSecurityGroupAttachmentMap{ "key": NetworkInterfaceSecurityGroupAttachmentArgs{...} }
   277  type NetworkInterfaceSecurityGroupAttachmentMapInput interface {
   278  	pulumi.Input
   279  
   280  	ToNetworkInterfaceSecurityGroupAttachmentMapOutput() NetworkInterfaceSecurityGroupAttachmentMapOutput
   281  	ToNetworkInterfaceSecurityGroupAttachmentMapOutputWithContext(context.Context) NetworkInterfaceSecurityGroupAttachmentMapOutput
   282  }
   283  
   284  type NetworkInterfaceSecurityGroupAttachmentMap map[string]NetworkInterfaceSecurityGroupAttachmentInput
   285  
   286  func (NetworkInterfaceSecurityGroupAttachmentMap) ElementType() reflect.Type {
   287  	return reflect.TypeOf((*map[string]*NetworkInterfaceSecurityGroupAttachment)(nil)).Elem()
   288  }
   289  
   290  func (i NetworkInterfaceSecurityGroupAttachmentMap) ToNetworkInterfaceSecurityGroupAttachmentMapOutput() NetworkInterfaceSecurityGroupAttachmentMapOutput {
   291  	return i.ToNetworkInterfaceSecurityGroupAttachmentMapOutputWithContext(context.Background())
   292  }
   293  
   294  func (i NetworkInterfaceSecurityGroupAttachmentMap) ToNetworkInterfaceSecurityGroupAttachmentMapOutputWithContext(ctx context.Context) NetworkInterfaceSecurityGroupAttachmentMapOutput {
   295  	return pulumi.ToOutputWithContext(ctx, i).(NetworkInterfaceSecurityGroupAttachmentMapOutput)
   296  }
   297  
   298  type NetworkInterfaceSecurityGroupAttachmentOutput struct{ *pulumi.OutputState }
   299  
   300  func (NetworkInterfaceSecurityGroupAttachmentOutput) ElementType() reflect.Type {
   301  	return reflect.TypeOf((**NetworkInterfaceSecurityGroupAttachment)(nil)).Elem()
   302  }
   303  
   304  func (o NetworkInterfaceSecurityGroupAttachmentOutput) ToNetworkInterfaceSecurityGroupAttachmentOutput() NetworkInterfaceSecurityGroupAttachmentOutput {
   305  	return o
   306  }
   307  
   308  func (o NetworkInterfaceSecurityGroupAttachmentOutput) ToNetworkInterfaceSecurityGroupAttachmentOutputWithContext(ctx context.Context) NetworkInterfaceSecurityGroupAttachmentOutput {
   309  	return o
   310  }
   311  
   312  // The ID of the network interface to attach to.
   313  func (o NetworkInterfaceSecurityGroupAttachmentOutput) NetworkInterfaceId() pulumi.StringOutput {
   314  	return o.ApplyT(func(v *NetworkInterfaceSecurityGroupAttachment) pulumi.StringOutput { return v.NetworkInterfaceId }).(pulumi.StringOutput)
   315  }
   316  
   317  // The ID of the security group.
   318  func (o NetworkInterfaceSecurityGroupAttachmentOutput) SecurityGroupId() pulumi.StringOutput {
   319  	return o.ApplyT(func(v *NetworkInterfaceSecurityGroupAttachment) pulumi.StringOutput { return v.SecurityGroupId }).(pulumi.StringOutput)
   320  }
   321  
   322  type NetworkInterfaceSecurityGroupAttachmentArrayOutput struct{ *pulumi.OutputState }
   323  
   324  func (NetworkInterfaceSecurityGroupAttachmentArrayOutput) ElementType() reflect.Type {
   325  	return reflect.TypeOf((*[]*NetworkInterfaceSecurityGroupAttachment)(nil)).Elem()
   326  }
   327  
   328  func (o NetworkInterfaceSecurityGroupAttachmentArrayOutput) ToNetworkInterfaceSecurityGroupAttachmentArrayOutput() NetworkInterfaceSecurityGroupAttachmentArrayOutput {
   329  	return o
   330  }
   331  
   332  func (o NetworkInterfaceSecurityGroupAttachmentArrayOutput) ToNetworkInterfaceSecurityGroupAttachmentArrayOutputWithContext(ctx context.Context) NetworkInterfaceSecurityGroupAttachmentArrayOutput {
   333  	return o
   334  }
   335  
   336  func (o NetworkInterfaceSecurityGroupAttachmentArrayOutput) Index(i pulumi.IntInput) NetworkInterfaceSecurityGroupAttachmentOutput {
   337  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *NetworkInterfaceSecurityGroupAttachment {
   338  		return vs[0].([]*NetworkInterfaceSecurityGroupAttachment)[vs[1].(int)]
   339  	}).(NetworkInterfaceSecurityGroupAttachmentOutput)
   340  }
   341  
   342  type NetworkInterfaceSecurityGroupAttachmentMapOutput struct{ *pulumi.OutputState }
   343  
   344  func (NetworkInterfaceSecurityGroupAttachmentMapOutput) ElementType() reflect.Type {
   345  	return reflect.TypeOf((*map[string]*NetworkInterfaceSecurityGroupAttachment)(nil)).Elem()
   346  }
   347  
   348  func (o NetworkInterfaceSecurityGroupAttachmentMapOutput) ToNetworkInterfaceSecurityGroupAttachmentMapOutput() NetworkInterfaceSecurityGroupAttachmentMapOutput {
   349  	return o
   350  }
   351  
   352  func (o NetworkInterfaceSecurityGroupAttachmentMapOutput) ToNetworkInterfaceSecurityGroupAttachmentMapOutputWithContext(ctx context.Context) NetworkInterfaceSecurityGroupAttachmentMapOutput {
   353  	return o
   354  }
   355  
   356  func (o NetworkInterfaceSecurityGroupAttachmentMapOutput) MapIndex(k pulumi.StringInput) NetworkInterfaceSecurityGroupAttachmentOutput {
   357  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *NetworkInterfaceSecurityGroupAttachment {
   358  		return vs[0].(map[string]*NetworkInterfaceSecurityGroupAttachment)[vs[1].(string)]
   359  	}).(NetworkInterfaceSecurityGroupAttachmentOutput)
   360  }
   361  
   362  func init() {
   363  	pulumi.RegisterInputType(reflect.TypeOf((*NetworkInterfaceSecurityGroupAttachmentInput)(nil)).Elem(), &NetworkInterfaceSecurityGroupAttachment{})
   364  	pulumi.RegisterInputType(reflect.TypeOf((*NetworkInterfaceSecurityGroupAttachmentArrayInput)(nil)).Elem(), NetworkInterfaceSecurityGroupAttachmentArray{})
   365  	pulumi.RegisterInputType(reflect.TypeOf((*NetworkInterfaceSecurityGroupAttachmentMapInput)(nil)).Elem(), NetworkInterfaceSecurityGroupAttachmentMap{})
   366  	pulumi.RegisterOutputType(NetworkInterfaceSecurityGroupAttachmentOutput{})
   367  	pulumi.RegisterOutputType(NetworkInterfaceSecurityGroupAttachmentArrayOutput{})
   368  	pulumi.RegisterOutputType(NetworkInterfaceSecurityGroupAttachmentMapOutput{})
   369  }