1- // @see https://github.com/hashicorp/packer/blob/v1.6.4 /builder/amazon /common/access_config.go
1+ // @see https://github.com/hashicorp/packer-plugin-amazon /blob/v1.0.0 /builder/common/access_config.go
22
33package main
44
@@ -16,16 +16,32 @@ import (
1616 "github.com/hashicorp/go-cleanhttp"
1717)
1818
19+ // AssumeRoleConfig lets users set configuration options for assuming a special
20+ // role when executing this plugin.
21+ type AssumeRoleConfig struct {
22+ AssumeRoleARN string `mapstructure:"role_arn" required:"false"`
23+ AssumeRoleDurationSeconds int `mapstructure:"duration_seconds" required:"false"`
24+ AssumeRoleExternalID string `mapstructure:"external_id" required:"false"`
25+ AssumeRolePolicy string `mapstructure:"policy" required:"false"`
26+ AssumeRolePolicyARNs []string `mapstructure:"policy_arns" required:"false"`
27+ AssumeRoleSessionName string `mapstructure:"session_name" required:"false"`
28+ AssumeRoleTags map [string ]string `mapstructure:"tags" required:"false"`
29+ AssumeRoleTransitiveTagKeys []string `mapstructure:"transitive_tag_keys" required:"false"`
30+ }
31+
1932// AccessConfig is for common configuration related to AWS access
2033type AccessConfig struct {
21- AccessKey string `mapstructure:"access_key"`
22- SecretKey string `mapstructure:"secret_key"`
23- ProfileName string `mapstructure:"profile"`
24- Token string `mapstructure:"token"`
25- MFACode string `mapstructure:"mfa_code"`
26- CustomEndpointEc2 string `mapstructure:"custom_endpoint_ec2"`
27- SkipValidation bool `mapstructure:"skip_region_validation"`
28- SkipMetadataAPICheck bool `mapstructure:"skip_metadata_api_check"`
34+ AccessKey string `mapstructure:"access_key"`
35+ AssumeRole AssumeRoleConfig `mapstructure:"assume_role" required:"false"`
36+ CustomEndpointEc2 string `mapstructure:"custom_endpoint_ec2"`
37+ MFACode string `mapstructure:"mfa_code"`
38+ ProfileName string `mapstructure:"profile"`
39+ SecretKey string `mapstructure:"secret_key"`
40+ SkipMetadataAPICheck bool `mapstructure:"skip_metadata_api_check"`
41+ Token string `mapstructure:"token"`
42+
43+ // SkipValidation is not used, but it is still a valid option to keep backward compatibility.
44+ SkipValidation bool `mapstructure:"skip_region_validation"`
2945
3046 session * session.Session
3147}
@@ -102,12 +118,20 @@ func (c *AccessConfig) Session() (*session.Session, error) {
102118func (c * AccessConfig ) GetCredentials (config * aws.Config ) (* awsCredentials.Credentials , error ) {
103119 // Reload values into the config used by the Packer-Terraform shared SDK
104120 awsbaseConfig := & awsbase.Config {
105- AccessKey : c .AccessKey ,
106- DebugLogging : false ,
107- Profile : c .ProfileName ,
108- SecretKey : c .SecretKey ,
109- SkipMetadataApiCheck : c .SkipMetadataAPICheck ,
110- Token : c .Token ,
121+ AccessKey : c .AccessKey ,
122+ AssumeRoleARN : c .AssumeRole .AssumeRoleARN ,
123+ AssumeRoleDurationSeconds : c .AssumeRole .AssumeRoleDurationSeconds ,
124+ AssumeRoleExternalID : c .AssumeRole .AssumeRoleExternalID ,
125+ AssumeRolePolicy : c .AssumeRole .AssumeRolePolicy ,
126+ AssumeRolePolicyARNs : c .AssumeRole .AssumeRolePolicyARNs ,
127+ AssumeRoleSessionName : c .AssumeRole .AssumeRoleSessionName ,
128+ AssumeRoleTags : c .AssumeRole .AssumeRoleTags ,
129+ AssumeRoleTransitiveTagKeys : c .AssumeRole .AssumeRoleTransitiveTagKeys ,
130+ DebugLogging : false ,
131+ Profile : c .ProfileName ,
132+ SecretKey : c .SecretKey ,
133+ SkipMetadataApiCheck : c .SkipMetadataAPICheck ,
134+ Token : c .Token ,
111135 }
112136
113137 return awsbase .GetCredentials (awsbaseConfig )
0 commit comments