From 7d5f0c11af2baecb8d6cb6ee11206a8f69782637 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Fri, 7 Feb 2020 16:36:14 +0100 Subject: [PATCH] add max_retries option to aws builders --- builder/amazon/chroot/builder.hcl2spec.go | 2 ++ builder/amazon/common/access_config.go | 7 +++++++ builder/amazon/ebs/builder.hcl2spec.go | 2 ++ builder/amazon/ebssurrogate/builder.hcl2spec.go | 2 ++ builder/amazon/ebsvolume/builder.hcl2spec.go | 2 ++ builder/amazon/instance/builder.hcl2spec.go | 2 ++ post-processor/amazon-import/post-processor.hcl2spec.go | 2 ++ .../amazon/common/_AccessConfig-not-required.html.md | 4 ++++ 8 files changed, 23 insertions(+) diff --git a/builder/amazon/chroot/builder.hcl2spec.go b/builder/amazon/chroot/builder.hcl2spec.go index 130ab5dd8..5565acc2c 100644 --- a/builder/amazon/chroot/builder.hcl2spec.go +++ b/builder/amazon/chroot/builder.hcl2spec.go @@ -41,6 +41,7 @@ type FlatConfig struct { CustomEndpointEc2 *string `mapstructure:"custom_endpoint_ec2" required:"false" cty:"custom_endpoint_ec2"` DecodeAuthZMessages *bool `mapstructure:"decode_authorization_messages" required:"false" cty:"decode_authorization_messages"` InsecureSkipTLSVerify *bool `mapstructure:"insecure_skip_tls_verify" required:"false" cty:"insecure_skip_tls_verify"` + MaxRetries *int `mapstructure:"max_retries" required:"false" cty:"max_retries"` MFACode *string `mapstructure:"mfa_code" required:"false" cty:"mfa_code"` ProfileName *string `mapstructure:"profile" required:"false" cty:"profile"` RawRegion *string `mapstructure:"region" required:"true" cty:"region"` @@ -112,6 +113,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "custom_endpoint_ec2": &hcldec.AttrSpec{Name: "custom_endpoint_ec2", Type: cty.String, Required: false}, "decode_authorization_messages": &hcldec.AttrSpec{Name: "decode_authorization_messages", Type: cty.Bool, Required: false}, "insecure_skip_tls_verify": &hcldec.AttrSpec{Name: "insecure_skip_tls_verify", Type: cty.Bool, Required: false}, + "max_retries": &hcldec.AttrSpec{Name: "max_retries", Type: cty.Number, Required: false}, "mfa_code": &hcldec.AttrSpec{Name: "mfa_code", Type: cty.String, Required: false}, "profile": &hcldec.AttrSpec{Name: "profile", Type: cty.String, Required: false}, "region": &hcldec.AttrSpec{Name: "region", Type: cty.String, Required: false}, diff --git a/builder/amazon/common/access_config.go b/builder/amazon/common/access_config.go index a32decf07..c63dabd60 100644 --- a/builder/amazon/common/access_config.go +++ b/builder/amazon/common/access_config.go @@ -60,6 +60,10 @@ type AccessConfig struct { // This allows skipping TLS // verification of the AWS EC2 endpoint. The default is false. InsecureSkipTLSVerify bool `mapstructure:"insecure_skip_tls_verify" required:"false"` + // This is the maximum number of times an API call is retried, in the case + // where requests are being throttled or experiencing transient failures. + // The delay between the subsequent API calls increases exponentially. + MaxRetries int `mapstructure:"max_retries" required:"false"` // The MFA // [TOTP](https://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm) // code. This should probably be a user variable since it changes all the @@ -134,6 +138,9 @@ func (c *AccessConfig) Session() (*session.Session, error) { } config := aws.NewConfig().WithCredentialsChainVerboseErrors(true) + if c.MaxRetries > 0 { + config = config.WithMaxRetries(c.MaxRetries) + } staticCreds := credentials.NewStaticCredentials(c.AccessKey, c.SecretKey, c.Token) if _, err := staticCreds.Get(); err != credentials.ErrStaticCredentialsEmpty { diff --git a/builder/amazon/ebs/builder.hcl2spec.go b/builder/amazon/ebs/builder.hcl2spec.go index 27501d772..c447e5717 100644 --- a/builder/amazon/ebs/builder.hcl2spec.go +++ b/builder/amazon/ebs/builder.hcl2spec.go @@ -21,6 +21,7 @@ type FlatConfig struct { CustomEndpointEc2 *string `mapstructure:"custom_endpoint_ec2" required:"false" cty:"custom_endpoint_ec2"` DecodeAuthZMessages *bool `mapstructure:"decode_authorization_messages" required:"false" cty:"decode_authorization_messages"` InsecureSkipTLSVerify *bool `mapstructure:"insecure_skip_tls_verify" required:"false" cty:"insecure_skip_tls_verify"` + MaxRetries *int `mapstructure:"max_retries" required:"false" cty:"max_retries"` MFACode *string `mapstructure:"mfa_code" required:"false" cty:"mfa_code"` ProfileName *string `mapstructure:"profile" required:"false" cty:"profile"` RawRegion *string `mapstructure:"region" required:"true" cty:"region"` @@ -147,6 +148,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "custom_endpoint_ec2": &hcldec.AttrSpec{Name: "custom_endpoint_ec2", Type: cty.String, Required: false}, "decode_authorization_messages": &hcldec.AttrSpec{Name: "decode_authorization_messages", Type: cty.Bool, Required: false}, "insecure_skip_tls_verify": &hcldec.AttrSpec{Name: "insecure_skip_tls_verify", Type: cty.Bool, Required: false}, + "max_retries": &hcldec.AttrSpec{Name: "max_retries", Type: cty.Number, Required: false}, "mfa_code": &hcldec.AttrSpec{Name: "mfa_code", Type: cty.String, Required: false}, "profile": &hcldec.AttrSpec{Name: "profile", Type: cty.String, Required: false}, "region": &hcldec.AttrSpec{Name: "region", Type: cty.String, Required: false}, diff --git a/builder/amazon/ebssurrogate/builder.hcl2spec.go b/builder/amazon/ebssurrogate/builder.hcl2spec.go index 81d98f448..45b5f6548 100644 --- a/builder/amazon/ebssurrogate/builder.hcl2spec.go +++ b/builder/amazon/ebssurrogate/builder.hcl2spec.go @@ -64,6 +64,7 @@ type FlatConfig struct { CustomEndpointEc2 *string `mapstructure:"custom_endpoint_ec2" required:"false" cty:"custom_endpoint_ec2"` DecodeAuthZMessages *bool `mapstructure:"decode_authorization_messages" required:"false" cty:"decode_authorization_messages"` InsecureSkipTLSVerify *bool `mapstructure:"insecure_skip_tls_verify" required:"false" cty:"insecure_skip_tls_verify"` + MaxRetries *int `mapstructure:"max_retries" required:"false" cty:"max_retries"` MFACode *string `mapstructure:"mfa_code" required:"false" cty:"mfa_code"` ProfileName *string `mapstructure:"profile" required:"false" cty:"profile"` RawRegion *string `mapstructure:"region" required:"true" cty:"region"` @@ -191,6 +192,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "custom_endpoint_ec2": &hcldec.AttrSpec{Name: "custom_endpoint_ec2", Type: cty.String, Required: false}, "decode_authorization_messages": &hcldec.AttrSpec{Name: "decode_authorization_messages", Type: cty.Bool, Required: false}, "insecure_skip_tls_verify": &hcldec.AttrSpec{Name: "insecure_skip_tls_verify", Type: cty.Bool, Required: false}, + "max_retries": &hcldec.AttrSpec{Name: "max_retries", Type: cty.Number, Required: false}, "mfa_code": &hcldec.AttrSpec{Name: "mfa_code", Type: cty.String, Required: false}, "profile": &hcldec.AttrSpec{Name: "profile", Type: cty.String, Required: false}, "region": &hcldec.AttrSpec{Name: "region", Type: cty.String, Required: false}, diff --git a/builder/amazon/ebsvolume/builder.hcl2spec.go b/builder/amazon/ebsvolume/builder.hcl2spec.go index 34a5199cb..5f2467101 100644 --- a/builder/amazon/ebsvolume/builder.hcl2spec.go +++ b/builder/amazon/ebsvolume/builder.hcl2spec.go @@ -64,6 +64,7 @@ type FlatConfig struct { CustomEndpointEc2 *string `mapstructure:"custom_endpoint_ec2" required:"false" cty:"custom_endpoint_ec2"` DecodeAuthZMessages *bool `mapstructure:"decode_authorization_messages" required:"false" cty:"decode_authorization_messages"` InsecureSkipTLSVerify *bool `mapstructure:"insecure_skip_tls_verify" required:"false" cty:"insecure_skip_tls_verify"` + MaxRetries *int `mapstructure:"max_retries" required:"false" cty:"max_retries"` MFACode *string `mapstructure:"mfa_code" required:"false" cty:"mfa_code"` ProfileName *string `mapstructure:"profile" required:"false" cty:"profile"` RawRegion *string `mapstructure:"region" required:"true" cty:"region"` @@ -171,6 +172,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "custom_endpoint_ec2": &hcldec.AttrSpec{Name: "custom_endpoint_ec2", Type: cty.String, Required: false}, "decode_authorization_messages": &hcldec.AttrSpec{Name: "decode_authorization_messages", Type: cty.Bool, Required: false}, "insecure_skip_tls_verify": &hcldec.AttrSpec{Name: "insecure_skip_tls_verify", Type: cty.Bool, Required: false}, + "max_retries": &hcldec.AttrSpec{Name: "max_retries", Type: cty.Number, Required: false}, "mfa_code": &hcldec.AttrSpec{Name: "mfa_code", Type: cty.String, Required: false}, "profile": &hcldec.AttrSpec{Name: "profile", Type: cty.String, Required: false}, "region": &hcldec.AttrSpec{Name: "region", Type: cty.String, Required: false}, diff --git a/builder/amazon/instance/builder.hcl2spec.go b/builder/amazon/instance/builder.hcl2spec.go index 2726a0994..388b28432 100644 --- a/builder/amazon/instance/builder.hcl2spec.go +++ b/builder/amazon/instance/builder.hcl2spec.go @@ -21,6 +21,7 @@ type FlatConfig struct { CustomEndpointEc2 *string `mapstructure:"custom_endpoint_ec2" required:"false" cty:"custom_endpoint_ec2"` DecodeAuthZMessages *bool `mapstructure:"decode_authorization_messages" required:"false" cty:"decode_authorization_messages"` InsecureSkipTLSVerify *bool `mapstructure:"insecure_skip_tls_verify" required:"false" cty:"insecure_skip_tls_verify"` + MaxRetries *int `mapstructure:"max_retries" required:"false" cty:"max_retries"` MFACode *string `mapstructure:"mfa_code" required:"false" cty:"mfa_code"` ProfileName *string `mapstructure:"profile" required:"false" cty:"profile"` RawRegion *string `mapstructure:"region" required:"true" cty:"region"` @@ -154,6 +155,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "custom_endpoint_ec2": &hcldec.AttrSpec{Name: "custom_endpoint_ec2", Type: cty.String, Required: false}, "decode_authorization_messages": &hcldec.AttrSpec{Name: "decode_authorization_messages", Type: cty.Bool, Required: false}, "insecure_skip_tls_verify": &hcldec.AttrSpec{Name: "insecure_skip_tls_verify", Type: cty.Bool, Required: false}, + "max_retries": &hcldec.AttrSpec{Name: "max_retries", Type: cty.Number, Required: false}, "mfa_code": &hcldec.AttrSpec{Name: "mfa_code", Type: cty.String, Required: false}, "profile": &hcldec.AttrSpec{Name: "profile", Type: cty.String, Required: false}, "region": &hcldec.AttrSpec{Name: "region", Type: cty.String, Required: false}, diff --git a/post-processor/amazon-import/post-processor.hcl2spec.go b/post-processor/amazon-import/post-processor.hcl2spec.go index 60ecb8f08..25738e586 100644 --- a/post-processor/amazon-import/post-processor.hcl2spec.go +++ b/post-processor/amazon-import/post-processor.hcl2spec.go @@ -21,6 +21,7 @@ type FlatConfig struct { CustomEndpointEc2 *string `mapstructure:"custom_endpoint_ec2" required:"false" cty:"custom_endpoint_ec2"` DecodeAuthZMessages *bool `mapstructure:"decode_authorization_messages" required:"false" cty:"decode_authorization_messages"` InsecureSkipTLSVerify *bool `mapstructure:"insecure_skip_tls_verify" required:"false" cty:"insecure_skip_tls_verify"` + MaxRetries *int `mapstructure:"max_retries" required:"false" cty:"max_retries"` MFACode *string `mapstructure:"mfa_code" required:"false" cty:"mfa_code"` ProfileName *string `mapstructure:"profile" required:"false" cty:"profile"` RawRegion *string `mapstructure:"region" required:"true" cty:"region"` @@ -69,6 +70,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "custom_endpoint_ec2": &hcldec.AttrSpec{Name: "custom_endpoint_ec2", Type: cty.String, Required: false}, "decode_authorization_messages": &hcldec.AttrSpec{Name: "decode_authorization_messages", Type: cty.Bool, Required: false}, "insecure_skip_tls_verify": &hcldec.AttrSpec{Name: "insecure_skip_tls_verify", Type: cty.Bool, Required: false}, + "max_retries": &hcldec.AttrSpec{Name: "max_retries", Type: cty.Number, Required: false}, "mfa_code": &hcldec.AttrSpec{Name: "mfa_code", Type: cty.String, Required: false}, "profile": &hcldec.AttrSpec{Name: "profile", Type: cty.String, Required: false}, "region": &hcldec.AttrSpec{Name: "region", Type: cty.String, Required: false}, diff --git a/website/source/partials/builder/amazon/common/_AccessConfig-not-required.html.md b/website/source/partials/builder/amazon/common/_AccessConfig-not-required.html.md index 4b7b05825..275f27fb5 100644 --- a/website/source/partials/builder/amazon/common/_AccessConfig-not-required.html.md +++ b/website/source/partials/builder/amazon/common/_AccessConfig-not-required.html.md @@ -12,6 +12,10 @@ - `insecure_skip_tls_verify` (bool) - This allows skipping TLS verification of the AWS EC2 endpoint. The default is false. +- `max_retries` (int) - This is the maximum number of times an API call is retried, in the case + where requests are being throttled or experiencing transient failures. + The delay between the subsequent API calls increases exponentially. + - `mfa_code` (string) - The MFA [TOTP](https://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm) code. This should probably be a user variable since it changes all the