diff --git a/builtin/providers/aws/resource_aws_instance.go b/builtin/providers/aws/resource_aws_instance.go index 2d42e24d7..b79923d82 100644 --- a/builtin/providers/aws/resource_aws_instance.go +++ b/builtin/providers/aws/resource_aws_instance.go @@ -469,12 +469,7 @@ 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", "") - } + d.Set("iam_instance_profile", iamInstanceProfileArnToName(instance.IamInstanceProfile)) if len(instance.NetworkInterfaces) > 0 { d.Set("subnet_id", instance.NetworkInterfaces[0].SubnetId) @@ -1078,6 +1073,9 @@ func awsTerminateInstance(conn *ec2.EC2, id string) error { return nil } -func iamInstanceProfileArnToName(arn *string) string { - return strings.Split(*arn, "/")[1] +func iamInstanceProfileArnToName(ip *ec2.IamInstanceProfile) string { + if ip == nil && ip.Arn == nil { + return "" + } + return strings.Split(*ip.Arn, "/")[1] }