Skip to content

Commit

Permalink
Merge pull request #5104 from terraform-providers/b/nat-gateway
Browse files Browse the repository at this point in the history
r/nat_gateway: handling a crash when the `sku` block is nil
  • Loading branch information
tombuildsstuff authored Dec 9, 2019
2 parents 21b0bb4 + 52eb19e commit 78572c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions azurerm/data_source_nat_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ func dataSourceArmNatGatewayRead(d *schema.ResourceData, meta interface{}) error
}
return fmt.Errorf("Error reading Nat Gateway %q (Resource Group %q): %+v", name, resourceGroup, err)
}
if resp.ID == nil {
if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("Cannot read NAT Gateway %q (Resource Group %q) ID", name, resourceGroup)
}
d.SetId(*resp.ID)

d.Set("name", resp.Name)
d.Set("sku_name", resp.Sku.Name)
d.Set("resource_group_name", resourceGroup)
if sku := resp.Sku; sku != nil {
d.Set("sku_name", resp.Sku.Name)
}

if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_nat_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func resourceArmNatGatewayCreateUpdate(d *schema.ResourceData, meta interface{})
if err != nil {
return fmt.Errorf("Error retrieving NAT Gateway %q (Resource Group %q): %+v", name, resourceGroup, err)
}
if resp.ID == nil {
if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("Cannot read NAT Gateway %q (Resource Group %q) ID", name, resourceGroup)
}
d.SetId(*resp.ID)
Expand Down

0 comments on commit 78572c9

Please sign in to comment.