Skip to content

Commit

Permalink
aws-ec2: add iam_instance_profile option
Browse files Browse the repository at this point in the history
  • Loading branch information
stephank committed Jan 5, 2021
1 parent 4e22574 commit 8d5e6d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
3 changes: 3 additions & 0 deletions doc/providers/aws_ec2.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ target "<address>" "aws_ec2" {
packages: [jq]
EOF
# Optional name of an IAM instance profile.
iam_instance_profile = "example"
# Optional alternate profile to use from local AWS configuration.
profile = "default" # The default
Expand Down
31 changes: 20 additions & 11 deletions providers/aws_ec2/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Factory struct{}

type Provider struct {
BlockDeviceMappings []*types.BlockDeviceMapping
IamInstanceProfile *types.IamInstanceProfileSpecification
ImageId string
InstanceType types.InstanceType
KeyName string
Expand All @@ -45,17 +46,18 @@ type state struct {
}

type hclTarget struct {
EbsBlockDevice []*hclEbsBlockDevice `hcl:"ebs_block_device,block"`
ImageId string `hcl:"image_id,attr"`
InstanceType string `hcl:"instance_type,attr"`
KeyName string `hcl:"key_name,attr"`
SubnetId *string `hcl:"subnet_id,optional"`
UserData *string `hcl:"user_data,optional"`
Profile *string `hcl:"profile,optional"`
Region *string `hcl:"region,optional"`
CheckPort uint16 `hcl:"check_port,optional"`
Shared *bool `hcl:"shared,optional"`
Linger string `hcl:"linger,optional"`
EbsBlockDevice []*hclEbsBlockDevice `hcl:"ebs_block_device,block"`
ImageId string `hcl:"image_id,attr"`
InstanceType string `hcl:"instance_type,attr"`
KeyName string `hcl:"key_name,attr"`
SubnetId *string `hcl:"subnet_id,optional"`
UserData *string `hcl:"user_data,optional"`
IamInstanceProfile string `hcl:"iam_instance_profile,optional"`
Profile *string `hcl:"profile,optional"`
Region *string `hcl:"region,optional"`
CheckPort uint16 `hcl:"check_port,optional"`
Shared *bool `hcl:"shared,optional"`
Linger string `hcl:"linger,optional"`
}

type hclEbsBlockDevice struct {
Expand Down Expand Up @@ -152,6 +154,12 @@ func (factory *Factory) NewProvider(target string, hclBlock hcl.Body) (providers
prov.UserData64 = aws.String(base64.StdEncoding.EncodeToString([]byte(*parsed.UserData)))
}

if parsed.IamInstanceProfile != "" {
prov.IamInstanceProfile = &types.IamInstanceProfileSpecification{
Name: aws.String(parsed.IamInstanceProfile),
}
}

if diags.HasErrors() {
return nil, diags
}
Expand Down Expand Up @@ -185,6 +193,7 @@ func (prov *Provider) start(mach *providers.Machine) bool {
KeyName: &prov.KeyName,
SubnetId: prov.SubnetId,
UserData: prov.UserData64,
IamInstanceProfile: prov.IamInstanceProfile,
})
if err != nil {
log.Printf("EC2 instance failed to start: %s\n", err.Error())
Expand Down

0 comments on commit 8d5e6d3

Please sign in to comment.