diff --git a/builtin/providers/azurerm/import_arm_public_ip_test.go b/builtin/providers/azurerm/import_arm_public_ip_test.go new file mode 100644 index 000000000..f911aa309 --- /dev/null +++ b/builtin/providers/azurerm/import_arm_public_ip_test.go @@ -0,0 +1,34 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAzureRMPublicIpStatic_importBasic(t *testing.T) { + resourceName := "azurerm_public_ip.test" + + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMVPublicIpStatic_basic, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMPublicIpDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"resource_group_name"}, + }, + }, + }) +} diff --git a/builtin/providers/azurerm/resource_arm_public_ip.go b/builtin/providers/azurerm/resource_arm_public_ip.go index bde231e3d..2f94add62 100644 --- a/builtin/providers/azurerm/resource_arm_public_ip.go +++ b/builtin/providers/azurerm/resource_arm_public_ip.go @@ -17,6 +17,9 @@ func resourceArmPublicIp() *schema.Resource { Read: resourceArmPublicIpRead, Update: resourceArmPublicIpCreate, Delete: resourceArmPublicIpDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "name": { @@ -42,6 +45,9 @@ func resourceArmPublicIp() *schema.Resource { Type: schema.TypeString, Required: true, ValidateFunc: validatePublicIpAllocation, + StateFunc: func(val interface{}) string { + return strings.ToLower(val.(string)) + }, }, "idle_timeout_in_minutes": { @@ -167,6 +173,10 @@ func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error making Read request on Azure public ip %s: %s", name, err) } + d.Set("location", resp.Location) + d.Set("name", resp.Name) + d.Set("public_ip_address_allocation", strings.ToLower(string(resp.Properties.PublicIPAllocationMethod))) + if resp.Properties.DNSSettings != nil && resp.Properties.DNSSettings.Fqdn != nil && *resp.Properties.DNSSettings.Fqdn != "" { d.Set("fqdn", resp.Properties.DNSSettings.Fqdn) }