From 7f26429a2adb0503a3cff46ff9d165a736cec894 Mon Sep 17 00:00:00 2001 From: elsnepal <46324484+elsnepal@users.noreply.github.com> Date: Fri, 2 Apr 2021 20:02:13 +0100 Subject: [PATCH] feature[alicloud]: add ramrole to ecs instance (#10845) * add RamRole support for ecs instance * ordering of attributes * run make generate --- builder/alicloud/ecs/builder.go | 1 + builder/alicloud/ecs/builder.hcl2spec.go | 2 ++ builder/alicloud/ecs/run_config.go | 2 ++ builder/alicloud/ecs/step_create_instance.go | 2 ++ post-processor/alicloud-import/post-processor.hcl2spec.go | 2 ++ .../partials/builder/alicloud/ecs/RunConfig-not-required.mdx | 2 ++ 6 files changed, 11 insertions(+) diff --git a/builder/alicloud/ecs/builder.go b/builder/alicloud/ecs/builder.go index fff28b7f4..963aaae15 100644 --- a/builder/alicloud/ecs/builder.go +++ b/builder/alicloud/ecs/builder.go @@ -135,6 +135,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) InstanceType: b.config.InstanceType, UserData: b.config.UserData, UserDataFile: b.config.UserDataFile, + RamRoleName: b.config.RamRoleName, RegionId: b.config.AlicloudRegion, InternetChargeType: b.config.InternetChargeType, InternetMaxBandwidthOut: b.config.InternetMaxBandwidthOut, diff --git a/builder/alicloud/ecs/builder.hcl2spec.go b/builder/alicloud/ecs/builder.hcl2spec.go index f9a2f37b7..16eb25cde 100644 --- a/builder/alicloud/ecs/builder.hcl2spec.go +++ b/builder/alicloud/ecs/builder.hcl2spec.go @@ -88,6 +88,7 @@ type FlatConfig struct { AlicloudSourceImage *string `mapstructure:"source_image" required:"true" cty:"source_image" hcl:"source_image"` ForceStopInstance *bool `mapstructure:"force_stop_instance" required:"false" cty:"force_stop_instance" hcl:"force_stop_instance"` DisableStopInstance *bool `mapstructure:"disable_stop_instance" required:"false" cty:"disable_stop_instance" hcl:"disable_stop_instance"` + RamRoleName *string `mapstructure:"ram_role_name" required:"false" cty:"ram_role_name" hcl:"ram_role_name"` SecurityGroupId *string `mapstructure:"security_group_id" required:"false" cty:"security_group_id" hcl:"security_group_id"` SecurityGroupName *string `mapstructure:"security_group_name" required:"false" cty:"security_group_name" hcl:"security_group_name"` UserData *string `mapstructure:"user_data" required:"false" cty:"user_data" hcl:"user_data"` @@ -205,6 +206,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "source_image": &hcldec.AttrSpec{Name: "source_image", Type: cty.String, Required: false}, "force_stop_instance": &hcldec.AttrSpec{Name: "force_stop_instance", Type: cty.Bool, Required: false}, "disable_stop_instance": &hcldec.AttrSpec{Name: "disable_stop_instance", Type: cty.Bool, Required: false}, + "ram_role_name": &hcldec.AttrSpec{Name: "ram_role_name", Type: cty.String, Required: false}, "security_group_id": &hcldec.AttrSpec{Name: "security_group_id", Type: cty.String, Required: false}, "security_group_name": &hcldec.AttrSpec{Name: "security_group_name", Type: cty.String, Required: false}, "user_data": &hcldec.AttrSpec{Name: "user_data", Type: cty.String, Required: false}, diff --git a/builder/alicloud/ecs/run_config.go b/builder/alicloud/ecs/run_config.go index 0b96be7af..f9c62ddee 100644 --- a/builder/alicloud/ecs/run_config.go +++ b/builder/alicloud/ecs/run_config.go @@ -47,6 +47,8 @@ type RunConfig struct { // E.g., Sysprep a windows which may shutdown the instance within its command. // The default value is false. DisableStopInstance bool `mapstructure:"disable_stop_instance" required:"false"` + // Ram Role to apply when launching the instance. + RamRoleName string `mapstructure:"ram_role_name" required:"false"` // ID of the security group to which a newly // created instance belongs. Mutual access is allowed between instances in one // security group. If not specified, the newly created instance will be added diff --git a/builder/alicloud/ecs/step_create_instance.go b/builder/alicloud/ecs/step_create_instance.go index f4867410e..dd4155542 100644 --- a/builder/alicloud/ecs/step_create_instance.go +++ b/builder/alicloud/ecs/step_create_instance.go @@ -23,6 +23,7 @@ type stepCreateAlicloudInstance struct { UserData string UserDataFile string instanceId string + RamRoleName string RegionId string InternetChargeType string InternetMaxBandwidthOut int @@ -115,6 +116,7 @@ func (s *stepCreateAlicloudInstance) buildCreateInstanceRequest(state multistep. request.RegionId = s.RegionId request.InstanceType = s.InstanceType request.InstanceName = s.InstanceName + request.RamRoleName = s.RamRoleName request.ZoneId = s.ZoneId sourceImage := state.Get("source_image").(*ecs.Image) diff --git a/post-processor/alicloud-import/post-processor.hcl2spec.go b/post-processor/alicloud-import/post-processor.hcl2spec.go index ddc4fb651..c1effd5bd 100644 --- a/post-processor/alicloud-import/post-processor.hcl2spec.go +++ b/post-processor/alicloud-import/post-processor.hcl2spec.go @@ -52,6 +52,7 @@ type FlatConfig struct { AlicloudSourceImage *string `mapstructure:"source_image" required:"true" cty:"source_image" hcl:"source_image"` ForceStopInstance *bool `mapstructure:"force_stop_instance" required:"false" cty:"force_stop_instance" hcl:"force_stop_instance"` DisableStopInstance *bool `mapstructure:"disable_stop_instance" required:"false" cty:"disable_stop_instance" hcl:"disable_stop_instance"` + RamRoleName *string `mapstructure:"ram_role_name" required:"false" cty:"ram_role_name" hcl:"ram_role_name"` SecurityGroupId *string `mapstructure:"security_group_id" required:"false" cty:"security_group_id" hcl:"security_group_id"` SecurityGroupName *string `mapstructure:"security_group_name" required:"false" cty:"security_group_name" hcl:"security_group_name"` UserData *string `mapstructure:"user_data" required:"false" cty:"user_data" hcl:"user_data"` @@ -177,6 +178,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "source_image": &hcldec.AttrSpec{Name: "source_image", Type: cty.String, Required: false}, "force_stop_instance": &hcldec.AttrSpec{Name: "force_stop_instance", Type: cty.Bool, Required: false}, "disable_stop_instance": &hcldec.AttrSpec{Name: "disable_stop_instance", Type: cty.Bool, Required: false}, + "ram_role_name": &hcldec.AttrSpec{Name: "ram_role_name", Type: cty.String, Required: false}, "security_group_id": &hcldec.AttrSpec{Name: "security_group_id", Type: cty.String, Required: false}, "security_group_name": &hcldec.AttrSpec{Name: "security_group_name", Type: cty.String, Required: false}, "user_data": &hcldec.AttrSpec{Name: "user_data", Type: cty.String, Required: false}, diff --git a/website/content/partials/builder/alicloud/ecs/RunConfig-not-required.mdx b/website/content/partials/builder/alicloud/ecs/RunConfig-not-required.mdx index edb8e05e5..d8bcad19b 100644 --- a/website/content/partials/builder/alicloud/ecs/RunConfig-not-required.mdx +++ b/website/content/partials/builder/alicloud/ecs/RunConfig-not-required.mdx @@ -24,6 +24,8 @@ E.g., Sysprep a windows which may shutdown the instance within its command. The default value is false. +- `ram_role_name` (string) - Ram Role to apply when launching the instance. + - `security_group_id` (string) - ID of the security group to which a newly created instance belongs. Mutual access is allowed between instances in one security group. If not specified, the newly created instance will be added