provider/azurerm: Fix azurerm_public_ip
``` HTTP_PROXY=http://localhost:8888 make testacc TEST=./builtin/providers/azurerm TESTARGS="-run TestAccAzureRMPublicIpStatic" ==> Checking that code complies with gofmt requirements... /Users/James/Code/go/bin/stringer go generate $(go list ./... | grep -v /vendor/) 2016/06/01 17:09:54 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMPublicIpStatic -timeout 120m === RUN TestAccAzureRMPublicIpStatic_basic --- PASS: TestAccAzureRMPublicIpStatic_basic (101.00s) === RUN TestAccAzureRMPublicIpStatic_withTags --- PASS: TestAccAzureRMPublicIpStatic_withTags (125.13s) === RUN TestAccAzureRMPublicIpStatic_update --- PASS: TestAccAzureRMPublicIpStatic_update (128.66s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 354.802s ```
This commit is contained in:
parent
876d0269df
commit
3831553c72
|
@ -52,7 +52,7 @@ func Provider() terraform.ResourceProvider {
|
||||||
//"azurerm_network_interface": resourceArmNetworkInterface(),
|
//"azurerm_network_interface": resourceArmNetworkInterface(),
|
||||||
//"azurerm_network_security_group": resourceArmNetworkSecurityGroup(),
|
//"azurerm_network_security_group": resourceArmNetworkSecurityGroup(),
|
||||||
//"azurerm_network_security_rule": resourceArmNetworkSecurityRule(),
|
//"azurerm_network_security_rule": resourceArmNetworkSecurityRule(),
|
||||||
//"azurerm_public_ip": resourceArmPublicIp(),
|
"azurerm_public_ip": resourceArmPublicIp(),
|
||||||
//"azurerm_route": resourceArmRoute(),
|
//"azurerm_route": resourceArmRoute(),
|
||||||
//"azurerm_route_table": resourceArmRouteTable(),
|
//"azurerm_route_table": resourceArmRouteTable(),
|
||||||
//"azurerm_storage_account": resourceArmStorageAccount(),
|
//"azurerm_storage_account": resourceArmStorageAccount(),
|
||||||
|
|
|
@ -1,251 +1,234 @@
|
||||||
package azurerm
|
package azurerm
|
||||||
|
|
||||||
//import (
|
import (
|
||||||
// "fmt"
|
"fmt"
|
||||||
// "log"
|
"log"
|
||||||
// "net/http"
|
"net/http"
|
||||||
// "regexp"
|
"regexp"
|
||||||
// "strings"
|
"strings"
|
||||||
// "time"
|
|
||||||
//
|
"github.com/Azure/azure-sdk-for-go/arm/network"
|
||||||
// "github.com/Azure/azure-sdk-for-go/arm/network"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
// "github.com/hashicorp/terraform/helper/resource"
|
)
|
||||||
// "github.com/hashicorp/terraform/helper/schema"
|
|
||||||
//)
|
func resourceArmPublicIp() *schema.Resource {
|
||||||
//
|
return &schema.Resource{
|
||||||
//func resourceArmPublicIp() *schema.Resource {
|
Create: resourceArmPublicIpCreate,
|
||||||
// return &schema.Resource{
|
Read: resourceArmPublicIpRead,
|
||||||
// Create: resourceArmPublicIpCreate,
|
Update: resourceArmPublicIpCreate,
|
||||||
// Read: resourceArmPublicIpRead,
|
Delete: resourceArmPublicIpDelete,
|
||||||
// Update: resourceArmPublicIpCreate,
|
|
||||||
// Delete: resourceArmPublicIpDelete,
|
Schema: map[string]*schema.Schema{
|
||||||
//
|
"name": {
|
||||||
// Schema: map[string]*schema.Schema{
|
Type: schema.TypeString,
|
||||||
// "name": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
ForceNew: true,
|
||||||
// Required: true,
|
},
|
||||||
// ForceNew: true,
|
|
||||||
// },
|
"location": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "location": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
ForceNew: true,
|
||||||
// Required: true,
|
StateFunc: azureRMNormalizeLocation,
|
||||||
// ForceNew: true,
|
},
|
||||||
// StateFunc: azureRMNormalizeLocation,
|
|
||||||
// },
|
"resource_group_name": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "resource_group_name": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
ForceNew: true,
|
||||||
// Required: true,
|
},
|
||||||
// ForceNew: true,
|
|
||||||
// },
|
"public_ip_address_allocation": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "public_ip_address_allocation": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
ValidateFunc: validatePublicIpAllocation,
|
||||||
// Required: true,
|
},
|
||||||
// ValidateFunc: validatePublicIpAllocation,
|
|
||||||
// },
|
"idle_timeout_in_minutes": {
|
||||||
//
|
Type: schema.TypeInt,
|
||||||
// "idle_timeout_in_minutes": &schema.Schema{
|
Optional: true,
|
||||||
// Type: schema.TypeInt,
|
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
|
||||||
// Optional: true,
|
value := v.(int)
|
||||||
// ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
|
if value < 4 || value > 30 {
|
||||||
// value := v.(int)
|
errors = append(errors, fmt.Errorf(
|
||||||
// if value < 4 || value > 30 {
|
"The idle timeout must be between 4 and 30 minutes"))
|
||||||
// errors = append(errors, fmt.Errorf(
|
}
|
||||||
// "The idle timeout must be between 4 and 30 minutes"))
|
return
|
||||||
// }
|
},
|
||||||
// return
|
},
|
||||||
// },
|
|
||||||
// },
|
"domain_name_label": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "domain_name_label": &schema.Schema{
|
Optional: true,
|
||||||
// Type: schema.TypeString,
|
ValidateFunc: validatePublicIpDomainNameLabel,
|
||||||
// Optional: true,
|
},
|
||||||
// ValidateFunc: validatePublicIpDomainNameLabel,
|
|
||||||
// },
|
"reverse_fqdn": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "reverse_fqdn": &schema.Schema{
|
Optional: true,
|
||||||
// Type: schema.TypeString,
|
},
|
||||||
// Optional: true,
|
|
||||||
// },
|
"fqdn": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "fqdn": &schema.Schema{
|
Computed: true,
|
||||||
// Type: schema.TypeString,
|
},
|
||||||
// Computed: true,
|
|
||||||
// },
|
"ip_address": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "ip_address": &schema.Schema{
|
Computed: true,
|
||||||
// Type: schema.TypeString,
|
},
|
||||||
// Computed: true,
|
|
||||||
// },
|
"tags": tagsSchema(),
|
||||||
//
|
},
|
||||||
// "tags": tagsSchema(),
|
}
|
||||||
// },
|
}
|
||||||
// }
|
|
||||||
//}
|
func resourceArmPublicIpCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
//
|
client := meta.(*ArmClient)
|
||||||
//func resourceArmPublicIpCreate(d *schema.ResourceData, meta interface{}) error {
|
publicIPClient := client.publicIPClient
|
||||||
// client := meta.(*ArmClient)
|
|
||||||
// publicIPClient := client.publicIPClient
|
log.Printf("[INFO] preparing arguments for Azure ARM Public IP creation.")
|
||||||
//
|
|
||||||
// log.Printf("[INFO] preparing arguments for Azure ARM Public IP creation.")
|
name := d.Get("name").(string)
|
||||||
//
|
location := d.Get("location").(string)
|
||||||
// name := d.Get("name").(string)
|
resGroup := d.Get("resource_group_name").(string)
|
||||||
// location := d.Get("location").(string)
|
tags := d.Get("tags").(map[string]interface{})
|
||||||
// resGroup := d.Get("resource_group_name").(string)
|
|
||||||
// tags := d.Get("tags").(map[string]interface{})
|
properties := network.PublicIPAddressPropertiesFormat{
|
||||||
//
|
PublicIPAllocationMethod: network.IPAllocationMethod(d.Get("public_ip_address_allocation").(string)),
|
||||||
// properties := network.PublicIPAddressPropertiesFormat{
|
}
|
||||||
// PublicIPAllocationMethod: network.IPAllocationMethod(d.Get("public_ip_address_allocation").(string)),
|
|
||||||
// }
|
dnl, hasDnl := d.GetOk("domain_name_label")
|
||||||
//
|
rfqdn, hasRfqdn := d.GetOk("reverse_fqdn")
|
||||||
// dnl, hasDnl := d.GetOk("domain_name_label")
|
|
||||||
// rfqdn, hasRfqdn := d.GetOk("reverse_fqdn")
|
if hasDnl || hasRfqdn {
|
||||||
//
|
dnsSettings := network.PublicIPAddressDNSSettings{}
|
||||||
// if hasDnl || hasRfqdn {
|
|
||||||
// dnsSettings := network.PublicIPAddressDNSSettings{}
|
if hasRfqdn {
|
||||||
//
|
reverse_fqdn := rfqdn.(string)
|
||||||
// if hasRfqdn {
|
dnsSettings.ReverseFqdn = &reverse_fqdn
|
||||||
// reverse_fqdn := rfqdn.(string)
|
}
|
||||||
// dnsSettings.ReverseFqdn = &reverse_fqdn
|
|
||||||
// }
|
if hasDnl {
|
||||||
//
|
domain_name_label := dnl.(string)
|
||||||
// if hasDnl {
|
dnsSettings.DomainNameLabel = &domain_name_label
|
||||||
// domain_name_label := dnl.(string)
|
|
||||||
// dnsSettings.DomainNameLabel = &domain_name_label
|
}
|
||||||
//
|
|
||||||
// }
|
properties.DNSSettings = &dnsSettings
|
||||||
//
|
}
|
||||||
// properties.DNSSettings = &dnsSettings
|
|
||||||
// }
|
if v, ok := d.GetOk("idle_timeout_in_minutes"); ok {
|
||||||
//
|
idle_timeout := v.(int32)
|
||||||
// if v, ok := d.GetOk("idle_timeout_in_minutes"); ok {
|
properties.IdleTimeoutInMinutes = &idle_timeout
|
||||||
// idle_timeout := v.(int)
|
}
|
||||||
// properties.IdleTimeoutInMinutes = &idle_timeout
|
|
||||||
// }
|
publicIp := network.PublicIPAddress{
|
||||||
//
|
Name: &name,
|
||||||
// publicIp := network.PublicIPAddress{
|
Location: &location,
|
||||||
// Name: &name,
|
Properties: &properties,
|
||||||
// Location: &location,
|
Tags: expandTags(tags),
|
||||||
// Properties: &properties,
|
}
|
||||||
// Tags: expandTags(tags),
|
|
||||||
// }
|
_, err := publicIPClient.CreateOrUpdate(resGroup, name, publicIp, make(chan struct{}))
|
||||||
//
|
if err != nil {
|
||||||
// resp, err := publicIPClient.CreateOrUpdate(resGroup, name, publicIp)
|
return err
|
||||||
// if err != nil {
|
}
|
||||||
// return err
|
|
||||||
// }
|
read, err := publicIPClient.Get(resGroup, name, "")
|
||||||
//
|
if err != nil {
|
||||||
// d.SetId(*resp.ID)
|
return err
|
||||||
//
|
}
|
||||||
// log.Printf("[DEBUG] Waiting for Public IP (%s) to become available", name)
|
if read.ID == nil {
|
||||||
// stateConf := &resource.StateChangeConf{
|
return fmt.Errorf("Cannot read Public IP %s (resource group %s) ID", name, resGroup)
|
||||||
// Pending: []string{"Accepted", "Updating"},
|
}
|
||||||
// Target: []string{"Succeeded"},
|
|
||||||
// Refresh: publicIPStateRefreshFunc(client, resGroup, name),
|
d.SetId(*read.ID)
|
||||||
// Timeout: 10 * time.Minute,
|
|
||||||
// }
|
return resourceArmPublicIpRead(d, meta)
|
||||||
// if _, err := stateConf.WaitForState(); err != nil {
|
}
|
||||||
// return fmt.Errorf("Error waiting for Public IP (%s) to become available: %s", name, err)
|
|
||||||
// }
|
func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
//
|
publicIPClient := meta.(*ArmClient).publicIPClient
|
||||||
// return resourceArmPublicIpRead(d, meta)
|
|
||||||
//}
|
id, err := parseAzureResourceID(d.Id())
|
||||||
//
|
if err != nil {
|
||||||
//func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error {
|
return err
|
||||||
// publicIPClient := meta.(*ArmClient).publicIPClient
|
}
|
||||||
//
|
resGroup := id.ResourceGroup
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
name := id.Path["publicIPAddresses"]
|
||||||
// if err != nil {
|
|
||||||
// return err
|
resp, err := publicIPClient.Get(resGroup, name, "")
|
||||||
// }
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
// resGroup := id.ResourceGroup
|
d.SetId("")
|
||||||
// name := id.Path["publicIPAddresses"]
|
return nil
|
||||||
//
|
}
|
||||||
// resp, err := publicIPClient.Get(resGroup, name, "")
|
if err != nil {
|
||||||
// if resp.StatusCode == http.StatusNotFound {
|
return fmt.Errorf("Error making Read request on Azure public ip %s: %s", name, err)
|
||||||
// d.SetId("")
|
}
|
||||||
// return nil
|
|
||||||
// }
|
if resp.Properties.DNSSettings != nil && resp.Properties.DNSSettings.Fqdn != nil && *resp.Properties.DNSSettings.Fqdn != "" {
|
||||||
// if err != nil {
|
d.Set("fqdn", resp.Properties.DNSSettings.Fqdn)
|
||||||
// return fmt.Errorf("Error making Read request on Azure public ip %s: %s", name, err)
|
}
|
||||||
// }
|
|
||||||
//
|
if resp.Properties.IPAddress != nil && *resp.Properties.IPAddress != "" {
|
||||||
// if resp.Properties.DNSSettings != nil && resp.Properties.DNSSettings.Fqdn != nil && *resp.Properties.DNSSettings.Fqdn != "" {
|
d.Set("ip_address", resp.Properties.IPAddress)
|
||||||
// d.Set("fqdn", resp.Properties.DNSSettings.Fqdn)
|
}
|
||||||
// }
|
|
||||||
//
|
flattenAndSetTags(d, resp.Tags)
|
||||||
// if resp.Properties.IPAddress != nil && *resp.Properties.IPAddress != "" {
|
|
||||||
// d.Set("ip_address", resp.Properties.IPAddress)
|
return nil
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// flattenAndSetTags(d, resp.Tags)
|
func resourceArmPublicIpDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
//
|
publicIPClient := meta.(*ArmClient).publicIPClient
|
||||||
// return nil
|
|
||||||
//}
|
id, err := parseAzureResourceID(d.Id())
|
||||||
//
|
if err != nil {
|
||||||
//func resourceArmPublicIpDelete(d *schema.ResourceData, meta interface{}) error {
|
return err
|
||||||
// publicIPClient := meta.(*ArmClient).publicIPClient
|
}
|
||||||
//
|
resGroup := id.ResourceGroup
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
name := id.Path["publicIPAddresses"]
|
||||||
// if err != nil {
|
|
||||||
// return err
|
_, err = publicIPClient.Delete(resGroup, name, make(chan struct{}))
|
||||||
// }
|
|
||||||
// resGroup := id.ResourceGroup
|
return err
|
||||||
// name := id.Path["publicIPAddresses"]
|
}
|
||||||
//
|
|
||||||
// _, err = publicIPClient.Delete(resGroup, name)
|
func validatePublicIpAllocation(v interface{}, k string) (ws []string, errors []error) {
|
||||||
//
|
value := strings.ToLower(v.(string))
|
||||||
// return err
|
allocations := map[string]bool{
|
||||||
//}
|
"static": true,
|
||||||
//
|
"dynamic": true,
|
||||||
//func publicIPStateRefreshFunc(client *ArmClient, resourceGroupName string, publicIpName string) resource.StateRefreshFunc {
|
}
|
||||||
// return func() (interface{}, string, error) {
|
|
||||||
// res, err := client.publicIPClient.Get(resourceGroupName, publicIpName, "")
|
if !allocations[value] {
|
||||||
// if err != nil {
|
errors = append(errors, fmt.Errorf("Public IP Allocation can only be Static of Dynamic"))
|
||||||
// return nil, "", fmt.Errorf("Error issuing read request in publicIPStateRefreshFunc to Azure ARM for public ip '%s' (RG: '%s'): %s", publicIpName, resourceGroupName, err)
|
}
|
||||||
// }
|
return
|
||||||
//
|
}
|
||||||
// return res, *res.Properties.ProvisioningState, nil
|
|
||||||
// }
|
func validatePublicIpDomainNameLabel(v interface{}, k string) (ws []string, errors []error) {
|
||||||
//}
|
value := v.(string)
|
||||||
//
|
if !regexp.MustCompile(`^[a-z0-9-]+$`).MatchString(value) {
|
||||||
//func validatePublicIpAllocation(v interface{}, k string) (ws []string, errors []error) {
|
errors = append(errors, fmt.Errorf(
|
||||||
// value := strings.ToLower(v.(string))
|
"only alphanumeric characters and hyphens allowed in %q: %q",
|
||||||
// allocations := map[string]bool{
|
k, value))
|
||||||
// "static": true,
|
}
|
||||||
// "dynamic": true,
|
|
||||||
// }
|
if len(value) > 61 {
|
||||||
//
|
errors = append(errors, fmt.Errorf(
|
||||||
// if !allocations[value] {
|
"%q cannot be longer than 61 characters: %q", k, value))
|
||||||
// errors = append(errors, fmt.Errorf("Public IP Allocation can only be Static of Dynamic"))
|
}
|
||||||
// }
|
|
||||||
// return
|
if len(value) == 0 {
|
||||||
//}
|
errors = append(errors, fmt.Errorf(
|
||||||
//
|
"%q cannot be an empty string: %q", k, value))
|
||||||
//func validatePublicIpDomainNameLabel(v interface{}, k string) (ws []string, errors []error) {
|
}
|
||||||
// value := v.(string)
|
if regexp.MustCompile(`-$`).MatchString(value) {
|
||||||
// if !regexp.MustCompile(`^[a-z0-9-]+$`).MatchString(value) {
|
errors = append(errors, fmt.Errorf(
|
||||||
// errors = append(errors, fmt.Errorf(
|
"%q cannot end with a hyphen: %q", k, value))
|
||||||
// "only alphanumeric characters and hyphens allowed in %q: %q",
|
}
|
||||||
// k, value))
|
|
||||||
// }
|
return
|
||||||
//
|
}
|
||||||
// if len(value) > 61 {
|
|
||||||
// errors = append(errors, fmt.Errorf(
|
|
||||||
// "%q cannot be longer than 61 characters: %q", k, value))
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if len(value) == 0 {
|
|
||||||
// errors = append(errors, fmt.Errorf(
|
|
||||||
// "%q cannot be an empty string: %q", k, value))
|
|
||||||
// }
|
|
||||||
// if regexp.MustCompile(`-$`).MatchString(value) {
|
|
||||||
// errors = append(errors, fmt.Errorf(
|
|
||||||
// "%q cannot end with a hyphen: %q", k, value))
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
|
|
|
@ -1,316 +1,316 @@
|
||||||
package azurerm
|
package azurerm
|
||||||
|
|
||||||
//import (
|
import (
|
||||||
// "fmt"
|
"fmt"
|
||||||
// "net/http"
|
"net/http"
|
||||||
// "testing"
|
"testing"
|
||||||
//
|
|
||||||
// "github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
// "github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
// "github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
//)
|
)
|
||||||
//
|
|
||||||
//func TestResourceAzureRMPublicIpAllocation_validation(t *testing.T) {
|
func TestResourceAzureRMPublicIpAllocation_validation(t *testing.T) {
|
||||||
// cases := []struct {
|
cases := []struct {
|
||||||
// Value string
|
Value string
|
||||||
// ErrCount int
|
ErrCount int
|
||||||
// }{
|
}{
|
||||||
// {
|
{
|
||||||
// Value: "Random",
|
Value: "Random",
|
||||||
// ErrCount: 1,
|
ErrCount: 1,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Value: "Static",
|
Value: "Static",
|
||||||
// ErrCount: 0,
|
ErrCount: 0,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Value: "Dynamic",
|
Value: "Dynamic",
|
||||||
// ErrCount: 0,
|
ErrCount: 0,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Value: "STATIC",
|
Value: "STATIC",
|
||||||
// ErrCount: 0,
|
ErrCount: 0,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Value: "static",
|
Value: "static",
|
||||||
// ErrCount: 0,
|
ErrCount: 0,
|
||||||
// },
|
},
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
// _, errors := validatePublicIpAllocation(tc.Value, "azurerm_public_ip")
|
_, errors := validatePublicIpAllocation(tc.Value, "azurerm_public_ip")
|
||||||
//
|
|
||||||
// if len(errors) != tc.ErrCount {
|
if len(errors) != tc.ErrCount {
|
||||||
// t.Fatalf("Expected the Azure RM Public IP allocation to trigger a validation error")
|
t.Fatalf("Expected the Azure RM Public IP allocation to trigger a validation error")
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func TestResourceAzureRMPublicIpDomainNameLabel_validation(t *testing.T) {
|
func TestResourceAzureRMPublicIpDomainNameLabel_validation(t *testing.T) {
|
||||||
// cases := []struct {
|
cases := []struct {
|
||||||
// Value string
|
Value string
|
||||||
// ErrCount int
|
ErrCount int
|
||||||
// }{
|
}{
|
||||||
// {
|
{
|
||||||
// Value: "tEsting123",
|
Value: "tEsting123",
|
||||||
// ErrCount: 1,
|
ErrCount: 1,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Value: "testing123!",
|
Value: "testing123!",
|
||||||
// ErrCount: 1,
|
ErrCount: 1,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Value: "testing123-",
|
Value: "testing123-",
|
||||||
// ErrCount: 1,
|
ErrCount: 1,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Value: acctest.RandString(80),
|
Value: acctest.RandString(80),
|
||||||
// ErrCount: 1,
|
ErrCount: 1,
|
||||||
// },
|
},
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
// _, errors := validatePublicIpDomainNameLabel(tc.Value, "azurerm_public_ip")
|
_, errors := validatePublicIpDomainNameLabel(tc.Value, "azurerm_public_ip")
|
||||||
//
|
|
||||||
// if len(errors) != tc.ErrCount {
|
if len(errors) != tc.ErrCount {
|
||||||
// t.Fatalf("Expected the Azure RM Public IP Domain Name Label to trigger a validation error")
|
t.Fatalf("Expected the Azure RM Public IP Domain Name Label to trigger a validation error")
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func TestAccAzureRMPublicIpStatic_basic(t *testing.T) {
|
func TestAccAzureRMPublicIpStatic_basic(t *testing.T) {
|
||||||
//
|
|
||||||
// ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
// config := fmt.Sprintf(testAccAzureRMVPublicIpStatic_basic, ri, ri)
|
config := fmt.Sprintf(testAccAzureRMVPublicIpStatic_basic, ri, ri)
|
||||||
//
|
|
||||||
// resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
// PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
// Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
// CheckDestroy: testCheckAzureRMPublicIpDestroy,
|
CheckDestroy: testCheckAzureRMPublicIpDestroy,
|
||||||
// Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
// resource.TestStep{
|
resource.TestStep{
|
||||||
// Config: config,
|
Config: config,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// })
|
})
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func TestAccAzureRMPublicIpStatic_withTags(t *testing.T) {
|
func TestAccAzureRMPublicIpStatic_withTags(t *testing.T) {
|
||||||
//
|
|
||||||
// ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
// preConfig := fmt.Sprintf(testAccAzureRMVPublicIpStatic_withTags, ri, ri)
|
preConfig := fmt.Sprintf(testAccAzureRMVPublicIpStatic_withTags, ri, ri)
|
||||||
// postConfig := fmt.Sprintf(testAccAzureRMVPublicIpStatic_withTagsUpdate, ri, ri)
|
postConfig := fmt.Sprintf(testAccAzureRMVPublicIpStatic_withTagsUpdate, ri, ri)
|
||||||
//
|
|
||||||
// resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
// PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
// Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
// CheckDestroy: testCheckAzureRMPublicIpDestroy,
|
CheckDestroy: testCheckAzureRMPublicIpDestroy,
|
||||||
// Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
// resource.TestStep{
|
resource.TestStep{
|
||||||
// Config: preConfig,
|
Config: preConfig,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_public_ip.test", "tags.#", "2"),
|
"azurerm_public_ip.test", "tags.#", "2"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_public_ip.test", "tags.environment", "Production"),
|
"azurerm_public_ip.test", "tags.environment", "Production"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_public_ip.test", "tags.cost_center", "MSFT"),
|
"azurerm_public_ip.test", "tags.cost_center", "MSFT"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// resource.TestStep{
|
resource.TestStep{
|
||||||
// Config: postConfig,
|
Config: postConfig,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_public_ip.test", "tags.#", "1"),
|
"azurerm_public_ip.test", "tags.#", "1"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_public_ip.test", "tags.environment", "staging"),
|
"azurerm_public_ip.test", "tags.environment", "staging"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// })
|
})
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func TestAccAzureRMPublicIpStatic_update(t *testing.T) {
|
func TestAccAzureRMPublicIpStatic_update(t *testing.T) {
|
||||||
//
|
|
||||||
// ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
// preConfig := fmt.Sprintf(testAccAzureRMVPublicIpStatic_basic, ri, ri)
|
preConfig := fmt.Sprintf(testAccAzureRMVPublicIpStatic_basic, ri, ri)
|
||||||
// postConfig := fmt.Sprintf(testAccAzureRMVPublicIpStatic_update, ri, ri)
|
postConfig := fmt.Sprintf(testAccAzureRMVPublicIpStatic_update, ri, ri)
|
||||||
//
|
|
||||||
// resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
// PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
// Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
// CheckDestroy: testCheckAzureRMPublicIpDestroy,
|
CheckDestroy: testCheckAzureRMPublicIpDestroy,
|
||||||
// Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
// resource.TestStep{
|
resource.TestStep{
|
||||||
// Config: preConfig,
|
Config: preConfig,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// resource.TestStep{
|
resource.TestStep{
|
||||||
// Config: postConfig,
|
Config: postConfig,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_public_ip.test", "domain_name_label", "mylabel01"),
|
"azurerm_public_ip.test", "domain_name_label", "mylabel01"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// })
|
})
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func TestAccAzureRMPublicIpDynamic_basic(t *testing.T) {
|
func TestAccAzureRMPublicIpDynamic_basic(t *testing.T) {
|
||||||
//
|
|
||||||
// ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
// config := fmt.Sprintf(testAccAzureRMVPublicIpDynamic_basic, ri, ri)
|
config := fmt.Sprintf(testAccAzureRMVPublicIpDynamic_basic, ri, ri)
|
||||||
//
|
|
||||||
// resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
// PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
// Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
// CheckDestroy: testCheckAzureRMPublicIpDestroy,
|
CheckDestroy: testCheckAzureRMPublicIpDestroy,
|
||||||
// Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
// resource.TestStep{
|
resource.TestStep{
|
||||||
// Config: config,
|
Config: config,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// })
|
})
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func testCheckAzureRMPublicIpExists(name string) resource.TestCheckFunc {
|
func testCheckAzureRMPublicIpExists(name string) resource.TestCheckFunc {
|
||||||
// return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
// // Ensure we have enough information in state to look up in API
|
// Ensure we have enough information in state to look up in API
|
||||||
// rs, ok := s.RootModule().Resources[name]
|
rs, ok := s.RootModule().Resources[name]
|
||||||
// if !ok {
|
if !ok {
|
||||||
// return fmt.Errorf("Not found: %s", name)
|
return fmt.Errorf("Not found: %s", name)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// availSetName := rs.Primary.Attributes["name"]
|
availSetName := rs.Primary.Attributes["name"]
|
||||||
// resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
// if !hasResourceGroup {
|
if !hasResourceGroup {
|
||||||
// return fmt.Errorf("Bad: no resource group found in state for public ip: %s", availSetName)
|
return fmt.Errorf("Bad: no resource group found in state for public ip: %s", availSetName)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// conn := testAccProvider.Meta().(*ArmClient).publicIPClient
|
conn := testAccProvider.Meta().(*ArmClient).publicIPClient
|
||||||
//
|
|
||||||
// resp, err := conn.Get(resourceGroup, availSetName, "")
|
resp, err := conn.Get(resourceGroup, availSetName, "")
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return fmt.Errorf("Bad: Get on publicIPClient: %s", err)
|
return fmt.Errorf("Bad: Get on publicIPClient: %s", err)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if resp.StatusCode == http.StatusNotFound {
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
// return fmt.Errorf("Bad: Public IP %q (resource group: %q) does not exist", name, resourceGroup)
|
return fmt.Errorf("Bad: Public IP %q (resource group: %q) does not exist", name, resourceGroup)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func testCheckAzureRMPublicIpDestroy(s *terraform.State) error {
|
func testCheckAzureRMPublicIpDestroy(s *terraform.State) error {
|
||||||
// conn := testAccProvider.Meta().(*ArmClient).publicIPClient
|
conn := testAccProvider.Meta().(*ArmClient).publicIPClient
|
||||||
//
|
|
||||||
// for _, rs := range s.RootModule().Resources {
|
for _, rs := range s.RootModule().Resources {
|
||||||
// if rs.Type != "azurerm_public_ip" {
|
if rs.Type != "azurerm_public_ip" {
|
||||||
// continue
|
continue
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// name := rs.Primary.Attributes["name"]
|
name := rs.Primary.Attributes["name"]
|
||||||
// resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
//
|
|
||||||
// resp, err := conn.Get(resourceGroup, name, "")
|
resp, err := conn.Get(resourceGroup, name, "")
|
||||||
//
|
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if resp.StatusCode != http.StatusNotFound {
|
if resp.StatusCode != http.StatusNotFound {
|
||||||
// return fmt.Errorf("Public IP still exists:\n%#v", resp.Properties)
|
return fmt.Errorf("Public IP still exists:\n%#v", resp.Properties)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return nil
|
return nil
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//var testAccAzureRMVPublicIpStatic_basic = `
|
var testAccAzureRMVPublicIpStatic_basic = `
|
||||||
//resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
// name = "acctestrg-%d"
|
name = "acctestrg-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
//}
|
}
|
||||||
//resource "azurerm_public_ip" "test" {
|
resource "azurerm_public_ip" "test" {
|
||||||
// name = "acctestpublicip-%d"
|
name = "acctestpublicip-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// public_ip_address_allocation = "static"
|
public_ip_address_allocation = "static"
|
||||||
//}
|
}
|
||||||
//`
|
`
|
||||||
//
|
|
||||||
//var testAccAzureRMVPublicIpStatic_update = `
|
var testAccAzureRMVPublicIpStatic_update = `
|
||||||
//resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
// name = "acctestrg-%d"
|
name = "acctestrg-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
//}
|
}
|
||||||
//resource "azurerm_public_ip" "test" {
|
resource "azurerm_public_ip" "test" {
|
||||||
// name = "acctestpublicip-%d"
|
name = "acctestpublicip-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// public_ip_address_allocation = "static"
|
public_ip_address_allocation = "static"
|
||||||
// domain_name_label = "mylabel01"
|
domain_name_label = "mylabel01"
|
||||||
//}
|
}
|
||||||
//`
|
`
|
||||||
//
|
|
||||||
//var testAccAzureRMVPublicIpDynamic_basic = `
|
var testAccAzureRMVPublicIpDynamic_basic = `
|
||||||
//resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
// name = "acctestrg-%d"
|
name = "acctestrg-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
//}
|
}
|
||||||
//resource "azurerm_public_ip" "test" {
|
resource "azurerm_public_ip" "test" {
|
||||||
// name = "acctestpublicip-%d"
|
name = "acctestpublicip-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// public_ip_address_allocation = "dynamic"
|
public_ip_address_allocation = "dynamic"
|
||||||
//}
|
}
|
||||||
//`
|
`
|
||||||
//
|
|
||||||
//var testAccAzureRMVPublicIpStatic_withTags = `
|
var testAccAzureRMVPublicIpStatic_withTags = `
|
||||||
//resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
// name = "acctestrg-%d"
|
name = "acctestrg-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
//}
|
}
|
||||||
//resource "azurerm_public_ip" "test" {
|
resource "azurerm_public_ip" "test" {
|
||||||
// name = "acctestpublicip-%d"
|
name = "acctestpublicip-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// public_ip_address_allocation = "static"
|
public_ip_address_allocation = "static"
|
||||||
//
|
|
||||||
// tags {
|
tags {
|
||||||
// environment = "Production"
|
environment = "Production"
|
||||||
// cost_center = "MSFT"
|
cost_center = "MSFT"
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//`
|
`
|
||||||
//
|
|
||||||
//var testAccAzureRMVPublicIpStatic_withTagsUpdate = `
|
var testAccAzureRMVPublicIpStatic_withTagsUpdate = `
|
||||||
//resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
// name = "acctestrg-%d"
|
name = "acctestrg-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
//}
|
}
|
||||||
//resource "azurerm_public_ip" "test" {
|
resource "azurerm_public_ip" "test" {
|
||||||
// name = "acctestpublicip-%d"
|
name = "acctestpublicip-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// public_ip_address_allocation = "static"
|
public_ip_address_allocation = "static"
|
||||||
//
|
|
||||||
// tags {
|
tags {
|
||||||
// environment = "staging"
|
environment = "staging"
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//`
|
`
|
||||||
|
|
Loading…
Reference in New Issue