Skip to content

Commit

Permalink
pip: Add sku parameter to support Public IP Standard
Browse files Browse the repository at this point in the history
  • Loading branch information
justaugustus committed Jan 6, 2018
1 parent 0d3b9f9 commit 93ee2fb
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions azurerm/resource_arm_public_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/Azure/azure-sdk-for-go/arm/network"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand Down Expand Up @@ -84,6 +85,18 @@ func resourceArmPublicIp() *schema.Resource {
Computed: true,
},

"sku": {
Type: schema.TypeString,
Optional: true,
Default: string(network.PublicIPAddressSkuNameBasic),
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(network.PublicIPAddressSkuNameBasic),
string(network.PublicIPAddressSkuNameStandard),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},

"tags": tagsSchema(),
},
}
Expand All @@ -98,6 +111,9 @@ func resourceArmPublicIpCreate(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
location := d.Get("location").(string)
resGroup := d.Get("resource_group_name").(string)
sku := network.PublicIPAddressSku{
Name: network.PublicIPAddressSkuName(d.Get("sku").(string)),
}
tags := d.Get("tags").(map[string]interface{})

properties := network.PublicIPAddressPropertiesFormat{
Expand Down Expand Up @@ -130,8 +146,9 @@ func resourceArmPublicIpCreate(d *schema.ResourceData, meta interface{}) error {
}

publicIp := network.PublicIPAddress{
Name: &name,
Location: &location,
Name: &name,
Location: &location,
Sku: &sku,
PublicIPAddressPropertiesFormat: &properties,
Tags: expandTags(tags),
}
Expand Down Expand Up @@ -179,6 +196,13 @@ func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error {
d.Set("name", resp.Name)
d.Set("public_ip_address_allocation", strings.ToLower(string(resp.PublicIPAddressPropertiesFormat.PublicIPAllocationMethod)))

// TODO: Extract SKU from client response
/*
if sku := publicIPClient.Sku; sku != nil {
d.Set("sku", string(sku.Name))
}
*/

if resp.PublicIPAddressPropertiesFormat.DNSSettings != nil && resp.PublicIPAddressPropertiesFormat.DNSSettings.Fqdn != nil && *resp.PublicIPAddressPropertiesFormat.DNSSettings.Fqdn != "" {
d.Set("fqdn", resp.PublicIPAddressPropertiesFormat.DNSSettings.Fqdn)
}
Expand Down Expand Up @@ -208,6 +232,12 @@ func resourceArmPublicIpDelete(d *schema.ResourceData, meta interface{}) error {
return err
}

/*
TODO: Need validation for Public IP Standard restrictions
- static allocation only
- IPv4 only
*/

func validatePublicIpAllocation(v interface{}, k string) (ws []string, errors []error) {
value := strings.ToLower(v.(string))
allocations := map[string]bool{
Expand Down

0 comments on commit 93ee2fb

Please sign in to comment.