Skip to content

Commit

Permalink
Merge pull request #3167 from dwradcliffe/read_instance_role
Browse files Browse the repository at this point in the history
provider/aws: read iam_instance_profile for instance and save to state
  • Loading branch information
phinze committed Sep 5, 2015
2 parents 2bf9aec + 0b88177 commit d937045
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions builtin/providers/aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,13 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("public_ip", instance.PublicIpAddress)
d.Set("private_dns", instance.PrivateDnsName)
d.Set("private_ip", instance.PrivateIpAddress)

if instance.IamInstanceProfile != nil {
d.Set("iam_instance_profile", iamInstanceProfileArnToName(instance.IamInstanceProfile.Arn))
} else if _, ok := d.GetOk("iam_instance_profile"); ok {
d.Set("iam_instance_profile", "")
}

if len(instance.NetworkInterfaces) > 0 {
d.Set("subnet_id", instance.NetworkInterfaces[0].SubnetId)
} else {
Expand Down Expand Up @@ -1070,3 +1077,7 @@ func awsTerminateInstance(conn *ec2.EC2, id string) error {

return nil
}

func iamInstanceProfileArnToName(arn *string) string {
return strings.Split(*arn, "/")[1]
}

0 comments on commit d937045

Please sign in to comment.