Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions internal/services/network/nat_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
package network

import (
"context"
"fmt"
"log"
"sort"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
Expand Down Expand Up @@ -50,6 +52,31 @@ func resourceNatGateway() *pluginsdk.Resource {
},

Schema: resourceNatGatewaySchema(),

CustomizeDiff: pluginsdk.CustomizeDiffShim(func(ctx context.Context, d *pluginsdk.ResourceDiff, _ interface{}) error {
skuName := d.Get("sku_name").(string)

if skuName == string(natgateways.NatGatewaySkuNameStandardVTwo) {
zonesRaw := d.Get("zones").(*schema.Set).List()
if len(zonesRaw) == 0 {
return fmt.Errorf("`zones` must be set to [1, 2, 3] when using StandardV2 SKU")
}

zones := make([]string, 0, len(zonesRaw))
for _, z := range zonesRaw {
zones = append(zones, z.(string))
}

sort.Strings(zones)

requiredZones := []string{"1", "2", "3"}
if len(zones) != 3 || zones[0] != "1" || zones[1] != "2" || zones[2] != "3" {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified using slices.Equal(zones, []string{"1", "2", "3"})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

return fmt.Errorf("`zones` must be set to [1, 2, 3] when using `StandardV2` SKU, got %v", requiredZones)
}
}

return nil
}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/nat_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The following arguments are supported:

* `sku_name` - (Optional) The SKU which should be used. Possible values are `Standard` and `StandardV2`. Defaults to `Standard`.

-> **Note:** When `StandardV2` is enabled, service API will also enable all availability zones. See [MS learn documentation](https://learn.microsoft.com/en-us/azure/nat-gateway/nat-overview#standardv2-nat-gateway) for more info. The user has to explicitly set this property in the Terraform configuration or handle it using `ignore_changes`.
-> **Note:** `StandardV2` SKU requires `zones` to be set to `[1,2,3]`, see [MS learn documentation](https://learn.microsoft.com/en-us/azure/nat-gateway/nat-overview#standardv2-nat-gateway) for more info.

* `tags` - (Optional) A mapping of tags to assign to the resource.

Expand Down
Loading