Skip to content

Commit

Permalink
ignore error when fetching tags failed in ReadFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiChangkuo committed May 30, 2020
1 parent d1adb0a commit d41cef9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
16 changes: 10 additions & 6 deletions huaweicloud/resource_huaweicloud_vpc_subnet_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,16 @@ func resourceVpcSubnetV1Read(d *schema.ResourceData, meta interface{}) error {
}
resourceTags, err := tags.Get(vpcSubnetV2Client, "subnets", d.Id()).Extract()
if err != nil {
return fmt.Errorf("Error fetching HuaweiCloud VpcSubnet tags: %s", err)
}

tagmap := tagsToMap(resourceTags.Tags)
if err := d.Set("tags", tagmap); err != nil {
return fmt.Errorf("Error saving tags for HuaweiCloud VpcSubnet (%s): %s", d.Id(), err)
if err404, ok := err.(golangsdk.ErrDefault404); ok {
log.Printf("[INFO] fetching Subnet tags failed: %s", err404)
} else {
return fmt.Errorf("Error fetching HuaweiCloud Subnet %s tags: %s", d.Id(), err)
}
} else {
tagmap := tagsToMap(resourceTags.Tags)
if err := d.Set("tags", tagmap); err != nil {
return fmt.Errorf("Error saving HuaweiCloud Subnet %s tags: %s", d.Id(), err)
}
}

return nil
Expand Down
16 changes: 10 additions & 6 deletions huaweicloud/resource_huaweicloud_vpc_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,16 @@ func resourceVirtualPrivateCloudV1Read(d *schema.ResourceData, meta interface{})
}
resourceTags, err := tags.Get(vpcV2Client, "vpcs", d.Id()).Extract()
if err != nil {
return fmt.Errorf("Error fetching HuaweiCloud VirtualPrivateCloud tags: %s", err)
}

tagmap := tagsToMap(resourceTags.Tags)
if err := d.Set("tags", tagmap); err != nil {
return fmt.Errorf("Error saving tags for HuaweiCloud VirtualPrivateCloud (%s): %s", d.Id(), err)
if err404, ok := err.(golangsdk.ErrDefault404); ok {
log.Printf("[INFO] fetching VPC tags failed: %s", err404)
} else {
return fmt.Errorf("Error fetching HuaweiCloud VPC %s tags: %s", d.Id(), err)
}
} else {
tagmap := tagsToMap(resourceTags.Tags)
if err := d.Set("tags", tagmap); err != nil {
return fmt.Errorf("Error saving HuaweiCloud VPC %s tags: %s", d.Id(), err)
}
}

return nil
Expand Down

0 comments on commit d41cef9

Please sign in to comment.