Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 29 additions & 7 deletions internal/services/network/nat_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package network

import (
"context"
"fmt"
"log"
"time"
Expand Down Expand Up @@ -49,6 +50,16 @@ func resourceNatGateway() *pluginsdk.Resource {
SchemaFunc: pluginsdk.GenerateIdentitySchema(&natgateways.NatGatewayId{}),
},

CustomizeDiff: func(_ context.Context, diff *schema.ResourceDiff, _ interface{}) error {
if diff.Get("sku_name").(string) == string(natgateways.NatGatewaySkuNameStandardVTwo) {
if !diff.GetRawConfig().AsValueMap()["zones"].IsNull() {
return fmt.Errorf("%s resources with `sku_name` set to `%s` are zone-redundant by default, Azure automatically deploys across all available zones. The `zones` argument must be omitted", natGatewayResourceName, natgateways.NatGatewaySkuNameStandardVTwo)
}
}

return nil
},

Schema: resourceNatGatewaySchema(),
}
}
Expand All @@ -74,15 +85,26 @@ func resourceNatGatewaySchema() map[string]*pluginsdk.Schema {
},

"sku_name": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(natgateways.NatGatewaySkuNameStandard),
ValidateFunc: validation.StringInSlice([]string{
string(natgateways.NatGatewaySkuNameStandard),
}, false),
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
Default: string(natgateways.NatGatewaySkuNameStandard),
ValidateFunc: validation.StringInSlice(natgateways.PossibleValuesForNatGatewaySkuName(), false),
},

"zones": commonschema.ZonesMultipleOptionalForceNew(),
"zones": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
DiffSuppressOnRefresh: true,
DiffSuppressFunc: func(_, _, _ string, d *schema.ResourceData) bool {
return d.Get("sku_name").(string) == string(natgateways.NatGatewaySkuNameStandardVTwo)
},
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringIsNotEmpty,
},
},

"resource_guid": {
Type: pluginsdk.TypeString,
Expand Down
35 changes: 35 additions & 0 deletions internal/services/network/nat_gateway_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ func TestAccNatGateway_update(t *testing.T) {
})
}

func TestAccNatGateway_standardVTwo(t *testing.T) {
Comment thread
sreallymatt marked this conversation as resolved.
data := acceptance.BuildTestData(t, "azurerm_nat_gateway", "test")
r := NatGatewayResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.standardVTwo(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (t NatGatewayResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := natgateways.ParseNatGatewayID(state.ID)
if err != nil {
Expand Down Expand Up @@ -208,3 +223,23 @@ resource "azurerm_nat_gateway_public_ip_prefix_association" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (NatGatewayResource) standardVTwo(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-network-%d"
location = "%s"
}

resource "azurerm_nat_gateway" "test" {
name = "acctestnatGateway-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku_name = "StandardV2"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
Comment thread
sreallymatt marked this conversation as resolved.
12 changes: 6 additions & 6 deletions internal/services/network/public_ip_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAccDataSourcePublicIP_static(t *testing.T) {
})
}

func TestAccDataSourcePublicIP_dynamic(t *testing.T) {
func TestAccDataSourcePublicIP_staticMinimal(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_public_ip", "test")
r := PublicIPDataSource{}

Expand All @@ -48,13 +48,13 @@ func TestAccDataSourcePublicIP_dynamic(t *testing.T) {

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: r.dynamic(data, "IPv4"),
Config: r.staticMinimal(data, "IPv4"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("name").HasValue(name),
check.That(data.ResourceName).Key("resource_group_name").HasValue(resourceGroupName),
check.That(data.ResourceName).Key("domain_name_label").HasValue(""),
check.That(data.ResourceName).Key("fqdn").HasValue(""),
check.That(data.ResourceName).Key("ip_address").HasValue(""),
check.That(data.ResourceName).Key("ip_address").Exists(),
check.That(data.ResourceName).Key("ip_version").HasValue("IPv4"),
check.That(data.ResourceName).Key("tags.%").HasValue("1"),
check.That(data.ResourceName).Key("tags.environment").HasValue("test"),
Expand Down Expand Up @@ -100,7 +100,7 @@ data "azurerm_public_ip" "test" {
`, resourceGroupName, data.Locations.Primary, name, data.RandomInteger)
}

func (PublicIPDataSource) dynamic(data acceptance.TestData, ipVersion string) string {
func (PublicIPDataSource) staticMinimal(data acceptance.TestData, ipVersion string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand All @@ -115,8 +115,8 @@ resource "azurerm_public_ip" "test" {
name = "acctestpublicip-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
allocation_method = "Dynamic"
sku = "Basic"
allocation_method = "Static"
sku = "Standard"

ip_version = "%s"

Expand Down
26 changes: 19 additions & 7 deletions internal/services/network/public_ip_prefix_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
package network

import (
"context"
"errors"
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
Expand Down Expand Up @@ -65,13 +68,11 @@ func resourcePublicIpPrefix() *pluginsdk.Resource {
},

"sku": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
Default: string(publicipprefixes.PublicIPPrefixSkuNameStandard),
ValidateFunc: validation.StringInSlice([]string{
string(publicipprefixes.PublicIPPrefixSkuNameStandard),
}, false),
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
Default: string(publicipprefixes.PublicIPPrefixSkuNameStandard),
ValidateFunc: validation.StringInSlice(publicipprefixes.PossibleValuesForPublicIPPrefixSkuName(), false),
},

"sku_tier": {
Expand Down Expand Up @@ -110,6 +111,17 @@ func resourcePublicIpPrefix() *pluginsdk.Resource {

"tags": commonschema.Tags(),
},

CustomizeDiff: pluginsdk.CustomDiffWithAll(
pluginsdk.CustomizeDiffShim(func(_ context.Context, d *pluginsdk.ResourceDiff, _ interface{}) error {
skuTier := d.Get("sku_tier").(string)
sku := d.Get("sku").(string)
if strings.EqualFold(skuTier, string(publicipprefixes.PublicIPPrefixSkuTierGlobal)) && !strings.EqualFold(sku, string(publicipprefixes.PublicIPPrefixSkuNameStandard)) {
return errors.New("`sku` must be set to `Standard` when `sku_tier` is set to `Global`")
}
return nil
}),
),
}
}

Expand Down
11 changes: 7 additions & 4 deletions internal/services/network/public_ip_prefix_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ func TestAccPublicIpPrefix_globalTier(t *testing.T) {

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.sku_tier(data, string(publicipprefixes.PublicIPPrefixSkuTierGlobal)),
Config: r.sku_tier(data, string(publicipprefixes.PublicIPPrefixSkuNameStandard), string(publicipprefixes.PublicIPPrefixSkuTierGlobal)),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("sku").HasValue(string(publicipprefixes.PublicIPPrefixSkuNameStandard)),
check.That(data.ResourceName).Key("sku_tier").HasValue(string(publicipprefixes.PublicIPPrefixSkuTierGlobal)),
),
},
Expand Down Expand Up @@ -104,9 +105,10 @@ func TestAccPublicIpPrefix_regionalTier(t *testing.T) {

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.sku_tier(data, string(publicipprefixes.PublicIPPrefixSkuTierRegional)),
Config: r.sku_tier(data, string(publicipprefixes.PublicIPPrefixSkuNameStandard), string(publicipprefixes.PublicIPPrefixSkuTierRegional)),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("sku").HasValue(string(publicipprefixes.PublicIPPrefixSkuNameStandard)),
check.That(data.ResourceName).Key("sku_tier").HasValue(string(publicipprefixes.PublicIPPrefixSkuTierRegional)),
),
},
Expand Down Expand Up @@ -393,7 +395,7 @@ resource "azurerm_public_ip_prefix" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (PublicIpPrefixResource) sku_tier(data acceptance.TestData, tier string) string {
func (PublicIpPrefixResource) sku_tier(data acceptance.TestData, sku string, tier string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand All @@ -408,9 +410,10 @@ resource "azurerm_public_ip_prefix" "test" {
resource_group_name = azurerm_resource_group.test.name
name = "acctestpublicipprefix-%d"
location = azurerm_resource_group.test.location
sku = "%s"
sku_tier = "%s"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, tier)
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, sku, tier)
}

func (PublicIpPrefixResource) zonesSingle(data acceptance.TestData) string {
Expand Down
30 changes: 23 additions & 7 deletions internal/services/network/public_ip_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package network

import (
"context"
"errors"
"fmt"
"log"
"strings"
Expand Down Expand Up @@ -109,10 +110,7 @@ func resourcePublicIp() *pluginsdk.Resource {
ForceNew: true,
Default: string(publicipaddresses.PublicIPAddressSkuNameStandard),
// https://azure.microsoft.com/en-us/updates/upgrade-to-standard-sku-public-ip-addresses-in-azure-by-30-september-2025-basic-sku-will-be-retired/
Comment thread
sreallymatt marked this conversation as resolved.
ValidateFunc: validation.StringInSlice([]string{
string(publicipaddresses.PublicIPAddressSkuNameBasic),
string(publicipaddresses.PublicIPAddressSkuNameStandard),
}, false),
ValidateFunc: validation.StringInSlice(publicipaddresses.PossibleValuesForPublicIPAddressSkuName(), false),
Comment thread
sreallymatt marked this conversation as resolved.
},

"sku_tier": {
Expand Down Expand Up @@ -182,13 +180,31 @@ func resourcePublicIp() *pluginsdk.Resource {
},

CustomizeDiff: pluginsdk.CustomDiffWithAll(
pluginsdk.CustomizeDiffShim(func(_ context.Context, d *pluginsdk.ResourceDiff, _ interface{}) error {
sku := d.Get("sku").(string)
if strings.EqualFold(sku, string(publicipaddresses.PublicIPAddressSkuNameBasic)) && d.HasChanges("name", "resource_group_name", "location", "allocation_method", "edge_zone", "ip_version", "sku", "sku_tier", "public_ip_prefix_id", "ip_tags", "zones") {
return errors.New(publicIPBasicSkuCreateDeprecationMessage)
}

return nil
}),
pluginsdk.CustomizeDiffShim(func(_ context.Context, d *pluginsdk.ResourceDiff, _ interface{}) error {
skuTier := d.Get("sku_tier").(string)
sku := d.Get("sku").(string)
if strings.EqualFold(skuTier, string(publicipaddresses.PublicIPAddressSkuTierGlobal)) && !strings.EqualFold(sku, string(publicipaddresses.PublicIPAddressSkuNameStandard)) {
return errors.New("`sku` must be set to `Standard` when `sku_tier` is set to `Global`")
}
return nil
}),
pluginsdk.ForceNewIfChange("domain_name_label_scope", func(ctx context.Context, old, new, meta interface{}) bool {
return old.(string) != "" || new.(string) == ""
}),
),
}
}

const publicIPBasicSkuCreateDeprecationMessage = "creation of new `Basic` SKU public IP addresses is no longer permitted following its deprecation on March 31, 2025. This also affects `allocation_method` set to `Dynamic`, as it is only available with the `Basic` SKU. For more information, see https://azure.microsoft.com/updates/upgrade-to-standard-sku-public-ip-addresses-in-azure-by-30-september-2025-basic-sku-will-be-retired/"

func resourcePublicIpCreate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Network.PublicIPAddresses
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
Expand All @@ -213,9 +229,9 @@ func resourcePublicIpCreate(d *pluginsdk.ResourceData, meta interface{}) error {
sku := d.Get("sku").(string)
ipAllocationMethod := d.Get("allocation_method").(string)

if strings.EqualFold(sku, "standard") {
if !strings.EqualFold(ipAllocationMethod, "static") {
return fmt.Errorf("static IP allocation must be used when creating Standard SKU public IP addresses")
if strings.EqualFold(sku, string(publicipaddresses.PublicIPAddressSkuNameStandard)) || strings.EqualFold(sku, string(publicipaddresses.PublicIPAddressSkuNameStandardVTwo)) {
if !strings.EqualFold(ipAllocationMethod, string(publicipaddresses.IPAllocationMethodStatic)) {
return fmt.Errorf("`allocation_method` must be set to `Static` when `sku` is set to `Standard` or `StandardV2`")
}
}

Expand Down
Loading
Loading