github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/ec2/eipAssociation.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  	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
    11  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    12  )
    13  
    14  // Provides an AWS EIP Association as a top level resource, to associate and
    15  // disassociate Elastic IPs from AWS Instances and Network Interfaces.
    16  //
    17  // > **NOTE:** Do not use this resource to associate an EIP to `lb.LoadBalancer` or `ec2.NatGateway` resources. Instead use the `allocationId` available in those resources to allow AWS to manage the association, otherwise you will see `AuthFailure` errors.
    18  //
    19  // > **NOTE:** `ec2.EipAssociation` is useful in scenarios where EIPs are either
    20  // pre-existing or distributed to customers or users and therefore cannot be changed.
    21  //
    22  // ## Example Usage
    23  //
    24  // <!--Start PulumiCodeChooser -->
    25  // ```go
    26  // package main
    27  //
    28  // import (
    29  //
    30  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    31  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    32  //
    33  // )
    34  //
    35  //	func main() {
    36  //		pulumi.Run(func(ctx *pulumi.Context) error {
    37  //			web, err := ec2.NewInstance(ctx, "web", &ec2.InstanceArgs{
    38  //				Ami:              pulumi.String("ami-21f78e11"),
    39  //				AvailabilityZone: pulumi.String("us-west-2a"),
    40  //				InstanceType:     pulumi.String(ec2.InstanceType_T2_Micro),
    41  //				Tags: pulumi.StringMap{
    42  //					"Name": pulumi.String("HelloWorld"),
    43  //				},
    44  //			})
    45  //			if err != nil {
    46  //				return err
    47  //			}
    48  //			example, err := ec2.NewEip(ctx, "example", &ec2.EipArgs{
    49  //				Domain: pulumi.String("vpc"),
    50  //			})
    51  //			if err != nil {
    52  //				return err
    53  //			}
    54  //			_, err = ec2.NewEipAssociation(ctx, "eip_assoc", &ec2.EipAssociationArgs{
    55  //				InstanceId:   web.ID(),
    56  //				AllocationId: example.ID(),
    57  //			})
    58  //			if err != nil {
    59  //				return err
    60  //			}
    61  //			return nil
    62  //		})
    63  //	}
    64  //
    65  // ```
    66  // <!--End PulumiCodeChooser -->
    67  //
    68  // ## Import
    69  //
    70  // Using `pulumi import`, import EIP Assocations using their association IDs. For example:
    71  //
    72  // ```sh
    73  // $ pulumi import aws:ec2/eipAssociation:EipAssociation test eipassoc-ab12c345
    74  // ```
    75  type EipAssociation struct {
    76  	pulumi.CustomResourceState
    77  
    78  	// The allocation ID. This is required for EC2-VPC.
    79  	AllocationId pulumi.StringOutput `pulumi:"allocationId"`
    80  	// Whether to allow an Elastic IP to
    81  	// be re-associated. Defaults to `true` in VPC.
    82  	AllowReassociation pulumi.BoolPtrOutput `pulumi:"allowReassociation"`
    83  	// The ID of the instance. This is required for
    84  	// EC2-Classic. For EC2-VPC, you can specify either the instance ID or the
    85  	// network interface ID, but not both. The operation fails if you specify an
    86  	// instance ID unless exactly one network interface is attached.
    87  	InstanceId pulumi.StringOutput `pulumi:"instanceId"`
    88  	// The ID of the network interface. If the
    89  	// instance has more than one network interface, you must specify a network
    90  	// interface ID.
    91  	NetworkInterfaceId pulumi.StringOutput `pulumi:"networkInterfaceId"`
    92  	// The primary or secondary private IP address
    93  	// to associate with the Elastic IP address. If no private IP address is
    94  	// specified, the Elastic IP address is associated with the primary private IP
    95  	// address.
    96  	PrivateIpAddress pulumi.StringOutput `pulumi:"privateIpAddress"`
    97  	// The Elastic IP address. This is required for EC2-Classic.
    98  	PublicIp pulumi.StringOutput `pulumi:"publicIp"`
    99  }
   100  
   101  // NewEipAssociation registers a new resource with the given unique name, arguments, and options.
   102  func NewEipAssociation(ctx *pulumi.Context,
   103  	name string, args *EipAssociationArgs, opts ...pulumi.ResourceOption) (*EipAssociation, error) {
   104  	if args == nil {
   105  		args = &EipAssociationArgs{}
   106  	}
   107  
   108  	opts = internal.PkgResourceDefaultOpts(opts)
   109  	var resource EipAssociation
   110  	err := ctx.RegisterResource("aws:ec2/eipAssociation:EipAssociation", name, args, &resource, opts...)
   111  	if err != nil {
   112  		return nil, err
   113  	}
   114  	return &resource, nil
   115  }
   116  
   117  // GetEipAssociation gets an existing EipAssociation resource's state with the given name, ID, and optional
   118  // state properties that are used to uniquely qualify the lookup (nil if not required).
   119  func GetEipAssociation(ctx *pulumi.Context,
   120  	name string, id pulumi.IDInput, state *EipAssociationState, opts ...pulumi.ResourceOption) (*EipAssociation, error) {
   121  	var resource EipAssociation
   122  	err := ctx.ReadResource("aws:ec2/eipAssociation:EipAssociation", name, id, state, &resource, opts...)
   123  	if err != nil {
   124  		return nil, err
   125  	}
   126  	return &resource, nil
   127  }
   128  
   129  // Input properties used for looking up and filtering EipAssociation resources.
   130  type eipAssociationState struct {
   131  	// The allocation ID. This is required for EC2-VPC.
   132  	AllocationId *string `pulumi:"allocationId"`
   133  	// Whether to allow an Elastic IP to
   134  	// be re-associated. Defaults to `true` in VPC.
   135  	AllowReassociation *bool `pulumi:"allowReassociation"`
   136  	// The ID of the instance. This is required for
   137  	// EC2-Classic. For EC2-VPC, you can specify either the instance ID or the
   138  	// network interface ID, but not both. The operation fails if you specify an
   139  	// instance ID unless exactly one network interface is attached.
   140  	InstanceId *string `pulumi:"instanceId"`
   141  	// The ID of the network interface. If the
   142  	// instance has more than one network interface, you must specify a network
   143  	// interface ID.
   144  	NetworkInterfaceId *string `pulumi:"networkInterfaceId"`
   145  	// The primary or secondary private IP address
   146  	// to associate with the Elastic IP address. If no private IP address is
   147  	// specified, the Elastic IP address is associated with the primary private IP
   148  	// address.
   149  	PrivateIpAddress *string `pulumi:"privateIpAddress"`
   150  	// The Elastic IP address. This is required for EC2-Classic.
   151  	PublicIp *string `pulumi:"publicIp"`
   152  }
   153  
   154  type EipAssociationState struct {
   155  	// The allocation ID. This is required for EC2-VPC.
   156  	AllocationId pulumi.StringPtrInput
   157  	// Whether to allow an Elastic IP to
   158  	// be re-associated. Defaults to `true` in VPC.
   159  	AllowReassociation pulumi.BoolPtrInput
   160  	// The ID of the instance. This is required for
   161  	// EC2-Classic. For EC2-VPC, you can specify either the instance ID or the
   162  	// network interface ID, but not both. The operation fails if you specify an
   163  	// instance ID unless exactly one network interface is attached.
   164  	InstanceId pulumi.StringPtrInput
   165  	// The ID of the network interface. If the
   166  	// instance has more than one network interface, you must specify a network
   167  	// interface ID.
   168  	NetworkInterfaceId pulumi.StringPtrInput
   169  	// The primary or secondary private IP address
   170  	// to associate with the Elastic IP address. If no private IP address is
   171  	// specified, the Elastic IP address is associated with the primary private IP
   172  	// address.
   173  	PrivateIpAddress pulumi.StringPtrInput
   174  	// The Elastic IP address. This is required for EC2-Classic.
   175  	PublicIp pulumi.StringPtrInput
   176  }
   177  
   178  func (EipAssociationState) ElementType() reflect.Type {
   179  	return reflect.TypeOf((*eipAssociationState)(nil)).Elem()
   180  }
   181  
   182  type eipAssociationArgs struct {
   183  	// The allocation ID. This is required for EC2-VPC.
   184  	AllocationId *string `pulumi:"allocationId"`
   185  	// Whether to allow an Elastic IP to
   186  	// be re-associated. Defaults to `true` in VPC.
   187  	AllowReassociation *bool `pulumi:"allowReassociation"`
   188  	// The ID of the instance. This is required for
   189  	// EC2-Classic. For EC2-VPC, you can specify either the instance ID or the
   190  	// network interface ID, but not both. The operation fails if you specify an
   191  	// instance ID unless exactly one network interface is attached.
   192  	InstanceId *string `pulumi:"instanceId"`
   193  	// The ID of the network interface. If the
   194  	// instance has more than one network interface, you must specify a network
   195  	// interface ID.
   196  	NetworkInterfaceId *string `pulumi:"networkInterfaceId"`
   197  	// The primary or secondary private IP address
   198  	// to associate with the Elastic IP address. If no private IP address is
   199  	// specified, the Elastic IP address is associated with the primary private IP
   200  	// address.
   201  	PrivateIpAddress *string `pulumi:"privateIpAddress"`
   202  	// The Elastic IP address. This is required for EC2-Classic.
   203  	PublicIp *string `pulumi:"publicIp"`
   204  }
   205  
   206  // The set of arguments for constructing a EipAssociation resource.
   207  type EipAssociationArgs struct {
   208  	// The allocation ID. This is required for EC2-VPC.
   209  	AllocationId pulumi.StringPtrInput
   210  	// Whether to allow an Elastic IP to
   211  	// be re-associated. Defaults to `true` in VPC.
   212  	AllowReassociation pulumi.BoolPtrInput
   213  	// The ID of the instance. This is required for
   214  	// EC2-Classic. For EC2-VPC, you can specify either the instance ID or the
   215  	// network interface ID, but not both. The operation fails if you specify an
   216  	// instance ID unless exactly one network interface is attached.
   217  	InstanceId pulumi.StringPtrInput
   218  	// The ID of the network interface. If the
   219  	// instance has more than one network interface, you must specify a network
   220  	// interface ID.
   221  	NetworkInterfaceId pulumi.StringPtrInput
   222  	// The primary or secondary private IP address
   223  	// to associate with the Elastic IP address. If no private IP address is
   224  	// specified, the Elastic IP address is associated with the primary private IP
   225  	// address.
   226  	PrivateIpAddress pulumi.StringPtrInput
   227  	// The Elastic IP address. This is required for EC2-Classic.
   228  	PublicIp pulumi.StringPtrInput
   229  }
   230  
   231  func (EipAssociationArgs) ElementType() reflect.Type {
   232  	return reflect.TypeOf((*eipAssociationArgs)(nil)).Elem()
   233  }
   234  
   235  type EipAssociationInput interface {
   236  	pulumi.Input
   237  
   238  	ToEipAssociationOutput() EipAssociationOutput
   239  	ToEipAssociationOutputWithContext(ctx context.Context) EipAssociationOutput
   240  }
   241  
   242  func (*EipAssociation) ElementType() reflect.Type {
   243  	return reflect.TypeOf((**EipAssociation)(nil)).Elem()
   244  }
   245  
   246  func (i *EipAssociation) ToEipAssociationOutput() EipAssociationOutput {
   247  	return i.ToEipAssociationOutputWithContext(context.Background())
   248  }
   249  
   250  func (i *EipAssociation) ToEipAssociationOutputWithContext(ctx context.Context) EipAssociationOutput {
   251  	return pulumi.ToOutputWithContext(ctx, i).(EipAssociationOutput)
   252  }
   253  
   254  // EipAssociationArrayInput is an input type that accepts EipAssociationArray and EipAssociationArrayOutput values.
   255  // You can construct a concrete instance of `EipAssociationArrayInput` via:
   256  //
   257  //	EipAssociationArray{ EipAssociationArgs{...} }
   258  type EipAssociationArrayInput interface {
   259  	pulumi.Input
   260  
   261  	ToEipAssociationArrayOutput() EipAssociationArrayOutput
   262  	ToEipAssociationArrayOutputWithContext(context.Context) EipAssociationArrayOutput
   263  }
   264  
   265  type EipAssociationArray []EipAssociationInput
   266  
   267  func (EipAssociationArray) ElementType() reflect.Type {
   268  	return reflect.TypeOf((*[]*EipAssociation)(nil)).Elem()
   269  }
   270  
   271  func (i EipAssociationArray) ToEipAssociationArrayOutput() EipAssociationArrayOutput {
   272  	return i.ToEipAssociationArrayOutputWithContext(context.Background())
   273  }
   274  
   275  func (i EipAssociationArray) ToEipAssociationArrayOutputWithContext(ctx context.Context) EipAssociationArrayOutput {
   276  	return pulumi.ToOutputWithContext(ctx, i).(EipAssociationArrayOutput)
   277  }
   278  
   279  // EipAssociationMapInput is an input type that accepts EipAssociationMap and EipAssociationMapOutput values.
   280  // You can construct a concrete instance of `EipAssociationMapInput` via:
   281  //
   282  //	EipAssociationMap{ "key": EipAssociationArgs{...} }
   283  type EipAssociationMapInput interface {
   284  	pulumi.Input
   285  
   286  	ToEipAssociationMapOutput() EipAssociationMapOutput
   287  	ToEipAssociationMapOutputWithContext(context.Context) EipAssociationMapOutput
   288  }
   289  
   290  type EipAssociationMap map[string]EipAssociationInput
   291  
   292  func (EipAssociationMap) ElementType() reflect.Type {
   293  	return reflect.TypeOf((*map[string]*EipAssociation)(nil)).Elem()
   294  }
   295  
   296  func (i EipAssociationMap) ToEipAssociationMapOutput() EipAssociationMapOutput {
   297  	return i.ToEipAssociationMapOutputWithContext(context.Background())
   298  }
   299  
   300  func (i EipAssociationMap) ToEipAssociationMapOutputWithContext(ctx context.Context) EipAssociationMapOutput {
   301  	return pulumi.ToOutputWithContext(ctx, i).(EipAssociationMapOutput)
   302  }
   303  
   304  type EipAssociationOutput struct{ *pulumi.OutputState }
   305  
   306  func (EipAssociationOutput) ElementType() reflect.Type {
   307  	return reflect.TypeOf((**EipAssociation)(nil)).Elem()
   308  }
   309  
   310  func (o EipAssociationOutput) ToEipAssociationOutput() EipAssociationOutput {
   311  	return o
   312  }
   313  
   314  func (o EipAssociationOutput) ToEipAssociationOutputWithContext(ctx context.Context) EipAssociationOutput {
   315  	return o
   316  }
   317  
   318  // The allocation ID. This is required for EC2-VPC.
   319  func (o EipAssociationOutput) AllocationId() pulumi.StringOutput {
   320  	return o.ApplyT(func(v *EipAssociation) pulumi.StringOutput { return v.AllocationId }).(pulumi.StringOutput)
   321  }
   322  
   323  // Whether to allow an Elastic IP to
   324  // be re-associated. Defaults to `true` in VPC.
   325  func (o EipAssociationOutput) AllowReassociation() pulumi.BoolPtrOutput {
   326  	return o.ApplyT(func(v *EipAssociation) pulumi.BoolPtrOutput { return v.AllowReassociation }).(pulumi.BoolPtrOutput)
   327  }
   328  
   329  // The ID of the instance. This is required for
   330  // EC2-Classic. For EC2-VPC, you can specify either the instance ID or the
   331  // network interface ID, but not both. The operation fails if you specify an
   332  // instance ID unless exactly one network interface is attached.
   333  func (o EipAssociationOutput) InstanceId() pulumi.StringOutput {
   334  	return o.ApplyT(func(v *EipAssociation) pulumi.StringOutput { return v.InstanceId }).(pulumi.StringOutput)
   335  }
   336  
   337  // The ID of the network interface. If the
   338  // instance has more than one network interface, you must specify a network
   339  // interface ID.
   340  func (o EipAssociationOutput) NetworkInterfaceId() pulumi.StringOutput {
   341  	return o.ApplyT(func(v *EipAssociation) pulumi.StringOutput { return v.NetworkInterfaceId }).(pulumi.StringOutput)
   342  }
   343  
   344  // The primary or secondary private IP address
   345  // to associate with the Elastic IP address. If no private IP address is
   346  // specified, the Elastic IP address is associated with the primary private IP
   347  // address.
   348  func (o EipAssociationOutput) PrivateIpAddress() pulumi.StringOutput {
   349  	return o.ApplyT(func(v *EipAssociation) pulumi.StringOutput { return v.PrivateIpAddress }).(pulumi.StringOutput)
   350  }
   351  
   352  // The Elastic IP address. This is required for EC2-Classic.
   353  func (o EipAssociationOutput) PublicIp() pulumi.StringOutput {
   354  	return o.ApplyT(func(v *EipAssociation) pulumi.StringOutput { return v.PublicIp }).(pulumi.StringOutput)
   355  }
   356  
   357  type EipAssociationArrayOutput struct{ *pulumi.OutputState }
   358  
   359  func (EipAssociationArrayOutput) ElementType() reflect.Type {
   360  	return reflect.TypeOf((*[]*EipAssociation)(nil)).Elem()
   361  }
   362  
   363  func (o EipAssociationArrayOutput) ToEipAssociationArrayOutput() EipAssociationArrayOutput {
   364  	return o
   365  }
   366  
   367  func (o EipAssociationArrayOutput) ToEipAssociationArrayOutputWithContext(ctx context.Context) EipAssociationArrayOutput {
   368  	return o
   369  }
   370  
   371  func (o EipAssociationArrayOutput) Index(i pulumi.IntInput) EipAssociationOutput {
   372  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *EipAssociation {
   373  		return vs[0].([]*EipAssociation)[vs[1].(int)]
   374  	}).(EipAssociationOutput)
   375  }
   376  
   377  type EipAssociationMapOutput struct{ *pulumi.OutputState }
   378  
   379  func (EipAssociationMapOutput) ElementType() reflect.Type {
   380  	return reflect.TypeOf((*map[string]*EipAssociation)(nil)).Elem()
   381  }
   382  
   383  func (o EipAssociationMapOutput) ToEipAssociationMapOutput() EipAssociationMapOutput {
   384  	return o
   385  }
   386  
   387  func (o EipAssociationMapOutput) ToEipAssociationMapOutputWithContext(ctx context.Context) EipAssociationMapOutput {
   388  	return o
   389  }
   390  
   391  func (o EipAssociationMapOutput) MapIndex(k pulumi.StringInput) EipAssociationOutput {
   392  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *EipAssociation {
   393  		return vs[0].(map[string]*EipAssociation)[vs[1].(string)]
   394  	}).(EipAssociationOutput)
   395  }
   396  
   397  func init() {
   398  	pulumi.RegisterInputType(reflect.TypeOf((*EipAssociationInput)(nil)).Elem(), &EipAssociation{})
   399  	pulumi.RegisterInputType(reflect.TypeOf((*EipAssociationArrayInput)(nil)).Elem(), EipAssociationArray{})
   400  	pulumi.RegisterInputType(reflect.TypeOf((*EipAssociationMapInput)(nil)).Elem(), EipAssociationMap{})
   401  	pulumi.RegisterOutputType(EipAssociationOutput{})
   402  	pulumi.RegisterOutputType(EipAssociationArrayOutput{})
   403  	pulumi.RegisterOutputType(EipAssociationMapOutput{})
   404  }