mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-07 22:53:08 -06:00
cc18e4d7ca
* provider/azurerm: vendor arm/trafficmanager package * provider/azurerm: add azurerm_traffic_manager_profile resource * provider/azurerm: add azurerm_traffic_manager_endpoint resource * provider/azurerm: document traffic manager resources * provider/azurerm: use short type argument for traffic manager endpoint The resource now takes the short type for example azureEndpoints instead of the long form Microsoft.Network/TrafficManagerProfiles/azureEndpoints. ``` TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMTrafficManagerEndpoint -timeout 120m === RUN TestAccAzureRMTrafficManagerEndpoint_basic --- PASS: TestAccAzureRMTrafficManagerEndpoint_basic (179.72s) === RUN TestAccAzureRMTrafficManagerEndpoint_basicDisableExternal --- PASS: TestAccAzureRMTrafficManagerEndpoint_basicDisableExternal (171.36s) === RUN TestAccAzureRMTrafficManagerEndpoint_updateWeight --- PASS: TestAccAzureRMTrafficManagerEndpoint_updateWeight (167.24s) === RUN TestAccAzureRMTrafficManagerEndpoint_updatePriority --- PASS: TestAccAzureRMTrafficManagerEndpoint_updatePriority (192.91s) === RUN TestAccAzureRMTrafficManagerEndpoint_nestedEndpoints --- PASS: TestAccAzureRMTrafficManagerEndpoint_nestedEndpoints (111.18s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 822.534s ``` * provider/azurerm: remove unnecesary dereferences in traffic manager resources ``` TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMTrafficManager -timeout 120m === RUN TestAccAzureRMTrafficManagerEndpoint_basic --- PASS: TestAccAzureRMTrafficManagerEndpoint_basic (176.08s) === RUN TestAccAzureRMTrafficManagerEndpoint_basicDisableExternal --- PASS: TestAccAzureRMTrafficManagerEndpoint_basicDisableExternal (172.28s) === RUN TestAccAzureRMTrafficManagerEndpoint_updateWeight --- PASS: TestAccAzureRMTrafficManagerEndpoint_updateWeight (148.97s) === RUN TestAccAzureRMTrafficManagerEndpoint_updatePriority --- PASS: TestAccAzureRMTrafficManagerEndpoint_updatePriority (101.18s) === RUN TestAccAzureRMTrafficManagerEndpoint_nestedEndpoints --- PASS: TestAccAzureRMTrafficManagerEndpoint_nestedEndpoints (88.33s) === RUN TestAccAzureRMTrafficManagerProfile_weighted --- PASS: TestAccAzureRMTrafficManagerProfile_weighted (80.92s) === RUN TestAccAzureRMTrafficManagerProfile_performance --- PASS: TestAccAzureRMTrafficManagerProfile_performance (82.98s) === RUN TestAccAzureRMTrafficManagerProfile_priority --- PASS: TestAccAzureRMTrafficManagerProfile_priority (81.07s) === RUN TestAccAzureRMTrafficManagerProfile_withTags --- PASS: TestAccAzureRMTrafficManagerProfile_withTags (102.50s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 1034.458s ```
304 lines
8.4 KiB
Go
304 lines
8.4 KiB
Go
package azurerm
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"testing"
|
|
|
|
"github.com/Azure/azure-sdk-for-go/core/http"
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccAzureRMTrafficManagerProfile_weighted(t *testing.T) {
|
|
ri := acctest.RandInt()
|
|
config := fmt.Sprintf(testAccAzureRMTrafficManagerProfile_weighted, ri, ri, ri)
|
|
|
|
fqdn := fmt.Sprintf("acctesttmp%d.trafficmanager.net", ri)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: config,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testCheckAzureRMTrafficManagerProfileExists("azurerm_traffic_manager_profile.test"),
|
|
resource.TestCheckResourceAttr("azurerm_traffic_manager_profile.test", "traffic_routing_method", "Weighted"),
|
|
resource.TestCheckResourceAttr("azurerm_traffic_manager_profile.test", "fqdn", fqdn),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAzureRMTrafficManagerProfile_performance(t *testing.T) {
|
|
ri := acctest.RandInt()
|
|
config := fmt.Sprintf(testAccAzureRMTrafficManagerProfile_performance, ri, ri, ri)
|
|
|
|
fqdn := fmt.Sprintf("acctesttmp%d.trafficmanager.net", ri)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: config,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testCheckAzureRMTrafficManagerProfileExists("azurerm_traffic_manager_profile.test"),
|
|
resource.TestCheckResourceAttr("azurerm_traffic_manager_profile.test", "traffic_routing_method", "Performance"),
|
|
resource.TestCheckResourceAttr("azurerm_traffic_manager_profile.test", "fqdn", fqdn),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAzureRMTrafficManagerProfile_priority(t *testing.T) {
|
|
ri := acctest.RandInt()
|
|
config := fmt.Sprintf(testAccAzureRMTrafficManagerProfile_priority, ri, ri, ri)
|
|
|
|
fqdn := fmt.Sprintf("acctesttmp%d.trafficmanager.net", ri)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: config,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testCheckAzureRMTrafficManagerProfileExists("azurerm_traffic_manager_profile.test"),
|
|
resource.TestCheckResourceAttr("azurerm_traffic_manager_profile.test", "traffic_routing_method", "Priority"),
|
|
resource.TestCheckResourceAttr("azurerm_traffic_manager_profile.test", "fqdn", fqdn),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAzureRMTrafficManagerProfile_withTags(t *testing.T) {
|
|
ri := acctest.RandInt()
|
|
preConfig := fmt.Sprintf(testAccAzureRMTrafficManagerProfile_withTags, ri, ri, ri)
|
|
postConfig := fmt.Sprintf(testAccAzureRMTrafficManagerProfile_withTagsUpdated, ri, ri, ri)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: preConfig,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testCheckAzureRMTrafficManagerProfileExists("azurerm_traffic_manager_profile.test"),
|
|
resource.TestCheckResourceAttr(
|
|
"azurerm_traffic_manager_profile.test", "tags.%", "2"),
|
|
resource.TestCheckResourceAttr(
|
|
"azurerm_traffic_manager_profile.test", "tags.environment", "Production"),
|
|
resource.TestCheckResourceAttr(
|
|
"azurerm_traffic_manager_profile.test", "tags.cost_center", "MSFT"),
|
|
),
|
|
},
|
|
|
|
resource.TestStep{
|
|
Config: postConfig,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testCheckAzureRMTrafficManagerProfileExists("azurerm_traffic_manager_profile.test"),
|
|
resource.TestCheckResourceAttr(
|
|
"azurerm_traffic_manager_profile.test", "tags.%", "1"),
|
|
resource.TestCheckResourceAttr(
|
|
"azurerm_traffic_manager_profile.test", "tags.environment", "staging"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testCheckAzureRMTrafficManagerProfileExists(name string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
// Ensure we have enough information in state to look up in API
|
|
rs, ok := s.RootModule().Resources[name]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", name)
|
|
}
|
|
|
|
name := rs.Primary.Attributes["name"]
|
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
|
if !hasResourceGroup {
|
|
return fmt.Errorf("Bad: no resource group found in state for Traffic Manager Profile: %s", name)
|
|
}
|
|
|
|
// Ensure resource group/virtual network combination exists in API
|
|
conn := testAccProvider.Meta().(*ArmClient).trafficManagerProfilesClient
|
|
|
|
resp, err := conn.Get(resourceGroup, name)
|
|
if err != nil {
|
|
return fmt.Errorf("Bad: Get on trafficManagerProfilesClient: %s", err)
|
|
}
|
|
|
|
if resp.StatusCode == http.StatusNotFound {
|
|
return fmt.Errorf("Bad: Traffic Manager %q (resource group: %q) does not exist", name, resourceGroup)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testCheckAzureRMTrafficManagerProfileDestroy(s *terraform.State) error {
|
|
conn := testAccProvider.Meta().(*ArmClient).trafficManagerProfilesClient
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "azurerm_traffic_manager_profile" {
|
|
continue
|
|
}
|
|
|
|
log.Printf("[TRACE] test_profile %#v", rs)
|
|
|
|
name := rs.Primary.Attributes["name"]
|
|
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
|
|
|
resp, err := conn.Get(resourceGroup, name)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
if resp.StatusCode != http.StatusNotFound {
|
|
return fmt.Errorf("Traffic Manager profile sitll exists:\n%#v", resp.Properties)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var testAccAzureRMTrafficManagerProfile_weighted = `
|
|
resource "azurerm_resource_group" "test" {
|
|
name = "acctestrg-%d"
|
|
location = "West US"
|
|
}
|
|
|
|
resource "azurerm_traffic_manager_profile" "test" {
|
|
name = "acctesttmp%d"
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
traffic_routing_method = "Weighted"
|
|
|
|
dns_config {
|
|
relative_name = "acctesttmp%d"
|
|
ttl = 30
|
|
}
|
|
|
|
monitor_config {
|
|
protocol = "https"
|
|
port = 443
|
|
path = "/"
|
|
}
|
|
}
|
|
`
|
|
|
|
var testAccAzureRMTrafficManagerProfile_performance = `
|
|
resource "azurerm_resource_group" "test" {
|
|
name = "acctestrg-%d"
|
|
location = "West US"
|
|
}
|
|
|
|
resource "azurerm_traffic_manager_profile" "test" {
|
|
name = "acctesttmp%d"
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
traffic_routing_method = "Performance"
|
|
|
|
dns_config {
|
|
relative_name = "acctesttmp%d"
|
|
ttl = 30
|
|
}
|
|
|
|
monitor_config {
|
|
protocol = "https"
|
|
port = 443
|
|
path = "/"
|
|
}
|
|
}
|
|
`
|
|
|
|
var testAccAzureRMTrafficManagerProfile_priority = `
|
|
resource "azurerm_resource_group" "test" {
|
|
name = "acctestrg-%d"
|
|
location = "West US"
|
|
}
|
|
|
|
resource "azurerm_traffic_manager_profile" "test" {
|
|
name = "acctesttmp%d"
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
traffic_routing_method = "Priority"
|
|
|
|
dns_config {
|
|
relative_name = "acctesttmp%d"
|
|
ttl = 30
|
|
}
|
|
|
|
monitor_config {
|
|
protocol = "https"
|
|
port = 443
|
|
path = "/"
|
|
}
|
|
}
|
|
`
|
|
|
|
var testAccAzureRMTrafficManagerProfile_withTags = `
|
|
resource "azurerm_resource_group" "test" {
|
|
name = "acctestrg-%d"
|
|
location = "West US"
|
|
}
|
|
|
|
resource "azurerm_traffic_manager_profile" "test" {
|
|
name = "acctesttmp%d"
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
traffic_routing_method = "Priority"
|
|
|
|
dns_config {
|
|
relative_name = "acctesttmp%d"
|
|
ttl = 30
|
|
}
|
|
|
|
monitor_config {
|
|
protocol = "https"
|
|
port = 443
|
|
path = "/"
|
|
}
|
|
|
|
tags {
|
|
environment = "Production"
|
|
cost_center = "MSFT"
|
|
}
|
|
}
|
|
`
|
|
|
|
var testAccAzureRMTrafficManagerProfile_withTagsUpdated = `
|
|
resource "azurerm_resource_group" "test" {
|
|
name = "acctestrg-%d"
|
|
location = "West US"
|
|
}
|
|
|
|
resource "azurerm_traffic_manager_profile" "test" {
|
|
name = "acctesttmp%d"
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
traffic_routing_method = "Priority"
|
|
|
|
dns_config {
|
|
relative_name = "acctesttmp%d"
|
|
ttl = 30
|
|
}
|
|
|
|
monitor_config {
|
|
protocol = "https"
|
|
port = 443
|
|
path = "/"
|
|
}
|
|
|
|
tags {
|
|
environment = "staging"
|
|
}
|
|
}
|
|
`
|