Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_eip: deprecate vpc attribute #31567

Merged
merged 10 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/31567.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_eip: Deprecate `vpc` attribute. Use `domain` instead
```
2 changes: 1 addition & 1 deletion examples/eip/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ provider "aws" {

resource "aws_eip" "default" {
instance = aws_instance.web.id
vpc = true
domain = "vpc"
}

# Our default security group to access
Expand Down
2 changes: 1 addition & 1 deletion internal/service/codebuild/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5182,7 +5182,7 @@ resource "aws_subnet" "private" {
}

resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand Down
23 changes: 17 additions & 6 deletions internal/service/ec2/ec2_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
Expand Down Expand Up @@ -72,8 +73,12 @@ func ResourceEIP() *schema.Resource {
Optional: true,
},
"domain": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
ForceNew: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this and vpc are both marked ForceNew, will it destroy an existing EIP if someone updates their config from vpc = true to domain = "vpc"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call. It does not. I went ahead and added a test to verify

$ make testacc TESTS="TestAccEC2EIP_migrateVPCToDomain" PKG=ec2

==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccEC2EIP_migrateVPCToDomain'  -timeout 180m
--- PASS: TestAccEC2EIP_migrateVPCToDomain (30.98s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	34.189s

Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice(ec2.DomainType_Values(), false),
ConflictsWith: []string{"vpc"},
},
"instance": {
Type: schema.TypeString,
Expand Down Expand Up @@ -116,10 +121,12 @@ func ResourceEIP() *schema.Resource {
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"vpc": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Computed: true,
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Computed: true,
Deprecated: "use domain attribute instead",
ConflictsWith: []string{"domain"},
},
},
}
Expand All @@ -141,6 +148,10 @@ func resourceEIPCreate(ctx context.Context, d *schema.ResourceData, meta interfa
input.CustomerOwnedIpv4Pool = aws.String(v.(string))
}

if v := d.Get("domain"); v != nil && v.(string) != "" {
input.Domain = aws.String(v.(string))
}

if v := d.Get("vpc"); v != nil && v.(bool) {
input.Domain = aws.String(ec2.DomainTypeVpc)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/service/ec2/ec2_eip_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ resource "aws_instance" "test" {
}

resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand Down Expand Up @@ -269,7 +269,7 @@ resource "aws_instance" "test" {
resource "aws_eip" "test" {
count = 2

vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand Down Expand Up @@ -307,7 +307,7 @@ resource "aws_network_interface" "test" {
}

resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand Down Expand Up @@ -364,7 +364,7 @@ resource "aws_ec2_tag" "test" {
}

resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand Down
8 changes: 4 additions & 4 deletions internal/service/ec2/ec2_eip_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestAccEC2EIPDataSource_customerOwnedIPv4Pool(t *testing.T) {
func testAccEIPDataSourceConfig_filter(rName string) string {
return fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand All @@ -217,7 +217,7 @@ data "aws_eip" "test" {
func testAccEIPDataSourceConfig_id(rName string) string {
return fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand All @@ -233,7 +233,7 @@ data "aws_eip" "test" {
func testAccEIPDataSourceConfig_publicIP(rName string) string {
return fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand All @@ -249,7 +249,7 @@ data "aws_eip" "test" {
func testAccEIPDataSourceConfig_tags(rName string) string {
return fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand Down
78 changes: 59 additions & 19 deletions internal/service/ec2/ec2_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,40 @@ func TestAccEC2EIP_disappears(t *testing.T) {
})
}

func TestAccEC2EIP_migrateVPCToDomain(t *testing.T) {
ctx := acctest.Context(t)
var conf ec2.Address
resourceName := "aws_eip.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID),
CheckDestroy: testAccCheckEIPDestroy(ctx),
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
Source: "hashicorp/aws",
VersionConstraint: "4.67.0",
},
},
Config: testAccEIPConfig_vpc,
Check: resource.ComposeTestCheckFunc(
testAccCheckEIPExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "domain", "vpc"),
resource.TestCheckResourceAttrSet(resourceName, "public_ip"),
testAccCheckEIPPublicDNS(resourceName),
),
},
{
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Config: testAccEIPConfig_basic,
PlanOnly: true,
},
},
})
}

func TestAccEC2EIP_noVPC(t *testing.T) {
ctx := acctest.Context(t)
var conf ec2.Address
Expand Down Expand Up @@ -737,6 +771,12 @@ func testAccCheckEIPPublicDNS(resourceName string) resource.TestCheckFunc {
}

const testAccEIPConfig_basic = `
resource "aws_eip" "test" {
domain = "vpc"
}
`

const testAccEIPConfig_vpc = `
resource "aws_eip" "test" {
vpc = true
}
Expand All @@ -762,7 +802,7 @@ resource "aws_eip" "test" {
func testAccEIPConfig_tags2(tagKey1, tagValue1, tagKey2, tagValue2 string) string {
return fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
%[1]q = %[2]q
Expand Down Expand Up @@ -802,7 +842,7 @@ func testAccEIPConfig_instance(rName string) string {
return acctest.ConfigCompose(testAccEIPConfig_baseInstance(rName), fmt.Sprintf(`
resource "aws_eip" "test" {
instance = aws_instance.test.id
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand All @@ -819,7 +859,7 @@ func testAccEIPConfig_instanceReassociate(rName string) string {
fmt.Sprintf(`
resource "aws_eip" "test" {
instance = aws_instance.test.id
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand Down Expand Up @@ -924,7 +964,7 @@ resource "aws_instance" "test" {
func testAccEIPConfig_instanceAssociated(rName string) string {
return acctest.ConfigCompose(testAccEIPConfig_baseInstanceAssociated(rName), fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

instance = aws_instance.test[1].id
associate_with_private_ip = aws_instance.test[1].private_ip
Expand All @@ -939,7 +979,7 @@ resource "aws_eip" "test" {
func testAccEIPConfig_instanceAssociatedSwitch(rName string) string {
return acctest.ConfigCompose(testAccEIPConfig_baseInstanceAssociated(rName), fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

instance = aws_instance.test[0].id
associate_with_private_ip = aws_instance.test[0].private_ip
Expand All @@ -954,7 +994,7 @@ resource "aws_eip" "test" {
func testAccEIPConfig_instanceAssociateNotAssociated(rName string) string {
return acctest.ConfigCompose(testAccEIPConfig_baseInstance(rName), fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand Down Expand Up @@ -984,7 +1024,7 @@ resource "aws_network_interface" "test" {
}

resource "aws_eip" "test" {
vpc = "true"
domain = "vpc"
network_interface = aws_network_interface.test.id

tags = {
Expand Down Expand Up @@ -1019,7 +1059,7 @@ resource "aws_network_interface" "test" {
resource "aws_eip" "test" {
count = 2

vpc = "true"
domain = "vpc"
network_interface = aws_network_interface.test.id
associate_with_private_ip = "10.0.0.1${count.index}"

Expand Down Expand Up @@ -1051,7 +1091,7 @@ resource "aws_network_interface" "test" {
func testAccEIPConfig_associationNone(rName string) string {
return acctest.ConfigCompose(testAccEIPConfig_baseAssociation(rName), fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand All @@ -1065,7 +1105,7 @@ resource "aws_eip" "test" {
func testAccEIPConfig_associationENI(rName string) string {
return acctest.ConfigCompose(testAccEIPConfig_baseAssociation(rName), fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand All @@ -1079,7 +1119,7 @@ resource "aws_eip" "test" {
func testAccEIPConfig_associationInstance(rName string) string {
return acctest.ConfigCompose(testAccEIPConfig_baseAssociation(rName), fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand All @@ -1095,7 +1135,7 @@ resource "aws_eip" "test" {
func testAccEIPConfig_publicIPv4PoolDefault(rName string) string {
return fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand All @@ -1107,7 +1147,7 @@ resource "aws_eip" "test" {
func testAccEIPConfig_publicIPv4PoolCustom(rName, poolName string) string {
return fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"
public_ipv4_pool = %[2]q

tags = {
Expand All @@ -1123,7 +1163,7 @@ data "aws_ec2_coip_pools" "test" {}

resource "aws_eip" "test" {
customer_owned_ipv4_pool = tolist(data.aws_ec2_coip_pools.test.pool_ids)[0]
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand All @@ -1137,7 +1177,7 @@ func testAccEIPConfig_networkBorderGroup(rName string) string {
data "aws_region" current {}

resource "aws_eip" "test" {
vpc = true
domain = "vpc"
network_border_group = data.aws_region.current.name

tags = {
Expand All @@ -1156,7 +1196,7 @@ data "aws_availability_zone" "available" {
}

resource "aws_eip" "test" {
vpc = true
domain = "vpc"
network_border_group = data.aws_availability_zone.available.network_border_group

tags = {
Expand All @@ -1169,7 +1209,7 @@ resource "aws_eip" "test" {
func testAccEIPConfig_byoipAddressCustomDefault(rName string) string {
return fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"

tags = {
Name = %[1]q
Expand All @@ -1181,7 +1221,7 @@ resource "aws_eip" "test" {
func testAccEIPConfig_byoipAddressCustom(rName, address string) string {
return fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"
address = %[2]q

tags = {
Expand All @@ -1194,7 +1234,7 @@ resource "aws_eip" "test" {
func testAccEIPConfig_byoipAddressCustomPublicIPv4Pool(rName, address, poolName string) string {
return fmt.Sprintf(`
resource "aws_eip" "test" {
vpc = true
domain = "vpc"
address = %[2]q
public_ipv4_pool = %[3]q

Expand Down
4 changes: 2 additions & 2 deletions internal/service/ec2/ec2_eips_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func TestAccEC2EIPsDataSource_basic(t *testing.T) {
func testAccEIPsDataSourceConfig_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_eip" "test1" {
vpc = true
domain = "vpc"

tags = {
Name = "%[1]s-1"
}
}

resource "aws_eip" "test2" {
vpc = true
domain = "vpc"

tags = {
Name = "%[1]s-2"
Expand Down
Loading