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

New resource: aws_eip_domain_name #36963

Merged
merged 25 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a7fad01
r/aws_eip_association: Reduce visibility.
ewbankkit Apr 17, 2024
4c4d126
r/aws_eip: Reduce visibility.
ewbankkit Apr 17, 2024
a327668
d/aws_eips: Reduce visibility.
ewbankkit Apr 17, 2024
e735c8b
d/aws_eip: Reduce visibility.
ewbankkit Apr 17, 2024
c4e674a
d/aws_eips: Migrate to AWS SDK for Go v2.
ewbankkit Apr 17, 2024
fe563a1
d/aws_eip: Migrate to AWS SDK for Go v2.
ewbankkit Apr 17, 2024
c923a93
r/aws_eip_association: Migrate to AWS SDK for Go v2.
ewbankkit Apr 17, 2024
f344e94
r/aws_eip: Migrate to AWS SDK for Go v2.
ewbankkit Apr 17, 2024
46679e3
Move 'RegionalPublicDNSSuffix'.
ewbankkit Apr 17, 2024
c888012
Add 'EC2PrivateDNSNameForIP' and 'EC2PublicDNSNameForIP' to 'AWSClient'.
ewbankkit Apr 17, 2024
92946df
Use 'AWSClient.EC2RegionalPrivateDNSSuffix'.
ewbankkit Apr 17, 2024
d72663b
Use 'AWSClient.EC2PrivateDNSNameForIP' and 'AWSClient.EC2PublicDNSNam…
ewbankkit Apr 17, 2024
39dec48
Acceptance test output:
ewbankkit Apr 17, 2024
9ca4c77
aws_eip: Add 'domain_name' attribute.
ewbankkit Apr 17, 2024
7ebe305
d/aws_eip: 'domain_name' -> 'ptr_record'.
ewbankkit Apr 17, 2024
7f7bc55
r/aws_eip_domain_name: New resource.
ewbankkit Apr 17, 2024
7a68411
r/aws_eip_domain_name: Add documentation.
ewbankkit Apr 17, 2024
886637d
Correct CHANGELOG entry.
ewbankkit Apr 17, 2024
0b66cb3
r/aws_eip: Add 'ptr_record' attribute.
ewbankkit Apr 17, 2024
719fafa
r/aws_eip_domain_name: Add first acceptance test.
ewbankkit Apr 17, 2024
74d489d
r/aws_eip_domain_name: Additional acceptance tests.
ewbankkit Apr 17, 2024
bb19ebe
r/aws_eip_domain_name: Add sweeper.
ewbankkit Apr 17, 2024
e8a9bd2
Fix 'TestAccEC2EIPDomainName_update'.
ewbankkit Apr 17, 2024
77a0b85
r/aws_eip_domain_name: Fix error handling on Delete.
ewbankkit Apr 17, 2024
cab40fc
Correct CHANGELOG entry file name.
ewbankkit Apr 17, 2024
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
2 changes: 1 addition & 1 deletion .changelog/36767.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```release-note:enhancement
resource/openzfs_file_system: Add `endpoint_ip_address` attribute
resource/aws_fsx_openzfs_file_system: Add `endpoint_ip_address` attribute
```
11 changes: 11 additions & 0 deletions .changelog/36963.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
data-source/aws_eip: Add `ptr_record` attribute
```

```release-note:enhancement
resource/aws_eip: Add `ptr_record` attribute
```

```release-note:new-resource
aws_eip_domain_name
```
35 changes: 35 additions & 0 deletions internal/conns/awsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"maps"
"net/http"
"os"
"strings"
"sync"

aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -250,6 +251,40 @@ func (c *AWSClient) ReverseDNSPrefix(ctx context.Context) string {
return names.ReverseDNS(c.DNSSuffix(ctx))
}

// EC2RegionalPrivateDNSSuffix returns the EC2 private DNS suffix for the configured AWS Region.
func (c *AWSClient) EC2RegionalPrivateDNSSuffix(context.Context) string {
region := c.Region
if region == names.USEast1RegionID {
return "ec2.internal"
}

return fmt.Sprintf("%s.compute.internal", region)
}

// EC2RegionalPublicDNSSuffix returns the EC2 public DNS suffix for the configured AWS Region.
func (c *AWSClient) EC2RegionalPublicDNSSuffix(context.Context) string {
region := c.Region
if region == names.USEast1RegionID {
return "compute-1"
}

return fmt.Sprintf("%s.compute", region)
}

// EC2PrivateDNSNameForIP returns a EC2 private DNS name in the configured AWS Region.
func (c *AWSClient) EC2PrivateDNSNameForIP(ctx context.Context, ip string) string {
return fmt.Sprintf("ip-%s.%s", convertIPToDashIP(ip), c.EC2RegionalPrivateDNSSuffix(ctx))
}

// EC2PublicDNSNameForIP returns a EC2 public DNS name in the configured AWS Region.
func (c *AWSClient) EC2PublicDNSNameForIP(ctx context.Context, ip string) string {
return c.PartitionHostname(ctx, fmt.Sprintf("ec2-%s.%s", convertIPToDashIP(ip), c.EC2RegionalPublicDNSSuffix(ctx)))
}

func convertIPToDashIP(ip string) string {
return strings.Replace(ip, ".", "-", -1)
}

// apiClientConfig returns the AWS API client configuration parameters for the specified service.
func (c *AWSClient) apiClientConfig(ctx context.Context, servicePackageName string) map[string]any {
m := map[string]any{
Expand Down
88 changes: 88 additions & 0 deletions internal/conns/awsclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,91 @@ func TestAWSClientRegionalHostname(t *testing.T) { // nosemgrep:ci.aws-in-func-n
})
}
}

func TestAWSClientEC2PrivateDNSNameForIP(t *testing.T) { // nosemgrep:ci.aws-in-func-name
t.Parallel()

ctx := context.TODO()
testCases := []struct {
Name string
AWSClient *AWSClient
IP string
Expected string
}{
{
Name: "us-west-2",
AWSClient: &AWSClient{
dnsSuffix: "amazonaws.com",
Region: "us-west-2", //lintignore:AWSAT003
},
IP: "10.20.30.40",
Expected: "ip-10-20-30-40.us-west-2.compute.internal", //lintignore:AWSAT003
},
{
Name: "us-east-1",
AWSClient: &AWSClient{
dnsSuffix: "amazonaws.com",
Region: "us-east-1", //lintignore:AWSAT003
},
IP: "10.20.30.40",
Expected: "ip-10-20-30-40.ec2.internal",
},
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.Name, func(t *testing.T) {
t.Parallel()

got := testCase.AWSClient.EC2PrivateDNSNameForIP(ctx, testCase.IP)

if got != testCase.Expected {
t.Errorf("got %s, expected %s", got, testCase.Expected)
}
})
}
}

func TestAWSClientEC2PublicDNSNameForIP(t *testing.T) { // nosemgrep:ci.aws-in-func-name
t.Parallel()

ctx := context.TODO()
testCases := []struct {
Name string
AWSClient *AWSClient
IP string
Expected string
}{
{
Name: "us-west-2",
AWSClient: &AWSClient{
dnsSuffix: "amazonaws.com",
Region: "us-west-2", //lintignore:AWSAT003
},
IP: "10.20.30.40",
Expected: "ec2-10-20-30-40.us-west-2.compute.amazonaws.com", //lintignore:AWSAT003
},
{
Name: "us-east-1",
AWSClient: &AWSClient{
dnsSuffix: "amazonaws.com",
Region: "us-east-1", //lintignore:AWSAT003
},
IP: "10.20.30.40",
Expected: "ec2-10-20-30-40.compute-1.amazonaws.com",
},
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.Name, func(t *testing.T) {
t.Parallel()

got := testCase.AWSClient.EC2PublicDNSNameForIP(ctx, testCase.IP)

if got != testCase.Expected {
t.Errorf("got %s, expected %s", got, testCase.Expected)
}
})
}
}
16 changes: 16 additions & 0 deletions internal/sdkv2/suppress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package sdkv2

import (
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// SuppressEquivalentStringCaseInsensitive provides custom difference suppression
// for strings that are equal under case-insensitivity.
func SuppressEquivalentStringCaseInsensitive(k, old, new string, d *schema.ResourceData) bool {
return strings.EqualFold(old, new)
}
5 changes: 5 additions & 0 deletions internal/service/ec2/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ const (
CustomerGatewayStatePending = "pending"
)

// See https://docs.aws.amazon.com/cli/latest/reference/ec2/modify-address-attribute.html#examples.
const (
PTRUpdateStatusPending = "PENDING"
)

const (
managedPrefixListAddressFamilyIPv4 = "IPv4"
managedPrefixListAddressFamilyIPv6 = "IPv6"
Expand Down
Loading
Loading