provider/azurerm: fix; add tests for importing traffic manager resources (#8111)

* provider/azurerm: add test for importing traffic manager profile resource

TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMTrafficManagerProfile_import -timeout 120m
=== RUN   TestAccAzureRMTrafficManagerProfile_importBasic
--- PASS: TestAccAzureRMTrafficManagerProfile_importBasic (84.50s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/azurerm	84.722s

* provider/azurerm: fix; add test for importing traffic_manager_endpoint resource

TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMTrafficManagerEndpoint -timeout 120m
=== RUN   TestAccAzureRMTrafficManagerEndpoint_importBasic
--- PASS: TestAccAzureRMTrafficManagerEndpoint_importBasic (130.66s)
=== RUN   TestAccAzureRMTrafficManagerEndpoint_basic
--- PASS: TestAccAzureRMTrafficManagerEndpoint_basic (152.87s)
=== RUN   TestAccAzureRMTrafficManagerEndpoint_basicDisableExternal
--- PASS: TestAccAzureRMTrafficManagerEndpoint_basicDisableExternal (151.55s)
=== RUN   TestAccAzureRMTrafficManagerEndpoint_updateWeight
--- PASS: TestAccAzureRMTrafficManagerEndpoint_updateWeight (199.33s)
=== RUN   TestAccAzureRMTrafficManagerEndpoint_updatePriority
--- PASS: TestAccAzureRMTrafficManagerEndpoint_updatePriority (113.15s)
=== RUN   TestAccAzureRMTrafficManagerEndpoint_nestedEndpoints
--- PASS: TestAccAzureRMTrafficManagerEndpoint_nestedEndpoints (97.05s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/azurerm	844.740s
This commit is contained in:
Peter McAtominey 2016-08-11 05:00:23 +01:00 committed by Paul Stack
parent 605dfada51
commit d7285d1b14
3 changed files with 82 additions and 1 deletions

View File

@ -0,0 +1,36 @@
package azurerm
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAzureRMTrafficManagerEndpoint_importBasic(t *testing.T) {
resourceName := "azurerm_traffic_manager_endpoint.testExternal"
ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMTrafficManagerEndpoint_basic, ri, ri, ri, ri, ri, ri, ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: config,
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"resource_group_name",
},
},
},
})
}

View File

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

View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net/http"
"regexp"
"github.com/Azure/azure-sdk-for-go/arm/trafficmanager"
"github.com/hashicorp/terraform/helper/schema"
@ -136,7 +137,15 @@ func resourceArmTrafficManagerEndpointRead(d *schema.ResourceData, meta interfac
return err
}
resGroup := id.ResourceGroup
endpointType := d.Get("type").(string)
// lookup endpointType in Azure ID path
var endpointType string
typeRegex := regexp.MustCompile("azureEndpoints|externalEndpoints|nestedEndpoints")
for k := range id.Path {
if typeRegex.MatchString(k) {
endpointType = k
}
}
profileName := id.Path["trafficManagerProfiles"]
// endpoint name is keyed by endpoint type in ARM ID
@ -153,6 +162,8 @@ func resourceArmTrafficManagerEndpointRead(d *schema.ResourceData, meta interfac
endpoint := *resp.Properties
d.Set("name", resp.Name)
d.Set("type", endpointType)
d.Set("profile_name", profileName)
d.Set("endpoint_status", endpoint.EndpointStatus)
d.Set("target_resource_id", endpoint.TargetResourceID)
d.Set("target", endpoint.Target)