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

Fix aws_ec2_instance_connect_endpoint/fips_dns_name in non-US regions #37939

Merged
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/37939.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ec2_instance_connect_endpoint: Set `fips_dns_name` to an empty value (`""`) when no value is returned from the EC2 API. This fixes known-after-apply loops in Regions that don't support FIPS endpoints
```
10 changes: 10 additions & 0 deletions internal/service/ec2/ec2_instance_connect_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ func (r *instanceConnectEndpointResource) Create(ctx context.Context, request re
return
}

// Fix missing FipsDnsName in regions without FIPS endpoint support.
if instanceConnectEndpoint.FipsDnsName == nil {
instanceConnectEndpoint.FipsDnsName = aws.String("")
}

// Set values for unknowns.
response.Diagnostics.Append(fwflex.Flatten(ctx, instanceConnectEndpoint, &data)...)
if response.Diagnostics.HasError() {
Expand Down Expand Up @@ -207,6 +212,11 @@ func (r *instanceConnectEndpointResource) Read(ctx context.Context, request reso
return
}

// Fix missing FipsDnsName in regions without FIPS endpoint support.
if instanceConnectEndpoint.FipsDnsName == nil {
instanceConnectEndpoint.FipsDnsName = aws.String("")
}

response.Diagnostics.Append(fwflex.Flatten(ctx, instanceConnectEndpoint, &data)...)
if response.Diagnostics.HasError() {
return
Expand Down
57 changes: 55 additions & 2 deletions internal/service/ec2/ec2_instance_connect_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/YakDriver/regexache"
"github.com/hashicorp/aws-sdk-go-base/v2/endpoints"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
Expand Down Expand Up @@ -39,7 +40,6 @@ func TestAccEC2InstanceConnectEndpoint_basic(t *testing.T) {
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "ec2", regexache.MustCompile(`instance-connect-endpoint/.+`)),
resource.TestCheckResourceAttrSet(resourceName, names.AttrAvailabilityZone),
resource.TestCheckResourceAttrSet(resourceName, names.AttrDNSName),
resource.TestCheckResourceAttrSet(resourceName, "fips_dns_name"),
acctest.CheckResourceAttrGreaterThanOrEqualValue(resourceName, "network_interface_ids.#", 1),
acctest.CheckResourceAttrAccountID(ctx, resourceName, names.AttrOwnerID),
resource.TestCheckResourceAttr(resourceName, "preserve_client_ip", acctest.CtTrue),
Expand Down Expand Up @@ -148,7 +148,6 @@ func TestAccEC2InstanceConnectEndpoint_securityGroupIDs(t *testing.T) {
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "ec2", regexache.MustCompile(`instance-connect-endpoint/.+`)),
resource.TestCheckResourceAttrSet(resourceName, names.AttrAvailabilityZone),
resource.TestCheckResourceAttrSet(resourceName, names.AttrDNSName),
resource.TestCheckResourceAttrSet(resourceName, "fips_dns_name"),
acctest.CheckResourceAttrGreaterThanOrEqualValue(resourceName, "network_interface_ids.#", 1),
resource.TestCheckResourceAttr(resourceName, "preserve_client_ip", acctest.CtFalse),
resource.TestCheckResourceAttr(resourceName, "security_group_ids.#", "2"),
Expand All @@ -169,6 +168,60 @@ func TestAccEC2InstanceConnectEndpoint_securityGroupIDs(t *testing.T) {
})
}

func TestAccEC2InstanceConnectEndpoint_fipsRegion(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_ec2_instance_connect_endpoint.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsWest2RegionID) },
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckInstanceConnectEndpointDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccInstanceConnectEndpointConfig_basic(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckInstanceConnectEndpointExists(ctx, resourceName),
resource.TestCheckResourceAttrSet(resourceName, "fips_dns_name"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccEC2InstanceConnectEndpoint_nonFIPSRegion(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_ec2_instance_connect_endpoint.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.ApNortheast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckInstanceConnectEndpointDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccInstanceConnectEndpointConfig_basic(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckInstanceConnectEndpointExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "fips_dns_name", ""),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckInstanceConnectEndpointExists(ctx context.Context, n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down
Loading