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_route53_key_signing_key #16840

Merged
merged 3 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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/16840.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_route53_key_signing_key
```
9 changes: 9 additions & 0 deletions aws/internal/service/route53/enum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package route53

const (
KeySigningKeyStatusActionNeeded = "ACTION_NEEDED"
KeySigningKeyStatusActive = "ACTIVE"
KeySigningKeyStatusDeleting = "DELETING"
KeySigningKeyStatusInactive = "INACTIVE"
KeySigningKeyStatusInternalFailure = "INTERNAL_FAILURE"
)
50 changes: 50 additions & 0 deletions aws/internal/service/route53/finder/finder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package finder

import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/route53"
tfroute53 "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/route53"
)

func KeySigningKey(conn *route53.Route53, hostedZoneID string, name string) (*route53.KeySigningKey, error) {
input := &route53.GetDNSSECInput{
HostedZoneId: aws.String(hostedZoneID),
}

var result *route53.KeySigningKey

output, err := conn.GetDNSSEC(input)

if err != nil {
return nil, err
}

if output == nil {
return nil, nil
}

for _, keySigningKey := range output.KeySigningKeys {
if keySigningKey == nil {
continue
}

if aws.StringValue(keySigningKey.Name) == name {
result = keySigningKey
break
}
}

return result, err
}

func KeySigningKeyByResourceID(conn *route53.Route53, resourceID string) (*route53.KeySigningKey, error) {
hostedZoneID, name, err := tfroute53.KeySigningKeyParseResourceID(resourceID)

if err != nil {
return nil, fmt.Errorf("error parsing Route 53 Key Signing Key (%s) identifier: %w", resourceID, err)
}

return KeySigningKey(conn, hostedZoneID, name)
}
25 changes: 25 additions & 0 deletions aws/internal/service/route53/id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package route53

import (
"fmt"
"strings"
)

const KeySigningKeyResourceIDSeparator = ","

func KeySigningKeyCreateResourceID(transitGatewayRouteTableID string, prefixListID string) string {
parts := []string{transitGatewayRouteTableID, prefixListID}
id := strings.Join(parts, KeySigningKeyResourceIDSeparator)

return id
}

func KeySigningKeyParseResourceID(id string) (string, string, error) {
parts := strings.Split(id, KeySigningKeyResourceIDSeparator)

if len(parts) == 2 && parts[0] != "" && parts[1] != "" {
return parts[0], parts[1], nil
}

return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected hosted-zone-id%[2]sname", id, KeySigningKeyResourceIDSeparator)
}
44 changes: 44 additions & 0 deletions aws/internal/service/route53/waiter/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package waiter

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/route53/finder"
)

func ChangeInfoStatus(conn *route53.Route53, changeID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &route53.GetChangeInput{
Id: aws.String(changeID),
}

output, err := conn.GetChange(input)

if err != nil {
return nil, "", err
}

if output == nil || output.ChangeInfo == nil {
return nil, "", nil
}

return output.ChangeInfo, aws.StringValue(output.ChangeInfo.Status), nil
}
}

func KeySigningKeyStatus(conn *route53.Route53, hostedZoneID string, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
keySigningKey, err := finder.KeySigningKey(conn, hostedZoneID, name)

if err != nil {
return nil, "", err
}

if keySigningKey == nil {
return nil, "", nil
}

return keySigningKey, aws.StringValue(keySigningKey.Status), nil
}
}
67 changes: 67 additions & 0 deletions aws/internal/service/route53/waiter/waiter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package waiter

import (
"fmt"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

const (
ChangeTimeout = 30 * time.Minute

KeySigningKeyStatusTimeout = 5 * time.Minute
)

func ChangeInfoStatusInsync(conn *route53.Route53, changeID string) (*route53.ChangeInfo, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{route53.ChangeStatusPending},
Target: []string{route53.ChangeStatusInsync},
Refresh: ChangeInfoStatus(conn, changeID),
Delay: 30 * time.Second,
MinTimeout: 5 * time.Second,
Timeout: ChangeTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*route53.ChangeInfo); ok {
return output, err
}

return nil, err
}

func KeySigningKeyStatusUpdated(conn *route53.Route53, hostedZoneID string, name string, status string) (*route53.KeySigningKey, error) {
stateConf := &resource.StateChangeConf{
Target: []string{status},
Refresh: KeySigningKeyStatus(conn, hostedZoneID, name),
MinTimeout: 5 * time.Second,
Timeout: KeySigningKeyStatusTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*route53.KeySigningKey); ok {
if err != nil && output != nil && output.Status != nil && output.StatusMessage != nil {
newErr := fmt.Errorf("%s: %s", aws.StringValue(output.Status), aws.StringValue(output.StatusMessage))

switch e := err.(type) {
case *resource.TimeoutError:
if e.LastError == nil {
e.LastError = newErr
}
case *resource.UnexpectedStateError:
if e.LastError == nil {
e.LastError = newErr
}
}
}

return output, err
}

return nil, err
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ func Provider() *schema.Provider {
"aws_redshift_event_subscription": resourceAwsRedshiftEventSubscription(),
"aws_resourcegroups_group": resourceAwsResourceGroupsGroup(),
"aws_route53_delegation_set": resourceAwsRoute53DelegationSet(),
"aws_route53_key_signing_key": resourceAwsRoute53KeySigningKey(),
"aws_route53_query_log": resourceAwsRoute53QueryLog(),
"aws_route53_record": resourceAwsRoute53Record(),
"aws_route53_zone_association": resourceAwsRoute53ZoneAssociation(),
Expand Down
Loading