provider/aws: tweak iam_instance_profile logic
- always `d.Set` to either the profile name or the empty string - add some conservative pointer checking to the helper method /cc @dwradcliffe
This commit is contained in:
parent
66e73b8350
commit
1dfad739bb
|
@ -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]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue