From c2c001a3006efe2323bceb00c530fcca5c130883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Fern=C3=A1ndez?= Date: Mon, 4 Nov 2024 14:39:51 -0300 Subject: [PATCH] Add sku_tier to public_ip_prefix --- .../network/public_ip_prefix_data_source.go | 6 +++ .../public_ip_prefix_data_source_test.go | 2 + .../network/public_ip_prefix_resource.go | 17 ++++-- .../network/public_ip_prefix_resource_test.go | 52 +++++++++++++++++++ website/docs/d/public_ip_prefix.html.markdown | 1 + website/docs/r/public_ip_prefix.html.markdown | 2 + 6 files changed, 77 insertions(+), 3 deletions(-) diff --git a/internal/services/network/public_ip_prefix_data_source.go b/internal/services/network/public_ip_prefix_data_source.go index f01d91382a72..049cfd1cca15 100644 --- a/internal/services/network/public_ip_prefix_data_source.go +++ b/internal/services/network/public_ip_prefix_data_source.go @@ -42,6 +42,11 @@ func dataSourcePublicIpPrefix() *pluginsdk.Resource { Computed: true, }, + "sku_tier": { + Type: pluginsdk.TypeString, + Computed: true, + }, + "prefix_length": { Type: pluginsdk.TypeInt, Computed: true, @@ -82,6 +87,7 @@ func dataSourcePublicIpPrefixRead(d *pluginsdk.ResourceData, meta interface{}) e if sku := model.Sku; sku != nil { d.Set("sku", string(pointer.From(sku.Name))) + d.Set("sku_tier", string(pointer.From(sku.Tier))) } if props := model.Properties; props != nil { d.Set("prefix_length", props.PrefixLength) diff --git a/internal/services/network/public_ip_prefix_data_source_test.go b/internal/services/network/public_ip_prefix_data_source_test.go index 26c23e46d8d6..1109d71a5707 100644 --- a/internal/services/network/public_ip_prefix_data_source_test.go +++ b/internal/services/network/public_ip_prefix_data_source_test.go @@ -7,6 +7,7 @@ import ( "fmt" "testing" + "github.com/hashicorp/go-azure-sdk/resource-manager/network/2024-03-01/publicipprefixes" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" ) @@ -27,6 +28,7 @@ func TestAccDataSourcePublicIPPrefix_basic(t *testing.T) { check.That(data.ResourceName).Key("resource_group_name").HasValue(resourceGroupName), check.That(data.ResourceName).Key("location").HasValue(data.Locations.Primary), check.That(data.ResourceName).Key("sku").HasValue("Standard"), + check.That(data.ResourceName).Key("sku_tier").HasValue(string(publicipprefixes.PublicIPPrefixSkuTierRegional)), check.That(data.ResourceName).Key("prefix_length").HasValue("31"), check.That(data.ResourceName).Key("ip_prefix").Exists(), check.That(data.ResourceName).Key("tags.%").HasValue("1"), diff --git a/internal/services/network/public_ip_prefix_resource.go b/internal/services/network/public_ip_prefix_resource.go index 804b6bcfcc5e..f44097b4727a 100644 --- a/internal/services/network/public_ip_prefix_resource.go +++ b/internal/services/network/public_ip_prefix_resource.go @@ -63,6 +63,17 @@ func resourcePublicIpPrefix() *pluginsdk.Resource { }, false), }, + "sku_tier": { + Type: pluginsdk.TypeString, + Optional: true, + Default: string(publicipprefixes.PublicIPPrefixSkuTierRegional), + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + string(publicipprefixes.PublicIPPrefixSkuTierGlobal), + string(publicipprefixes.PublicIPPrefixSkuTierRegional), + }, false), + }, + "prefix_length": { Type: pluginsdk.TypeInt, Optional: true, @@ -118,6 +129,7 @@ func resourcePublicIpPrefixCreate(d *pluginsdk.ResourceData, meta interface{}) e Location: pointer.To(location.Normalize(d.Get("location").(string))), Sku: &publicipprefixes.PublicIPPrefixSku{ Name: pointer.To(publicipprefixes.PublicIPPrefixSkuName(d.Get("sku").(string))), + Tier: pointer.To(publicipprefixes.PublicIPPrefixSkuTier(d.Get("sku_tier").(string))), }, Properties: &publicipprefixes.PublicIPPrefixPropertiesFormat{ PrefixLength: pointer.To(int64(d.Get("prefix_length").(int))), @@ -190,11 +202,10 @@ func resourcePublicIpPrefixRead(d *pluginsdk.ResourceData, meta interface{}) err if model := resp.Model; model != nil { d.Set("location", location.NormalizeNilable(model.Location)) d.Set("zones", zones.FlattenUntyped(model.Zones)) - skuName := "" if sku := model.Sku; sku != nil { - skuName = string(pointer.From(sku.Name)) + d.Set("sku", string(pointer.From(sku.Name))) + d.Set("sku_tier", string(pointer.From(sku.Tier))) } - d.Set("sku", skuName) if props := model.Properties; props != nil { d.Set("prefix_length", props.PrefixLength) d.Set("ip_prefix", props.IPPrefix) diff --git a/internal/services/network/public_ip_prefix_resource_test.go b/internal/services/network/public_ip_prefix_resource_test.go index 2c3685633ef9..dfd129795a53 100644 --- a/internal/services/network/public_ip_prefix_resource_test.go +++ b/internal/services/network/public_ip_prefix_resource_test.go @@ -63,6 +63,38 @@ func TestAccPublicIpPrefix_basic(t *testing.T) { }) } +func TestAccPublicIpPrefix_globalTier(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_public_ip_prefix", "test") + r := PublicIPPrefixResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.sku_tier(data, string(publicipprefixes.PublicIPPrefixSkuTierGlobal)), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_tier").HasValue(string(publicipprefixes.PublicIPPrefixSkuTierGlobal)), + ), + }, + data.ImportStep(), + }) +} + +func TestAccPublicIpPrefix_regionalTier(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_public_ip_prefix", "test") + r := PublicIPPrefixResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.sku_tier(data, string(publicipprefixes.PublicIPPrefixSkuTierRegional)), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_tier").HasValue(string(publicipprefixes.PublicIPPrefixSkuTierRegional)), + ), + }, + data.ImportStep(), + }) +} + func TestAccPublicIpPrefix_ipv6(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_public_ip_prefix", "test") r := PublicIPPrefixResource{} @@ -342,6 +374,26 @@ resource "azurerm_public_ip_prefix" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } +func (PublicIPPrefixResource) sku_tier(data acceptance.TestData, tier string) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_public_ip_prefix" "test" { + resource_group_name = azurerm_resource_group.test.name + name = "acctestpublicipprefix-%d" + location = azurerm_resource_group.test.location + sku_tier = "%s" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, tier) +} + func (PublicIPPrefixResource) zonesSingle(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/website/docs/d/public_ip_prefix.html.markdown b/website/docs/d/public_ip_prefix.html.markdown index f8f47575c220..4fe3deb77cfd 100644 --- a/website/docs/d/public_ip_prefix.html.markdown +++ b/website/docs/d/public_ip_prefix.html.markdown @@ -35,6 +35,7 @@ output "public_ip_prefix" { * `ip_prefix` - The Public IP address range, in CIDR notation. * `location` - The supported Azure location where the resource exists. * `sku` - The SKU of the Public IP Prefix. +* `sku_tier` - The SKU Tier of the Public IP. * `prefix_length` - The number of bits of the prefix. * `tags` - A mapping of tags to assigned to the resource. * `zones` - A list of Availability Zones in which this Public IP Prefix is located. diff --git a/website/docs/r/public_ip_prefix.html.markdown b/website/docs/r/public_ip_prefix.html.markdown index c121273c1597..260823b62295 100644 --- a/website/docs/r/public_ip_prefix.html.markdown +++ b/website/docs/r/public_ip_prefix.html.markdown @@ -45,6 +45,8 @@ The following arguments are supported: -> **Note:** Public IP Prefix can only be created with Standard SKUs at this time. +* `sku_tier` - (Optional) The SKU Tier that should be used for the Public IP. Possible values are `Regional` and `Global`. Defaults to `Regional`. Changing this forces a new resource to be created. + * `ip_version` - (Optional) The IP Version to use, `IPv6` or `IPv4`. Changing this forces a new resource to be created. Default is `IPv4`. * `prefix_length` - (Optional) Specifies the number of bits of the prefix. The value can be set between 0 (4,294,967,296 addresses) and 31 (2 addresses). Defaults to `28`(16 addresses). Changing this forces a new resource to be created.