|
| 1 | +package waiter |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "time" |
| 6 | + |
| 7 | + "github.com/aws/aws-sdk-go/aws" |
| 8 | + "github.com/aws/aws-sdk-go/service/route53" |
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 10 | +) |
| 11 | + |
| 12 | +const ( |
| 13 | + ChangeTimeout = 30 * time.Minute |
| 14 | + |
| 15 | + KeySigningKeyStatusTimeout = 5 * time.Minute |
| 16 | +) |
| 17 | + |
| 18 | +func ChangeInfoStatusInsync(conn *route53.Route53, changeID string) (*route53.ChangeInfo, error) { |
| 19 | + stateConf := &resource.StateChangeConf{ |
| 20 | + Pending: []string{route53.ChangeStatusPending}, |
| 21 | + Target: []string{route53.ChangeStatusInsync}, |
| 22 | + Refresh: ChangeInfoStatus(conn, changeID), |
| 23 | + Delay: 30 * time.Second, |
| 24 | + MinTimeout: 5 * time.Second, |
| 25 | + Timeout: ChangeTimeout, |
| 26 | + } |
| 27 | + |
| 28 | + outputRaw, err := stateConf.WaitForState() |
| 29 | + |
| 30 | + if output, ok := outputRaw.(*route53.ChangeInfo); ok { |
| 31 | + return output, err |
| 32 | + } |
| 33 | + |
| 34 | + return nil, err |
| 35 | +} |
| 36 | + |
| 37 | +func KeySigningKeyStatusUpdated(conn *route53.Route53, hostedZoneID string, name string, status string) (*route53.KeySigningKey, error) { |
| 38 | + stateConf := &resource.StateChangeConf{ |
| 39 | + Target: []string{status}, |
| 40 | + Refresh: KeySigningKeyStatus(conn, hostedZoneID, name), |
| 41 | + MinTimeout: 5 * time.Second, |
| 42 | + Timeout: KeySigningKeyStatusTimeout, |
| 43 | + } |
| 44 | + |
| 45 | + outputRaw, err := stateConf.WaitForState() |
| 46 | + |
| 47 | + if output, ok := outputRaw.(*route53.KeySigningKey); ok { |
| 48 | + if err != nil && output != nil && output.Status != nil && output.StatusMessage != nil { |
| 49 | + newErr := fmt.Errorf("%s: %s", aws.StringValue(output.Status), aws.StringValue(output.StatusMessage)) |
| 50 | + |
| 51 | + switch e := err.(type) { |
| 52 | + case *resource.TimeoutError: |
| 53 | + if e.LastError == nil { |
| 54 | + e.LastError = newErr |
| 55 | + } |
| 56 | + case *resource.UnexpectedStateError: |
| 57 | + if e.LastError == nil { |
| 58 | + e.LastError = newErr |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + return output, err |
| 64 | + } |
| 65 | + |
| 66 | + return nil, err |
| 67 | +} |
0 commit comments