Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_public_ip: computed values now default to an empy string #1247

Merged
merged 3 commits into from
May 19, 2018
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
64 changes: 26 additions & 38 deletions azurerm/resource_arm_public_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func resourceArmPublicIp() *schema.Resource {
Read: resourceArmPublicIpRead,
Update: resourceArmPublicIpCreate,
Delete: resourceArmPublicIpDelete,

Importer: &schema.ResourceImporter{
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
id, err := parseAzureResourceID(d.Id())
Expand Down Expand Up @@ -46,24 +47,32 @@ func resourceArmPublicIp() *schema.Resource {
"zones": singleZonesSchema(),

"public_ip_address_allocation": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validatePublicIpAllocation,
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(network.Static),
string(network.Dynamic),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
StateFunc: ignoreCaseStateFunc,
},

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

"idle_timeout_in_minutes": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(int)
if value < 4 || value > 30 {
errors = append(errors, fmt.Errorf(
"The idle timeout must be between 4 and 30 minutes"))
}
return
},
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(4, 30),
},

"domain_name_label": {
Expand All @@ -87,18 +96,6 @@ 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 Down Expand Up @@ -227,11 +224,15 @@ func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error {
if settings := props.DNSSettings; settings != nil {
if fqdn := settings.Fqdn; fqdn != nil {
d.Set("fqdn", fqdn)
} else {
d.Set("fqdn", "")
}
}

if ip := props.IPAddress; ip != nil {
d.Set("ip_address", ip)
} else {
d.Set("ip_address", "")
}
}

Expand Down Expand Up @@ -264,19 +265,6 @@ func resourceArmPublicIpDelete(d *schema.ResourceData, meta interface{}) error {
return nil
}

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

if !allocations[value] {
errors = append(errors, fmt.Errorf("Public IP Allocation must be an accepted value: Static, Dynamic"))
}
return
}

func validatePublicIpDomainNameLabel(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[a-z0-9-]+$`).MatchString(value) {
Expand Down
36 changes: 0 additions & 36 deletions azurerm/resource_arm_public_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,6 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func TestResourceAzureRMPublicIpAllocation_validation(t *testing.T) {
cases := []struct {
Value string
ErrCount int
}{
{
Value: "Random",
ErrCount: 1,
},
{
Value: "Static",
ErrCount: 0,
},
{
Value: "Dynamic",
ErrCount: 0,
},
{
Value: "STATIC",
ErrCount: 0,
},
{
Value: "static",
ErrCount: 0,
},
}

for _, tc := range cases {
_, errors := validatePublicIpAllocation(tc.Value, "azurerm_public_ip")

if len(errors) != tc.ErrCount {
t.Fatalf("Expected the Azure RM Public IP allocation to trigger a validation error")
}
}
}

func TestResourceAzureRMPublicIpDomainNameLabel_validation(t *testing.T) {
cases := []struct {
Value string
Expand Down