EipAssociation class

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 allocationId 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,
});
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)
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,
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/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().ToIDOutput().ToStringOutput(),
			AllocationId: example.ID().ToIDOutput().ToStringOutput(),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_ec2_eipassociation" "eip_assoc" {
  instance_id   = aws_ec2_instance.web.id
  allocation_id = aws_ec2_eip.example.id
}
resource "aws_ec2_instance" "web" {
  ami               = "ami-21f78e11"
  availability_zone = "us-west-2a"
  instance_type     = "t2.micro"
  tags = {
    "Name" = "HelloWorld"
  }
}
resource "aws_ec2_eip" "example" {
  domain = "vpc"
}
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.ArrayList;
import java.util.Arrays;
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());

    }
}
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

Import

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

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

Constructors

EipAssociation(String name, {EipAssociationArgs? args, CustomResourceOptions? options})
Creates a new EipAssociation. name The Pulumi resource name. args Arguments used to configure this EipAssociation. The set of arguments for EipAssociation. options Resource options controlling this resource's behavior.
EipAssociation.reference(String urn)
Creates a typed reference to an existing EipAssociation resource.

Properties

allocationId ↔ Output<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.
latefinal
allowReassociation ↔ Output<bool?>
Whether to allow an Elastic IP address to be re-associated. Defaults to true.
latefinal
childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
hashCode → int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
instanceId ↔ Output<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.
latefinal
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
networkInterfaceId ↔ Output<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.
latefinal
privateIpAddress ↔ Output<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.
latefinal
publicIp ↔ Output<String>
) Address of the associated Elastic IP.
latefinal
region ↔ Output<String>
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {EipAssociationState? state, CustomResourceOptions? options}) → EipAssociation
Gets an existing EipAssociation resource's state with the given name and id.