From 37dc411f3057cb2d6f8f9a50e5c5d394866d8323 Mon Sep 17 00:00:00 2001 From: haoshuwei Date: Fri, 20 Dec 2019 11:28:31 +0800 Subject: [PATCH] add skip_image_validation arg to use an expired image as the soure image Signed-off-by: haoshuwei --- builder/alicloud/ecs/access_config.go | 3 +++ builder/alicloud/ecs/builder.hcl2spec.go | 2 ++ builder/alicloud/ecs/step_check_source_image.go | 3 +++ post-processor/alicloud-import/post-processor.hcl2spec.go | 2 ++ .../alicloud/ecs/_AlicloudAccessConfig-not-required.html.md | 3 +++ 5 files changed, 13 insertions(+) diff --git a/builder/alicloud/ecs/access_config.go b/builder/alicloud/ecs/access_config.go index b7a5fe26b..bc1968dc8 100644 --- a/builder/alicloud/ecs/access_config.go +++ b/builder/alicloud/ecs/access_config.go @@ -26,6 +26,9 @@ type AlicloudAccessConfig struct { // The region validation can be skipped if this value is true, the default // value is false. AlicloudSkipValidation bool `mapstructure:"skip_region_validation" required:"false"` + // The image validation can be skipped if this value is true, the default + // value is false. + AlicloudSkipImageValidation bool `mapstructure:"skip_image_validation" required:"false"` // STS access token, can be set through template or by exporting as // environment variable such as `export SECURITY_TOKEN=value`. SecurityToken string `mapstructure:"security_token" required:"false"` diff --git a/builder/alicloud/ecs/builder.hcl2spec.go b/builder/alicloud/ecs/builder.hcl2spec.go index 595ada017..f9e9b25f7 100644 --- a/builder/alicloud/ecs/builder.hcl2spec.go +++ b/builder/alicloud/ecs/builder.hcl2spec.go @@ -54,6 +54,7 @@ type FlatConfig struct { AlicloudSecretKey *string `mapstructure:"secret_key" required:"true" cty:"secret_key"` AlicloudRegion *string `mapstructure:"region" required:"true" cty:"region"` AlicloudSkipValidation *bool `mapstructure:"skip_region_validation" required:"false" cty:"skip_region_validation"` + AlicloudSkipImageValidation *bool `mapstructure:"skip_image_validation" required:"false" cty:"skip_image_validation"` SecurityToken *string `mapstructure:"security_token" required:"false" cty:"security_token"` AlicloudImageName *string `mapstructure:"image_name" required:"true" cty:"image_name"` AlicloudImageVersion *string `mapstructure:"image_version" required:"false" cty:"image_version"` @@ -154,6 +155,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "secret_key": &hcldec.AttrSpec{Name: "secret_key", Type: cty.String, Required: false}, "region": &hcldec.AttrSpec{Name: "region", Type: cty.String, Required: false}, "skip_region_validation": &hcldec.AttrSpec{Name: "skip_region_validation", Type: cty.Bool, Required: false}, + "skip_image_validation": &hcldec.AttrSpec{Name: "skip_image_validation", Type: cty.Bool, Required: false}, "security_token": &hcldec.AttrSpec{Name: "security_token", Type: cty.String, Required: false}, "image_name": &hcldec.AttrSpec{Name: "image_name", Type: cty.String, Required: false}, "image_version": &hcldec.AttrSpec{Name: "image_version", Type: cty.String, Required: false}, diff --git a/builder/alicloud/ecs/step_check_source_image.go b/builder/alicloud/ecs/step_check_source_image.go index 541bd19eb..3eedec595 100644 --- a/builder/alicloud/ecs/step_check_source_image.go +++ b/builder/alicloud/ecs/step_check_source_image.go @@ -21,6 +21,9 @@ func (s *stepCheckAlicloudSourceImage) Run(ctx context.Context, state multistep. describeImagesRequest := ecs.CreateDescribeImagesRequest() describeImagesRequest.RegionId = config.AlicloudRegion describeImagesRequest.ImageId = config.AlicloudSourceImage + if config.AlicloudSkipImageValidation { + describeImagesRequest.ShowExpired = "true" + } imagesResponse, err := client.DescribeImages(describeImagesRequest) if err != nil { return halt(state, err, "Error querying alicloud image") diff --git a/post-processor/alicloud-import/post-processor.hcl2spec.go b/post-processor/alicloud-import/post-processor.hcl2spec.go index aeeed2435..a137bd450 100644 --- a/post-processor/alicloud-import/post-processor.hcl2spec.go +++ b/post-processor/alicloud-import/post-processor.hcl2spec.go @@ -21,6 +21,7 @@ type FlatConfig struct { AlicloudSecretKey *string `mapstructure:"secret_key" required:"true" cty:"secret_key"` AlicloudRegion *string `mapstructure:"region" required:"true" cty:"region"` AlicloudSkipValidation *bool `mapstructure:"skip_region_validation" required:"false" cty:"skip_region_validation"` + AlicloudSkipImageValidation *bool `mapstructure:"skip_image_validation" required:"false" cty:"skip_image_validation"` SecurityToken *string `mapstructure:"security_token" required:"false" cty:"security_token"` AlicloudImageName *string `mapstructure:"image_name" required:"true" cty:"image_name"` AlicloudImageVersion *string `mapstructure:"image_version" required:"false" cty:"image_version"` @@ -129,6 +130,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "secret_key": &hcldec.AttrSpec{Name: "secret_key", Type: cty.String, Required: false}, "region": &hcldec.AttrSpec{Name: "region", Type: cty.String, Required: false}, "skip_region_validation": &hcldec.AttrSpec{Name: "skip_region_validation", Type: cty.Bool, Required: false}, + "skip_image_validation": &hcldec.AttrSpec{Name: "skip_image_validation", Type: cty.Bool, Required: false}, "security_token": &hcldec.AttrSpec{Name: "security_token", Type: cty.String, Required: false}, "image_name": &hcldec.AttrSpec{Name: "image_name", Type: cty.String, Required: false}, "image_version": &hcldec.AttrSpec{Name: "image_version", Type: cty.String, Required: false}, diff --git a/website/source/partials/builder/alicloud/ecs/_AlicloudAccessConfig-not-required.html.md b/website/source/partials/builder/alicloud/ecs/_AlicloudAccessConfig-not-required.html.md index 3ed83f123..7e3448a7b 100644 --- a/website/source/partials/builder/alicloud/ecs/_AlicloudAccessConfig-not-required.html.md +++ b/website/source/partials/builder/alicloud/ecs/_AlicloudAccessConfig-not-required.html.md @@ -3,6 +3,9 @@ - `skip_region_validation` (bool) - The region validation can be skipped if this value is true, the default value is false. +- `skip_image_validation` (bool) - The image validation can be skipped if this value is true, the default + value is false. + - `security_token` (string) - STS access token, can be set through template or by exporting as environment variable such as `export SECURITY_TOKEN=value`. \ No newline at end of file