From 0b88177cf064335b091b083810c5b99d4c791660 Mon Sep 17 00:00:00 2001 From: David Radcliffe Date: Thu, 3 Sep 2015 15:43:41 -0400 Subject: [PATCH] read iam_instance_profile and save to state --- builtin/providers/aws/resource_aws_instance.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/builtin/providers/aws/resource_aws_instance.go b/builtin/providers/aws/resource_aws_instance.go index 9307c13673ce..2d42e24d7a8c 100644 --- a/builtin/providers/aws/resource_aws_instance.go +++ b/builtin/providers/aws/resource_aws_instance.go @@ -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 { @@ -1070,3 +1077,7 @@ func awsTerminateInstance(conn *ec2.EC2, id string) error { return nil } + +func iamInstanceProfileArnToName(arn *string) string { + return strings.Split(*arn, "/")[1] +}