Merge pull request #9306 from BedeGaming/azurerm-cdn-profile-id-fix

provider/azurerm: fix cdn_profile ID parsing, add import capability
This commit is contained in:
James Nugent 2016-10-10 20:33:50 -04:00 committed by GitHub
commit 51c4f8665f
2 changed files with 42 additions and 2 deletions

View File

@ -0,0 +1,33 @@
package azurerm
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAzureRMCdnProfile_importWithTags(t *testing.T) {
resourceName := "azurerm_cdn_profile.test"
ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMCdnProfile_withTags, ri, ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMCdnProfileDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: config,
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

View File

@ -17,6 +17,9 @@ func resourceArmCdnProfile() *schema.Resource {
Read: resourceArmCdnProfileRead, Read: resourceArmCdnProfileRead,
Update: resourceArmCdnProfileUpdate, Update: resourceArmCdnProfileUpdate,
Delete: resourceArmCdnProfileDelete, Delete: resourceArmCdnProfileDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": { "name": {
@ -96,7 +99,7 @@ func resourceArmCdnProfileRead(d *schema.ResourceData, meta interface{}) error {
return err return err
} }
resGroup := id.ResourceGroup resGroup := id.ResourceGroup
name := id.Path["Profiles"] name := id.Path["profiles"]
resp, err := cdnProfilesClient.Get(name, resGroup) resp, err := cdnProfilesClient.Get(name, resGroup)
if err != nil { if err != nil {
@ -107,6 +110,10 @@ func resourceArmCdnProfileRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error making Read request on Azure CDN Profile %s: %s", name, err) return fmt.Errorf("Error making Read request on Azure CDN Profile %s: %s", name, err)
} }
d.Set("name", name)
d.Set("resource_group_name", resGroup)
d.Set("location", azureRMNormalizeLocation(*resp.Location))
if resp.Sku != nil { if resp.Sku != nil {
d.Set("sku", string(resp.Sku.Name)) d.Set("sku", string(resp.Sku.Name))
} }
@ -147,7 +154,7 @@ func resourceArmCdnProfileDelete(d *schema.ResourceData, meta interface{}) error
return err return err
} }
resGroup := id.ResourceGroup resGroup := id.ResourceGroup
name := id.Path["Profiles"] name := id.Path["profiles"]
_, err = cdnProfilesClient.DeleteIfExists(name, resGroup, make(chan struct{})) _, err = cdnProfilesClient.DeleteIfExists(name, resGroup, make(chan struct{}))