Skip to content

Commit

Permalink
azurerm_public_ip_prefix: adding sku_tier property (#27882)
Browse files Browse the repository at this point in the history
* Add sku_tier to public_ip_prefix

* Fix format.

* Replacing explicit values listing by Function returning the values.
  • Loading branch information
CorrenSoft authored Nov 5, 2024
1 parent 3251539 commit 2fc04ee
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 3 deletions.
6 changes: 6 additions & 0 deletions internal/services/network/public_ip_prefix_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func dataSourcePublicIpPrefix() *pluginsdk.Resource {
Computed: true,
},

"sku_tier": {
Type: pluginsdk.TypeString,
Computed: true,
},

"prefix_length": {
Type: pluginsdk.TypeInt,
Computed: true,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"),
Expand Down
14 changes: 11 additions & 3 deletions internal/services/network/public_ip_prefix_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ func resourcePublicIpPrefix() *pluginsdk.Resource {
}, false),
},

"sku_tier": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(publicipprefixes.PublicIPPrefixSkuTierRegional),
ForceNew: true,
ValidateFunc: validation.StringInSlice(publicipprefixes.PossibleValuesForPublicIPPrefixSkuTier(), false),
},

"prefix_length": {
Type: pluginsdk.TypeInt,
Optional: true,
Expand Down Expand Up @@ -118,6 +126,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))),
Expand Down Expand Up @@ -190,11 +199,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)
Expand Down
52 changes: 52 additions & 0 deletions internal/services/network/public_ip_prefix_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/public_ip_prefix.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/public_ip_prefix.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2fc04ee

Please sign in to comment.