Skip to content

Commit

Permalink
Merge pull request #320 from terraform-providers/b-import-public-ip
Browse files Browse the repository at this point in the history
Add test for mistyped id
  • Loading branch information
mbfrahry authored Sep 11, 2017
2 parents 2a04247 + e1af078 commit d48b02a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
27 changes: 27 additions & 0 deletions azurerm/import_arm_public_ip_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package azurerm

import (
"fmt"
"os"
"regexp"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
Expand Down Expand Up @@ -29,3 +32,27 @@ func TestAccAzureRMPublicIpStatic_importBasic(t *testing.T) {
},
})
}

func TestAccAzureRMPublicIpStatic_importIdError(t *testing.T) {
resourceName := "azurerm_public_ip.test"

ri := acctest.RandInt()
config := testAccAzureRMPublicIPStatic_basic(ri, testLocation())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMPublicIpDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateId: fmt.Sprintf("/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/publicIPAdresses/acctestpublicip-%d", os.Getenv("ARM_SUBSCRIPTION_ID"), ri, ri),
ExpectError: regexp.MustCompile("Error parsing supplied resource id."),
},
},
})
}
12 changes: 11 additions & 1 deletion azurerm/resource_arm_public_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ func resourceArmPublicIp() *schema.Resource {
Update: resourceArmPublicIpCreate,
Delete: resourceArmPublicIpDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
id, err := parseAzureResourceID(d.Id())
if err != nil {
return nil, err
}
name := id.Path["publicIPAddresses"]
if name == "" {
return nil, fmt.Errorf("Error parsing supplied resource id. Please check it and rerun:\n %s", d.Id())
}
return []*schema.ResourceData{d}, nil
},
},

Schema: map[string]*schema.Schema{
Expand Down

0 comments on commit d48b02a

Please sign in to comment.