1. Packages
  2. AWS
  3. API Docs
  4. ec2
  5. EipAssociation
AWS v6.77.0 published on Wednesday, Apr 9, 2025 by Pulumi

aws.ec2.EipAssociation

Explore with Pulumi AI

Provides an AWS EIP Association as a top level resource, to associate and disassociate Elastic IPs from AWS Instances and Network Interfaces.

NOTE: Do not use this resource to associate an EIP to aws.lb.LoadBalancer or aws.ec2.NatGateway resources. Instead use the allocation_id available in those resources to allow AWS to manage the association, otherwise you will see AuthFailure errors.

NOTE: aws.ec2.EipAssociation is useful in scenarios where EIPs are either pre-existing or distributed to customers or users and therefore cannot be changed.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const web = new aws.ec2.Instance("web", {
    ami: "ami-21f78e11",
    availabilityZone: "us-west-2a",
    instanceType: aws.ec2.InstanceType.T2_Micro,
    tags: {
        Name: "HelloWorld",
    },
});
const example = new aws.ec2.Eip("example", {domain: "vpc"});
const eipAssoc = new aws.ec2.EipAssociation("eip_assoc", {
    instanceId: web.id,
    allocationId: example.id,
});
Copy
import pulumi
import pulumi_aws as aws

web = aws.ec2.Instance("web",
    ami="ami-21f78e11",
    availability_zone="us-west-2a",
    instance_type=aws.ec2.InstanceType.T2_MICRO,
    tags={
        "Name": "HelloWorld",
    })
example = aws.ec2.Eip("example", domain="vpc")
eip_assoc = aws.ec2.EipAssociation("eip_assoc",
    instance_id=web.id,
    allocation_id=example.id)
Copy
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		web, err := ec2.NewInstance(ctx, "web", &ec2.InstanceArgs{
			Ami:              pulumi.String("ami-21f78e11"),
			AvailabilityZone: pulumi.String("us-west-2a"),
			InstanceType:     pulumi.String(ec2.InstanceType_T2_Micro),
			Tags: pulumi.StringMap{
				"Name": pulumi.String("HelloWorld"),
			},
		})
		if err != nil {
			return err
		}
		example, err := ec2.NewEip(ctx, "example", &ec2.EipArgs{
			Domain: pulumi.String("vpc"),
		})
		if err != nil {
			return err
		}
		_, err = ec2.NewEipAssociation(ctx, "eip_assoc", &ec2.EipAssociationArgs{
			InstanceId:   web.ID(),
			AllocationId: example.ID(),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var web = new Aws.Ec2.Instance("web", new()
    {
        Ami = "ami-21f78e11",
        AvailabilityZone = "us-west-2a",
        InstanceType = Aws.Ec2.InstanceType.T2_Micro,
        Tags = 
        {
            { "Name", "HelloWorld" },
        },
    });

    var example = new Aws.Ec2.Eip("example", new()
    {
        Domain = "vpc",
    });

    var eipAssoc = new Aws.Ec2.EipAssociation("eip_assoc", new()
    {
        InstanceId = web.Id,
        AllocationId = example.Id,
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.Instance;
import com.pulumi.aws.ec2.InstanceArgs;
import com.pulumi.aws.ec2.Eip;
import com.pulumi.aws.ec2.EipArgs;
import com.pulumi.aws.ec2.EipAssociation;
import com.pulumi.aws.ec2.EipAssociationArgs;
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) {
        var web = new Instance("web", InstanceArgs.builder()
            .ami("ami-21f78e11")
            .availabilityZone("us-west-2a")
            .instanceType("t2.micro")
            .tags(Map.of("Name", "HelloWorld"))
            .build());

        var example = new Eip("example", EipArgs.builder()
            .domain("vpc")
            .build());

        var eipAssoc = new EipAssociation("eipAssoc", EipAssociationArgs.builder()
            .instanceId(web.id())
            .allocationId(example.id())
            .build());

    }
}
Copy
resources:
  eipAssoc:
    type: aws:ec2:EipAssociation
    name: eip_assoc
    properties:
      instanceId: ${web.id}
      allocationId: ${example.id}
  web:
    type: aws:ec2:Instance
    properties:
      ami: ami-21f78e11
      availabilityZone: us-west-2a
      instanceType: t2.micro
      tags:
        Name: HelloWorld
  example:
    type: aws:ec2:Eip
    properties:
      domain: vpc
Copy

Create EipAssociation Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new EipAssociation(name: string, args?: EipAssociationArgs, opts?: CustomResourceOptions);
@overload
def EipAssociation(resource_name: str,
                   args: Optional[EipAssociationArgs] = None,
                   opts: Optional[ResourceOptions] = None)

@overload
def EipAssociation(resource_name: str,
                   opts: Optional[ResourceOptions] = None,
                   allocation_id: Optional[str] = None,
                   allow_reassociation: Optional[bool] = None,
                   instance_id: Optional[str] = None,
                   network_interface_id: Optional[str] = None,
                   private_ip_address: Optional[str] = None,
                   public_ip: Optional[str] = None)
func NewEipAssociation(ctx *Context, name string, args *EipAssociationArgs, opts ...ResourceOption) (*EipAssociation, error)
public EipAssociation(string name, EipAssociationArgs? args = null, CustomResourceOptions? opts = null)
public EipAssociation(String name, EipAssociationArgs args)
public EipAssociation(String name, EipAssociationArgs args, CustomResourceOptions options)
type: aws:ec2:EipAssociation
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args EipAssociationArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args EipAssociationArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args EipAssociationArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args EipAssociationArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. EipAssociationArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var eipAssociationResource = new Aws.Ec2.EipAssociation("eipAssociationResource", new()
{
    AllocationId = "string",
    AllowReassociation = false,
    InstanceId = "string",
    NetworkInterfaceId = "string",
    PrivateIpAddress = "string",
    PublicIp = "string",
});
Copy
example, err := ec2.NewEipAssociation(ctx, "eipAssociationResource", &ec2.EipAssociationArgs{
	AllocationId:       pulumi.String("string"),
	AllowReassociation: pulumi.Bool(false),
	InstanceId:         pulumi.String("string"),
	NetworkInterfaceId: pulumi.String("string"),
	PrivateIpAddress:   pulumi.String("string"),
	PublicIp:           pulumi.String("string"),
})
Copy
var eipAssociationResource = new EipAssociation("eipAssociationResource", EipAssociationArgs.builder()
    .allocationId("string")
    .allowReassociation(false)
    .instanceId("string")
    .networkInterfaceId("string")
    .privateIpAddress("string")
    .publicIp("string")
    .build());
Copy
eip_association_resource = aws.ec2.EipAssociation("eipAssociationResource",
    allocation_id="string",
    allow_reassociation=False,
    instance_id="string",
    network_interface_id="string",
    private_ip_address="string",
    public_ip="string")
Copy
const eipAssociationResource = new aws.ec2.EipAssociation("eipAssociationResource", {
    allocationId: "string",
    allowReassociation: false,
    instanceId: "string",
    networkInterfaceId: "string",
    privateIpAddress: "string",
    publicIp: "string",
});
Copy
type: aws:ec2:EipAssociation
properties:
    allocationId: string
    allowReassociation: false
    instanceId: string
    networkInterfaceId: string
    privateIpAddress: string
    publicIp: string
Copy

EipAssociation Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The EipAssociation resource accepts the following input properties:

AllocationId Changes to this property will trigger replacement. string
ID of the associated Elastic IP. This argument is required despite being optional at the resource level due to legacy support for EC2-Classic networking.
AllowReassociation Changes to this property will trigger replacement. bool
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
InstanceId Changes to this property will trigger replacement. string
ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.
NetworkInterfaceId Changes to this property will trigger replacement. string
ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID. You can specify either the instance ID or the network interface ID, but not both.
PrivateIpAddress Changes to this property will trigger replacement. string
Primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.
PublicIp Changes to this property will trigger replacement. string
) Address of the associated Elastic IP.
AllocationId Changes to this property will trigger replacement. string
ID of the associated Elastic IP. This argument is required despite being optional at the resource level due to legacy support for EC2-Classic networking.
AllowReassociation Changes to this property will trigger replacement. bool
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
InstanceId Changes to this property will trigger replacement. string
ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.
NetworkInterfaceId Changes to this property will trigger replacement. string
ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID. You can specify either the instance ID or the network interface ID, but not both.
PrivateIpAddress Changes to this property will trigger replacement. string
Primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.
PublicIp Changes to this property will trigger replacement. string
) Address of the associated Elastic IP.
allocationId Changes to this property will trigger replacement. String
ID of the associated Elastic IP. This argument is required despite being optional at the resource level due to legacy support for EC2-Classic networking.
allowReassociation Changes to this property will trigger replacement. Boolean
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
instanceId Changes to this property will trigger replacement. String
ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.
networkInterfaceId Changes to this property will trigger replacement. String
ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID. You can specify either the instance ID or the network interface ID, but not both.
privateIpAddress Changes to this property will trigger replacement. String
Primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.
publicIp Changes to this property will trigger replacement. String
) Address of the associated Elastic IP.
allocationId Changes to this property will trigger replacement. string
ID of the associated Elastic IP. This argument is required despite being optional at the resource level due to legacy support for EC2-Classic networking.
allowReassociation Changes to this property will trigger replacement. boolean
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
instanceId Changes to this property will trigger replacement. string
ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.
networkInterfaceId Changes to this property will trigger replacement. string
ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID. You can specify either the instance ID or the network interface ID, but not both.
privateIpAddress Changes to this property will trigger replacement. string
Primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.
publicIp Changes to this property will trigger replacement. string
) Address of the associated Elastic IP.
allocation_id Changes to this property will trigger replacement. str
ID of the associated Elastic IP. This argument is required despite being optional at the resource level due to legacy support for EC2-Classic networking.
allow_reassociation Changes to this property will trigger replacement. bool
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
instance_id Changes to this property will trigger replacement. str
ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.
network_interface_id Changes to this property will trigger replacement. str
ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID. You can specify either the instance ID or the network interface ID, but not both.
private_ip_address Changes to this property will trigger replacement. str
Primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.
public_ip Changes to this property will trigger replacement. str
) Address of the associated Elastic IP.
allocationId Changes to this property will trigger replacement. String
ID of the associated Elastic IP. This argument is required despite being optional at the resource level due to legacy support for EC2-Classic networking.
allowReassociation Changes to this property will trigger replacement. Boolean
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
instanceId Changes to this property will trigger replacement. String
ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.
networkInterfaceId Changes to this property will trigger replacement. String
ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID. You can specify either the instance ID or the network interface ID, but not both.
privateIpAddress Changes to this property will trigger replacement. String
Primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.
publicIp Changes to this property will trigger replacement. String
) Address of the associated Elastic IP.

Outputs

All input properties are implicitly available as output properties. Additionally, the EipAssociation resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing EipAssociation Resource

Get an existing EipAssociation resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: EipAssociationState, opts?: CustomResourceOptions): EipAssociation
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        allocation_id: Optional[str] = None,
        allow_reassociation: Optional[bool] = None,
        instance_id: Optional[str] = None,
        network_interface_id: Optional[str] = None,
        private_ip_address: Optional[str] = None,
        public_ip: Optional[str] = None) -> EipAssociation
func GetEipAssociation(ctx *Context, name string, id IDInput, state *EipAssociationState, opts ...ResourceOption) (*EipAssociation, error)
public static EipAssociation Get(string name, Input<string> id, EipAssociationState? state, CustomResourceOptions? opts = null)
public static EipAssociation get(String name, Output<String> id, EipAssociationState state, CustomResourceOptions options)
resources:  _:    type: aws:ec2:EipAssociation    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
AllocationId Changes to this property will trigger replacement. string
ID of the associated Elastic IP. This argument is required despite being optional at the resource level due to legacy support for EC2-Classic networking.
AllowReassociation Changes to this property will trigger replacement. bool
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
InstanceId Changes to this property will trigger replacement. string
ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.
NetworkInterfaceId Changes to this property will trigger replacement. string
ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID. You can specify either the instance ID or the network interface ID, but not both.
PrivateIpAddress Changes to this property will trigger replacement. string
Primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.
PublicIp Changes to this property will trigger replacement. string
) Address of the associated Elastic IP.
AllocationId Changes to this property will trigger replacement. string
ID of the associated Elastic IP. This argument is required despite being optional at the resource level due to legacy support for EC2-Classic networking.
AllowReassociation Changes to this property will trigger replacement. bool
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
InstanceId Changes to this property will trigger replacement. string
ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.
NetworkInterfaceId Changes to this property will trigger replacement. string
ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID. You can specify either the instance ID or the network interface ID, but not both.
PrivateIpAddress Changes to this property will trigger replacement. string
Primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.
PublicIp Changes to this property will trigger replacement. string
) Address of the associated Elastic IP.
allocationId Changes to this property will trigger replacement. String
ID of the associated Elastic IP. This argument is required despite being optional at the resource level due to legacy support for EC2-Classic networking.
allowReassociation Changes to this property will trigger replacement. Boolean
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
instanceId Changes to this property will trigger replacement. String
ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.
networkInterfaceId Changes to this property will trigger replacement. String
ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID. You can specify either the instance ID or the network interface ID, but not both.
privateIpAddress Changes to this property will trigger replacement. String
Primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.
publicIp Changes to this property will trigger replacement. String
) Address of the associated Elastic IP.
allocationId Changes to this property will trigger replacement. string
ID of the associated Elastic IP. This argument is required despite being optional at the resource level due to legacy support for EC2-Classic networking.
allowReassociation Changes to this property will trigger replacement. boolean
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
instanceId Changes to this property will trigger replacement. string
ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.
networkInterfaceId Changes to this property will trigger replacement. string
ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID. You can specify either the instance ID or the network interface ID, but not both.
privateIpAddress Changes to this property will trigger replacement. string
Primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.
publicIp Changes to this property will trigger replacement. string
) Address of the associated Elastic IP.
allocation_id Changes to this property will trigger replacement. str
ID of the associated Elastic IP. This argument is required despite being optional at the resource level due to legacy support for EC2-Classic networking.
allow_reassociation Changes to this property will trigger replacement. bool
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
instance_id Changes to this property will trigger replacement. str
ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.
network_interface_id Changes to this property will trigger replacement. str
ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID. You can specify either the instance ID or the network interface ID, but not both.
private_ip_address Changes to this property will trigger replacement. str
Primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.
public_ip Changes to this property will trigger replacement. str
) Address of the associated Elastic IP.
allocationId Changes to this property will trigger replacement. String
ID of the associated Elastic IP. This argument is required despite being optional at the resource level due to legacy support for EC2-Classic networking.
allowReassociation Changes to this property will trigger replacement. Boolean
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
instanceId Changes to this property will trigger replacement. String
ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.
networkInterfaceId Changes to this property will trigger replacement. String
ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID. You can specify either the instance ID or the network interface ID, but not both.
privateIpAddress Changes to this property will trigger replacement. String
Primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.
publicIp Changes to this property will trigger replacement. String
) Address of the associated Elastic IP.

Import

Using pulumi import, import EIP Assocations using their association IDs. For example:

$ pulumi import aws:ec2/eipAssociation:EipAssociation test eipassoc-ab12c345
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
AWS Classic pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.