diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index 8021824bb..7509b7fb6 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -132,7 +132,7 @@ type RunConfig struct { // The name of an [IAM instance // profile](https://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html) // to launch the EC2 instance with. - IamInstanceProfile string `mapstructure:"iam_instance_profile" required:"false"` + IamInstanceProfile string `mapstructure:"iam_instance_profile" required:"false"` // Temporary IAM instance profile policy document // If IamInstanceProfile is specified it will be used instead. Example: // diff --git a/builder/amazon/common/step_iam_instance_profile.go b/builder/amazon/common/step_iam_instance_profile.go index 75d84d3be..7221e08d4 100644 --- a/builder/amazon/common/step_iam_instance_profile.go +++ b/builder/amazon/common/step_iam_instance_profile.go @@ -3,16 +3,15 @@ package common import ( "context" "fmt" - "log" "github.com/aws/aws-sdk-go/aws" + "log" "time" + "encoding/json" + "github.com/aws/aws-sdk-go/service/iam" "github.com/hashicorp/packer/common/uuid" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" - "github.com/aws/aws-sdk-go/service/iam" - "encoding/json" - ) type StepIamInstanceProfile struct { @@ -87,8 +86,8 @@ func (s *StepIamInstanceProfile) Run(ctx context.Context, state multistep.StateB ui.Say(fmt.Sprintf("Creating temporary role for this instance: %s", profileName)) roleResp, err := iamsvc.CreateRole(&iam.CreateRoleInput{ - RoleName: aws.String(profileName), - Description: aws.String("Temporary role for Packer"), + RoleName: aws.String(profileName), + Description: aws.String("Temporary role for Packer"), AssumeRolePolicyDocument: aws.String("{\"Version\": \"2012-10-17\",\"Statement\": [{\"Effect\": \"Allow\",\"Principal\": {\"Service\": \"ec2.amazonaws.com\"},\"Action\": \"sts:AssumeRole\"}]}"), }) if err != nil { @@ -115,8 +114,8 @@ func (s *StepIamInstanceProfile) Run(ctx context.Context, state multistep.StateB ui.Say(fmt.Sprintf("Attaching policy to the temporary role: %s", profileName)) _, err = iamsvc.PutRolePolicy(&iam.PutRolePolicyInput{ - RoleName: roleResp.Role.RoleName, - PolicyName:aws.String(profileName), + RoleName: roleResp.Role.RoleName, + PolicyName: aws.String(profileName), PolicyDocument: aws.String(string(policy)), }) if err != nil { @@ -128,7 +127,7 @@ func (s *StepIamInstanceProfile) Run(ctx context.Context, state multistep.StateB s.createdPolicyName = aws.StringValue(roleResp.Role.RoleName) _, err = iamsvc.AddRoleToInstanceProfile(&iam.AddRoleToInstanceProfileInput{ - RoleName: roleResp.Role.RoleName, + RoleName: roleResp.Role.RoleName, InstanceProfileName: profileResp.InstanceProfile.InstanceProfileName, }) if err != nil { @@ -140,7 +139,7 @@ func (s *StepIamInstanceProfile) Run(ctx context.Context, state multistep.StateB s.roleIsAttached = true state.Put("iamInstanceProfile", aws.StringValue(profileResp.InstanceProfile.InstanceProfileName)) - time.Sleep(5*time.Second) + time.Sleep(5 * time.Second) } return multistep.ActionContinue @@ -156,7 +155,7 @@ func (s *StepIamInstanceProfile) Cleanup(state multistep.StateBag) { _, err := iamsvc.RemoveRoleFromInstanceProfile(&iam.RemoveRoleFromInstanceProfileInput{ InstanceProfileName: aws.String(s.createdInstanceProfileName), - RoleName: aws.String(s.createdRoleName), + RoleName: aws.String(s.createdRoleName), }) if err != nil { ui.Error(fmt.Sprintf( @@ -168,7 +167,7 @@ func (s *StepIamInstanceProfile) Cleanup(state multistep.StateBag) { ui.Say("Removing policy from temporary role...") iamsvc.DeleteRolePolicy(&iam.DeleteRolePolicyInput{ PolicyName: aws.String(s.createdPolicyName), - RoleName: aws.String(s.createdRoleName), + RoleName: aws.String(s.createdRoleName), }) } if s.createdRoleName != "" { @@ -192,4 +191,4 @@ func (s *StepIamInstanceProfile) Cleanup(state multistep.StateBag) { "Error %s. Please delete the instance profile manually: %s", err.Error(), s.createdInstanceProfileName)) } } -} \ No newline at end of file +}