Merge pull request #7578 from hashicorp/import-arm-publicip

provider/azurerm: Support Import for `azurerm_public_ip`
This commit is contained in:
James Nugent 2016-07-11 10:35:18 -06:00 committed by GitHub
commit 6cc2a52810
2 changed files with 44 additions and 0 deletions

View File

@ -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"},
},
},
})
}

View File

@ -17,6 +17,9 @@ func resourceArmPublicIp() *schema.Resource {
Read: resourceArmPublicIpRead, Read: resourceArmPublicIpRead,
Update: resourceArmPublicIpCreate, Update: resourceArmPublicIpCreate,
Delete: resourceArmPublicIpDelete, Delete: resourceArmPublicIpDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": { "name": {
@ -42,6 +45,9 @@ func resourceArmPublicIp() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ValidateFunc: validatePublicIpAllocation, ValidateFunc: validatePublicIpAllocation,
StateFunc: func(val interface{}) string {
return strings.ToLower(val.(string))
},
}, },
"idle_timeout_in_minutes": { "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) 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 != "" { if resp.Properties.DNSSettings != nil && resp.Properties.DNSSettings.Fqdn != nil && *resp.Properties.DNSSettings.Fqdn != "" {
d.Set("fqdn", resp.Properties.DNSSettings.Fqdn) d.Set("fqdn", resp.Properties.DNSSettings.Fqdn)
} }