From 60a5eda36ad6ae928c32989f870137156ad366ae Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Tue, 5 Nov 2019 10:55:56 -0600 Subject: [PATCH 01/20] Add HybridConnectionsClient --- azurerm/internal/services/relay/client.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/relay/client.go b/azurerm/internal/services/relay/client.go index 8b10bb708dbc..9f3046c85b3f 100644 --- a/azurerm/internal/services/relay/client.go +++ b/azurerm/internal/services/relay/client.go @@ -6,14 +6,18 @@ import ( ) type Client struct { - NamespacesClient *relay.NamespacesClient + NamespacesClient *relay.NamespacesClient + HybridConnectionsClient *relay.HybridConnectionsClient } func BuildClient(o *common.ClientOptions) *Client { NamespacesClient := relay.NewNamespacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + HybridConnectionsClient := relay.NewHybridConnectionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&NamespacesClient.Client, o.ResourceManagerAuthorizer) + o.ConfigureClient(&HybridConnectionsClient.Client, o.ResourceManagerAuthorizer) return &Client{ - NamespacesClient: &NamespacesClient, + NamespacesClient: &NamespacesClient, + HybridConnectionsClient: &HybridConnectionsClient, } } From 08776a172d31122a8af945e5e8abb33168faf92f Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Tue, 5 Nov 2019 11:01:36 -0600 Subject: [PATCH 02/20] Add placeholder for resource and test --- azurerm/resource_arm_relay_hybridconnection.go | 0 azurerm/resource_arm_relay_hybridconnection_test.go | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 azurerm/resource_arm_relay_hybridconnection.go create mode 100644 azurerm/resource_arm_relay_hybridconnection_test.go diff --git a/azurerm/resource_arm_relay_hybridconnection.go b/azurerm/resource_arm_relay_hybridconnection.go new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/azurerm/resource_arm_relay_hybridconnection_test.go b/azurerm/resource_arm_relay_hybridconnection_test.go new file mode 100644 index 000000000000..e69de29bb2d1 From bf6f82102c1b4756c25d9aaa2e08e2a6ff909a06 Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Tue, 5 Nov 2019 12:06:13 -0600 Subject: [PATCH 03/20] Rename file for hybrid connection --- ...ybridconnection.go => resource_arm_relay_hybrid_connection.go} | 0 ...ction_test.go => resource_arm_relay_hybrid_connection_test.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename azurerm/{resource_arm_relay_hybridconnection.go => resource_arm_relay_hybrid_connection.go} (100%) rename azurerm/{resource_arm_relay_hybridconnection_test.go => resource_arm_relay_hybrid_connection_test.go} (100%) diff --git a/azurerm/resource_arm_relay_hybridconnection.go b/azurerm/resource_arm_relay_hybrid_connection.go similarity index 100% rename from azurerm/resource_arm_relay_hybridconnection.go rename to azurerm/resource_arm_relay_hybrid_connection.go diff --git a/azurerm/resource_arm_relay_hybridconnection_test.go b/azurerm/resource_arm_relay_hybrid_connection_test.go similarity index 100% rename from azurerm/resource_arm_relay_hybridconnection_test.go rename to azurerm/resource_arm_relay_hybrid_connection_test.go From d1545680f6f9e1b611bf1992fdbf663eefe57c49 Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Tue, 5 Nov 2019 13:02:18 -0600 Subject: [PATCH 04/20] Add unit test --- ...source_arm_relay_hybrid_connection_test.go | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/azurerm/resource_arm_relay_hybrid_connection_test.go b/azurerm/resource_arm_relay_hybrid_connection_test.go index e69de29bb2d1..5bc4f786f5a9 100644 --- a/azurerm/resource_arm_relay_hybrid_connection_test.go +++ b/azurerm/resource_arm_relay_hybrid_connection_test.go @@ -0,0 +1,155 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" +) + +func TestAccAzureRMHybridConnection_basic(t *testing.T) { + resourceName := "azurerm_relay_hybrid_connection.test" + ri := tf.AccRandTimeInt() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMHybridConnectionDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMHybridConnection_basic(ri, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMHybridConnectionExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "requires_client_authorization"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMHybridConnection_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + + resourceName := "azurerm_relay_hybrid_connection.test" + ri := tf.AccRandTimeInt() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMHybridConnectionDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMHybridConnection_basic(ri, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMHybridConnectionExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "metric_id"), + ), + }, + { + Config: testAccAzureRMHybridConnection_requiresImport(ri, testLocation()), + ExpectError: testRequiresImportError("azurerm_relay_hybrid_connection"), + }, + }, + }) +} + +func testAccAzureRMHybridConnection_basic(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_relay_namespace" "test" { + name = "acctestrn-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku_name = "Standard" +} + +resource "azurerm_relay_hybrid_connection" "test" { + name = "acctestrnhc-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + relay_namespace_name = "acctestrn-%d" + } +`, rInt, location, rInt, rInt, rInt) +} + +func testAccAzureRMHybridConnection_requiresImport(rInt int, location string) string { + return fmt.Sprintf(` +%s + +resource "azurerm_relay_namespace" "import" { + name = "acctestrnhc-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + relay_namespace_name = "acctestrn-%d" +} +`, testAccAzureRMHybridConnection_basic(rInt, location)) +} + +func testCheckAzureRMHybridConnectionExists(resourceName 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[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + resourceGroup := rs.Primary.Attributes["resource_group_name"] + relayNamespace := rs.Primary.Attributes["relay_namespace_name"] + name := rs.Primary.Attributes["name"] + + // Ensure resource group exists in API + client := testAccProvider.Meta().(*ArmClient).Relay.HybridConnectionsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + resp, err := client.Get(ctx, resourceGroup, relayNamespace, name) + if err != nil { + return fmt.Errorf("Bad: Get on relayHybridConnectionsClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Relay Hybrid Connection %q in Namespace %q (Resource Group: %q) does not exist", name, relayNamespace, resourceGroup) + } + + return nil + } +} + +func testCheckAzureRMHybridConnectionDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).Relay.HybridConnectionsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_relay_hybrid_connection" { + continue + } + + resourceGroup := rs.Primary.Attributes["resource_group_name"] + relayNamespace := rs.Primary.Attributes["relay_namespace_name"] + name := rs.Primary.Attributes["name"] + + resp, err := client.Get(ctx, resourceGroup, relayNamespace, name) + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Relay Hybrid Connection still exists:\n%#v", resp) + } + } + + return nil +} From d6fa441114c95df5e6ecdce9a238ac27884a52fa Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Tue, 5 Nov 2019 14:58:00 -0600 Subject: [PATCH 05/20] Fix testcase and import --- azurerm/resource_arm_relay_hybrid_connection_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_relay_hybrid_connection_test.go b/azurerm/resource_arm_relay_hybrid_connection_test.go index 5bc4f786f5a9..d67ff245af82 100644 --- a/azurerm/resource_arm_relay_hybrid_connection_test.go +++ b/azurerm/resource_arm_relay_hybrid_connection_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMHybridConnection_basic(t *testing.T) { @@ -96,7 +97,7 @@ resource "azurerm_relay_namespace" "import" { resource_group_name = "${azurerm_resource_group.test.name}" relay_namespace_name = "acctestrn-%d" } -`, testAccAzureRMHybridConnection_basic(rInt, location)) +`, testAccAzureRMHybridConnection_basic(rInt, location), rInt, rInt) } func testCheckAzureRMHybridConnectionExists(resourceName string) resource.TestCheckFunc { From 360a96ff18c0722cfde15fcd212c4f376a912b7d Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Tue, 5 Nov 2019 14:58:48 -0600 Subject: [PATCH 06/20] Add Relay Hybrid Connection support --- .../resource_arm_relay_hybrid_connection.go | 184 ++++++++++++++++++ 1 file changed, 184 insertions(+) diff --git a/azurerm/resource_arm_relay_hybrid_connection.go b/azurerm/resource_arm_relay_hybrid_connection.go index e69de29bb2d1..e9007c92fc3b 100644 --- a/azurerm/resource_arm_relay_hybrid_connection.go +++ b/azurerm/resource_arm_relay_hybrid_connection.go @@ -0,0 +1,184 @@ +package azurerm + +import ( + "context" + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/relay/mgmt/2017-04-01/relay" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmHybridConnection() *schema.Resource { + return &schema.Resource{ + Create: resourceArmHybridConnectionCreateUpdate, + Read: resourceArmHybridConnectionRead, + Update: resourceArmHybridConnectionCreateUpdate, + Delete: resourceArmHybridConnectionDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(6, 50), + }, + + "relay_namespace_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "resource_group_name": azure.SchemaResourceGroupName(), + + "requires_client_authorization": { + Type: schema.TypeBool, + Optional: true, + }, + }, + } +} + +func resourceArmHybridConnectionCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).Relay.HybridConnectionsClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*ArmClient).StopContext, d) + defer cancel() + + log.Printf("[INFO] preparing arguments for Relay Hybrid Connection creation.") + + name := d.Get("name").(string) + relayNamespace := d.Get("relay_namespace_name").(string) + resourceGroup := d.Get("resource_group_name").(string) + requireClientAuthroization := d.Get("requires_client_authorization").(bool) + + parameters := relay.HybridConnection{ + HybridConnectionProperties: &relay.HybridConnectionProperties{ + RequiresClientAuthorization: &requireClientAuthroization, + }, + } + + _, err := client.CreateOrUpdate(ctx, resourceGroup, relayNamespace, name, parameters) + if err != nil { + return fmt.Errorf("Error creating Relay Hybrid Connection %q (Namespace %q Resource Group %q): %+v", name, relayNamespace, resourceGroup, err) + } + + read, err := client.Get(ctx, resourceGroup, relayNamespace, name) + if err != nil { + return fmt.Errorf("Error issuing get request for Relay Hybrid Connection %q (Namespace %q Resource Group %q): %+v", name, relayNamespace, resourceGroup, err) + } + if read.ID == nil { + return fmt.Errorf("Cannot read Relay Hybrid Connection %q (Namespace %q Resource group %s) ID", name, relayNamespace, resourceGroup) + } + + d.SetId(*read.ID) + + return resourceArmHybridConnectionRead(d, meta) +} + +func resourceArmHybridConnectionRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).Relay.HybridConnectionsClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*ArmClient).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + relayNamespace := id.Path["namespaces"] + name := id.Path["HybridConnections"] + + resp, err := client.Get(ctx, resourceGroup, relayNamespace, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + + return fmt.Errorf("Error making Read request on Relay Hybrid Connection %q (Namespace %q Resource Group %q): %s", name, relayNamespace, resourceGroup, err) + } + + d.Set("name", name) + d.Set("resource_group_name", resourceGroup) + d.Set("relay_namespace_name", relayNamespace) + + if props := resp.HybridConnectionProperties; props != nil { + d.Set("metric_id", props.RequiresClientAuthorization) + } + + return nil +} + +func resourceArmHybridConnectionDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).Relay.HybridConnectionsClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*ArmClient).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + relayNamespace := id.Path["namespaces"] + name := id.Path["HybridConnections"] + + log.Printf("[INFO] Waiting for Relay Hybrid Connection %q (Namespace %q Resource Group %q) to be deleted", name, relayNamespace, resourceGroup) + rc, err := client.Delete(ctx, resourceGroup, relayNamespace, name) + + if err != nil { + if response.WasNotFound(rc.Response) { + return nil + } + + return err + } + + stateConf := &resource.StateChangeConf{ + Pending: []string{"Pending"}, + Target: []string{"Deleted"}, + Refresh: hybridConnectionDeleteRefreshFunc(ctx, client, resourceGroup, relayNamespace, name), + Timeout: 60 * time.Minute, + MinTimeout: 15 * time.Second, + } + + if _, err := stateConf.WaitForState(); err != nil { + return fmt.Errorf("Error waiting for Relay Hybrid Connection %q (Namespace %q Resource Group %q) to be deleted: %s", name, relayNamespace, resourceGroup, err) + } + + return nil +} + +func hybridConnectionDeleteRefreshFunc(ctx context.Context, client *relay.HybridConnectionsClient, resourceGroupName string, relayNamespace string, name string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + res, err := client.Get(ctx, resourceGroupName, relayNamespace, name) + if err != nil { + if utils.ResponseWasNotFound(res.Response) { + return res, "Deleted", nil + } + + return nil, "Error", fmt.Errorf("Error issuing read request in relayNamespaceDeleteRefreshFunc to Relay Hybrid Connection %q (Namespace %q Resource Group %q): %s", name, relayNamespace, resourceGroupName, err) + } + + return res, "Pending", nil + } +} From a73f489e0e877988b32eaeb9085a46228c25d1df Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Wed, 6 Nov 2019 10:18:57 -0600 Subject: [PATCH 07/20] Add resource mapping --- azurerm/provider.go | 1 + 1 file changed, 1 insertion(+) diff --git a/azurerm/provider.go b/azurerm/provider.go index 43c9ffb6e118..439ae2799cb3 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -396,6 +396,7 @@ func Provider() terraform.ResourceProvider { "azurerm_redis_cache": resourceArmRedisCache(), "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), "azurerm_relay_namespace": resourceArmRelayNamespace(), + "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), "azurerm_resource_group": resourceArmResourceGroup(), "azurerm_role_assignment": resourceArmRoleAssignment(), "azurerm_role_definition": resourceArmRoleDefinition(), From c92be400167a13212ba40a14ff264dd533113c7a Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Wed, 6 Nov 2019 11:56:10 -0600 Subject: [PATCH 08/20] Fix typos --- azurerm/resource_arm_relay_hybrid_connection.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/azurerm/resource_arm_relay_hybrid_connection.go b/azurerm/resource_arm_relay_hybrid_connection.go index e9007c92fc3b..8a308f1b2d38 100644 --- a/azurerm/resource_arm_relay_hybrid_connection.go +++ b/azurerm/resource_arm_relay_hybrid_connection.go @@ -9,7 +9,6 @@ import ( "github.com/Azure/azure-sdk-for-go/services/relay/mgmt/2017-04-01/relay" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" @@ -39,9 +38,11 @@ func resourceArmHybridConnection() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validation.StringLenBetween(6, 50), + ValidateFunc: validate.NoEmptyStrings, }, + "resource_group_name": azure.SchemaResourceGroupName(), + "relay_namespace_name": { Type: schema.TypeString, Required: true, @@ -49,8 +50,6 @@ func resourceArmHybridConnection() *schema.Resource { ValidateFunc: validate.NoEmptyStrings, }, - "resource_group_name": azure.SchemaResourceGroupName(), - "requires_client_authorization": { Type: schema.TypeBool, Optional: true, @@ -67,8 +66,8 @@ func resourceArmHybridConnectionCreateUpdate(d *schema.ResourceData, meta interf log.Printf("[INFO] preparing arguments for Relay Hybrid Connection creation.") name := d.Get("name").(string) - relayNamespace := d.Get("relay_namespace_name").(string) resourceGroup := d.Get("resource_group_name").(string) + relayNamespace := d.Get("relay_namespace_name").(string) requireClientAuthroization := d.Get("requires_client_authorization").(bool) parameters := relay.HybridConnection{ @@ -106,7 +105,7 @@ func resourceArmHybridConnectionRead(d *schema.ResourceData, meta interface{}) e } resourceGroup := id.ResourceGroup relayNamespace := id.Path["namespaces"] - name := id.Path["HybridConnections"] + name := id.Path["hybridConnections"] resp, err := client.Get(ctx, resourceGroup, relayNamespace, name) if err != nil { @@ -123,7 +122,7 @@ func resourceArmHybridConnectionRead(d *schema.ResourceData, meta interface{}) e d.Set("relay_namespace_name", relayNamespace) if props := resp.HybridConnectionProperties; props != nil { - d.Set("metric_id", props.RequiresClientAuthorization) + d.Set("requires_client_authorization", props.RequiresClientAuthorization) } return nil @@ -140,7 +139,7 @@ func resourceArmHybridConnectionDelete(d *schema.ResourceData, meta interface{}) } resourceGroup := id.ResourceGroup relayNamespace := id.Path["namespaces"] - name := id.Path["HybridConnections"] + name := id.Path["hybridConnections"] log.Printf("[INFO] Waiting for Relay Hybrid Connection %q (Namespace %q Resource Group %q) to be deleted", name, relayNamespace, resourceGroup) rc, err := client.Delete(ctx, resourceGroup, relayNamespace, name) From 8308a1071d6e1a2ea58293d27cca34db8513c6a4 Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Wed, 6 Nov 2019 11:57:25 -0600 Subject: [PATCH 09/20] Update values for correct depedencies --- ...esource_arm_relay_hybrid_connection_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/azurerm/resource_arm_relay_hybrid_connection_test.go b/azurerm/resource_arm_relay_hybrid_connection_test.go index d67ff245af82..41ee94e76944 100644 --- a/azurerm/resource_arm_relay_hybrid_connection_test.go +++ b/azurerm/resource_arm_relay_hybrid_connection_test.go @@ -54,7 +54,7 @@ func TestAccAzureRMHybridConnection_requiresImport(t *testing.T) { Config: testAccAzureRMHybridConnection_basic(ri, testLocation()), Check: resource.ComposeTestCheckFunc( testCheckAzureRMHybridConnectionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "metric_id"), + resource.TestCheckResourceAttrSet(resourceName, "requires_client_authorization"), ), }, { @@ -82,10 +82,10 @@ resource "azurerm_relay_namespace" "test" { resource "azurerm_relay_hybrid_connection" "test" { name = "acctestrnhc-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - relay_namespace_name = "acctestrn-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + relay_namespace_name = "${azurerm_relay_namespace.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, rInt, location, rInt, rInt) } func testAccAzureRMHybridConnection_requiresImport(rInt int, location string) string { @@ -94,10 +94,10 @@ func testAccAzureRMHybridConnection_requiresImport(rInt int, location string) st resource "azurerm_relay_namespace" "import" { name = "acctestrnhc-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - relay_namespace_name = "acctestrn-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + relay_namespace_name = "${azurerm_relay_namespace.test.name}" } -`, testAccAzureRMHybridConnection_basic(rInt, location), rInt, rInt) +`, testAccAzureRMHybridConnection_basic(rInt, location), rInt) } func testCheckAzureRMHybridConnectionExists(resourceName string) resource.TestCheckFunc { @@ -108,9 +108,9 @@ func testCheckAzureRMHybridConnectionExists(resourceName string) resource.TestCh return fmt.Errorf("Not found: %s", resourceName) } + name := rs.Primary.Attributes["name"] resourceGroup := rs.Primary.Attributes["resource_group_name"] relayNamespace := rs.Primary.Attributes["relay_namespace_name"] - name := rs.Primary.Attributes["name"] // Ensure resource group exists in API client := testAccProvider.Meta().(*ArmClient).Relay.HybridConnectionsClient @@ -138,9 +138,9 @@ func testCheckAzureRMHybridConnectionDestroy(s *terraform.State) error { continue } + name := rs.Primary.Attributes["name"] resourceGroup := rs.Primary.Attributes["resource_group_name"] relayNamespace := rs.Primary.Attributes["relay_namespace_name"] - name := rs.Primary.Attributes["name"] resp, err := client.Get(ctx, resourceGroup, relayNamespace, name) if err != nil { From d23f6a02cbfcf714d9fcd2a186899b4a5aca2472 Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Wed, 6 Nov 2019 12:45:34 -0600 Subject: [PATCH 10/20] Align with Azure Portal settings --- azurerm/resource_arm_relay_hybrid_connection.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/azurerm/resource_arm_relay_hybrid_connection.go b/azurerm/resource_arm_relay_hybrid_connection.go index 8a308f1b2d38..779956a1b7a0 100644 --- a/azurerm/resource_arm_relay_hybrid_connection.go +++ b/azurerm/resource_arm_relay_hybrid_connection.go @@ -52,6 +52,8 @@ func resourceArmHybridConnection() *schema.Resource { "requires_client_authorization": { Type: schema.TypeBool, + Default: true, + ForceNew: true, Optional: true, }, }, From 1efdb7376ba31231cf253d6f5151dea6e2b46a80 Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Wed, 6 Nov 2019 13:55:42 -0600 Subject: [PATCH 11/20] Workaround for updating requires_client_authorization --- azurerm/resource_arm_relay_hybrid_connection.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_relay_hybrid_connection.go b/azurerm/resource_arm_relay_hybrid_connection.go index 779956a1b7a0..c3587a0c592e 100644 --- a/azurerm/resource_arm_relay_hybrid_connection.go +++ b/azurerm/resource_arm_relay_hybrid_connection.go @@ -7,6 +7,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/services/relay/mgmt/2017-04-01/relay" + "github.com/hashicorp/terraform-plugin-sdk/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" @@ -53,10 +54,17 @@ func resourceArmHybridConnection() *schema.Resource { "requires_client_authorization": { Type: schema.TypeBool, Default: true, - ForceNew: true, Optional: true, }, }, + + CustomizeDiff: customdiff.Sequence( + // This is to prevent this error: + // All fields are ForceNew or Computed w/out Optional, Update is superfluous. + customdiff.ForceNewIfChange("requires_client_authorization", func(old, new, meta interface{}) bool { + return true + }), + ), } } From 0e668790a141586719409f7bff3bbd568acd08f9 Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Wed, 6 Nov 2019 13:55:59 -0600 Subject: [PATCH 12/20] Add test for updating requires_client_authorization --- ...source_arm_relay_hybrid_connection_test.go | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/azurerm/resource_arm_relay_hybrid_connection_test.go b/azurerm/resource_arm_relay_hybrid_connection_test.go index 41ee94e76944..078cf7b2b7be 100644 --- a/azurerm/resource_arm_relay_hybrid_connection_test.go +++ b/azurerm/resource_arm_relay_hybrid_connection_test.go @@ -36,6 +36,32 @@ func TestAccAzureRMHybridConnection_basic(t *testing.T) { }) } +func TestAccAzureRMHybridConnection_update(t *testing.T) { + resourceName := "azurerm_relay_hybrid_connection.test" + rInt := tf.AccRandTimeInt() + location := testLocation() + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMHybridConnectionDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMHybridConnection_basic(rInt, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMHybridConnectionExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "requires_client_authorization"), + ), + }, + { + Config: testAccAzureRMHybridConnection_update(rInt, location), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "requires_client_authorization", "false"), + ), + }, + }, + }) +} + func TestAccAzureRMHybridConnection_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -88,6 +114,30 @@ resource "azurerm_relay_hybrid_connection" "test" { `, rInt, location, rInt, rInt) } +func testAccAzureRMHybridConnection_update(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_relay_namespace" "test" { + name = "acctestrn-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku_name = "Standard" +} + +resource "azurerm_relay_hybrid_connection" "test" { + name = "acctestrnhc-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + relay_namespace_name = "${azurerm_relay_namespace.test.name}" + requires_client_authorization = false + } +`, rInt, location, rInt, rInt) +} + func testAccAzureRMHybridConnection_requiresImport(rInt int, location string) string { return fmt.Sprintf(` %s From fe6132b85fd02fe157292dd6db92378ec195a4d4 Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Wed, 6 Nov 2019 14:18:26 -0600 Subject: [PATCH 13/20] Add document for azurerm_relay_hybrid_connection --- .../r/relay_hybrid_connection.html.markdown | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 website/docs/r/relay_hybrid_connection.html.markdown diff --git a/website/docs/r/relay_hybrid_connection.html.markdown b/website/docs/r/relay_hybrid_connection.html.markdown new file mode 100644 index 000000000000..0e2e2ea616cb --- /dev/null +++ b/website/docs/r/relay_hybrid_connection.html.markdown @@ -0,0 +1,65 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_relay_hybrid_connection" +sidebar_current: "docs-azurerm-resource-messaging-relay-hybrid-connection" +description: |- + Manages an Azure Relay Hybrid Connection. + +--- + +# azurerm_relay_hybrid_connection + +Manages an Azure Relay Hybrid Connection. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "test" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_relay_namespace" "test" { + name = "example-relay" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku_name = "Standard" + + tags = { + source = "terraform" + } +} + +resource "azurerm_relay_hybrid_connection" "test" { + name = "acctestrnhc-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + relay_namespace_name = "${azurerm_relay_namespace.test.name}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Azure Relay Hybrid Connection. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which to create the Azure Relay Hybrid Connection. Changing this forces a new resource to be created. + +* `relay_namespace_name` - (Required) The name of the Azure Relay in which to create the Azure Relay Hybrid Connection. Changing this forces a new resource to be created. + +* `requires_client_authorization` - (Optional) Specify if client authorization is needed for this hybrid connection. Changing this forces a new resource to be created. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The Azure Relay Hybrid Connection ID. + +## Import + +Azure Relay Namespace's can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_relay_namespace.relay1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Relay/namespaces/relay1/hybridConnections/hconn1 +``` From 524684867973f1fed32e26fb02bd33d606a3b540 Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Wed, 6 Nov 2019 14:36:24 -0600 Subject: [PATCH 14/20] Add optional requires_client_authorization in example --- website/docs/r/relay_hybrid_connection.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/relay_hybrid_connection.html.markdown b/website/docs/r/relay_hybrid_connection.html.markdown index 0e2e2ea616cb..ce585ee522f4 100644 --- a/website/docs/r/relay_hybrid_connection.html.markdown +++ b/website/docs/r/relay_hybrid_connection.html.markdown @@ -35,6 +35,7 @@ resource "azurerm_relay_hybrid_connection" "test" { name = "acctestrnhc-%d" resource_group_name = "${azurerm_resource_group.test.name}" relay_namespace_name = "${azurerm_relay_namespace.test.name}" + requires_client_authorization = false } ``` From 1e7856b4d691ec9ba1eb8536bd21e41a694b5ca6 Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Thu, 7 Nov 2019 08:58:59 -0600 Subject: [PATCH 15/20] Support UserMetadata --- ...source_arm_relay_hybrid_connection_test.go | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/azurerm/resource_arm_relay_hybrid_connection_test.go b/azurerm/resource_arm_relay_hybrid_connection_test.go index 078cf7b2b7be..854d9642f95b 100644 --- a/azurerm/resource_arm_relay_hybrid_connection_test.go +++ b/azurerm/resource_arm_relay_hybrid_connection_test.go @@ -36,6 +36,32 @@ func TestAccAzureRMHybridConnection_basic(t *testing.T) { }) } +func TestAccAzureRMHybridConnection_full(t *testing.T) { + resourceName := "azurerm_relay_hybrid_connection.test" + ri := tf.AccRandTimeInt() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMHybridConnectionDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMHybridConnection_full(ri, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMHybridConnectionExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "requires_client_authorization"), + resource.TestCheckResourceAttr(resourceName, "user_metadata", "metadatatest"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMHybridConnection_update(t *testing.T) { resourceName := "azurerm_relay_hybrid_connection.test" rInt := tf.AccRandTimeInt() @@ -56,6 +82,7 @@ func TestAccAzureRMHybridConnection_update(t *testing.T) { Config: testAccAzureRMHybridConnection_update(rInt, location), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "requires_client_authorization", "false"), + resource.TestCheckResourceAttr(resourceName, "user_metadata", "metadataupdated"), ), }, }, @@ -114,6 +141,30 @@ resource "azurerm_relay_hybrid_connection" "test" { `, rInt, location, rInt, rInt) } +func testAccAzureRMHybridConnection_full(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_relay_namespace" "test" { + name = "acctestrn-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku_name = "Standard" +} + +resource "azurerm_relay_hybrid_connection" "test" { + name = "acctestrnhc-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + relay_namespace_name = "${azurerm_relay_namespace.test.name}" + user_metadata = "metadatatest" + } +`, rInt, location, rInt, rInt) +} + func testAccAzureRMHybridConnection_update(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -134,6 +185,7 @@ resource "azurerm_relay_hybrid_connection" "test" { resource_group_name = "${azurerm_resource_group.test.name}" relay_namespace_name = "${azurerm_relay_namespace.test.name}" requires_client_authorization = false + user_metadata = "metadataupdated" } `, rInt, location, rInt, rInt) } From 8ee9c9b2ffd3d98ec4c8a15610d4932c09a6b9e3 Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Thu, 7 Nov 2019 09:45:24 -0600 Subject: [PATCH 16/20] Support UserMetadata --- azurerm/resource_arm_relay_hybrid_connection.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/azurerm/resource_arm_relay_hybrid_connection.go b/azurerm/resource_arm_relay_hybrid_connection.go index c3587a0c592e..1c2540c01ddd 100644 --- a/azurerm/resource_arm_relay_hybrid_connection.go +++ b/azurerm/resource_arm_relay_hybrid_connection.go @@ -7,7 +7,6 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/services/relay/mgmt/2017-04-01/relay" - "github.com/hashicorp/terraform-plugin-sdk/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" @@ -54,17 +53,14 @@ func resourceArmHybridConnection() *schema.Resource { "requires_client_authorization": { Type: schema.TypeBool, Default: true, + ForceNew: true, + Optional: true, + }, + "user_metadata": { + Type: schema.TypeString, Optional: true, }, }, - - CustomizeDiff: customdiff.Sequence( - // This is to prevent this error: - // All fields are ForceNew or Computed w/out Optional, Update is superfluous. - customdiff.ForceNewIfChange("requires_client_authorization", func(old, new, meta interface{}) bool { - return true - }), - ), } } @@ -79,10 +75,12 @@ func resourceArmHybridConnectionCreateUpdate(d *schema.ResourceData, meta interf resourceGroup := d.Get("resource_group_name").(string) relayNamespace := d.Get("relay_namespace_name").(string) requireClientAuthroization := d.Get("requires_client_authorization").(bool) + userMetadata := d.Get("user_metadata").(string) parameters := relay.HybridConnection{ HybridConnectionProperties: &relay.HybridConnectionProperties{ RequiresClientAuthorization: &requireClientAuthroization, + UserMetadata: &userMetadata, }, } @@ -133,6 +131,7 @@ func resourceArmHybridConnectionRead(d *schema.ResourceData, meta interface{}) e if props := resp.HybridConnectionProperties; props != nil { d.Set("requires_client_authorization", props.RequiresClientAuthorization) + d.Set("user_metadata", props.UserMetadata) } return nil From a85eb9be3cdbd6bf8b5836ba467fcba9afccf945 Mon Sep 17 00:00:00 2001 From: DSakura1987 Date: Thu, 7 Nov 2019 09:57:22 -0600 Subject: [PATCH 17/20] Add description for user_metadata --- website/docs/r/relay_hybrid_connection.html.markdown | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/website/docs/r/relay_hybrid_connection.html.markdown b/website/docs/r/relay_hybrid_connection.html.markdown index ce585ee522f4..e076dbb8d593 100644 --- a/website/docs/r/relay_hybrid_connection.html.markdown +++ b/website/docs/r/relay_hybrid_connection.html.markdown @@ -32,10 +32,11 @@ resource "azurerm_relay_namespace" "test" { } resource "azurerm_relay_hybrid_connection" "test" { - name = "acctestrnhc-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - relay_namespace_name = "${azurerm_relay_namespace.test.name}" + name = "acctestrnhc-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + relay_namespace_name = "${azurerm_relay_namespace.test.name}" requires_client_authorization = false + user_metadata = "testmetadata" } ``` @@ -49,7 +50,9 @@ The following arguments are supported: * `relay_namespace_name` - (Required) The name of the Azure Relay in which to create the Azure Relay Hybrid Connection. Changing this forces a new resource to be created. -* `requires_client_authorization` - (Optional) Specify if client authorization is needed for this hybrid connection. Changing this forces a new resource to be created. +* `requires_client_authorization` - (Optional) Specify if client authorization is needed for this hybrid connection. True by default. Changing this forces a new resource to be created. + +* `user_metadata` - (Optional) The usermetadata is a placeholder to store user-defined string data for the hybrid connection endpoint. For example, it can be used to store descriptive data, such as a list of teams and their contact information. Also, user-defined configuration settings can be stored. ## Attributes Reference From 8884ca3699d00c1514009a71aeecb23f787eb330 Mon Sep 17 00:00:00 2001 From: DSakura207 <4421906+DSakura207@users.noreply.github.com> Date: Thu, 7 Nov 2019 12:52:19 -0600 Subject: [PATCH 18/20] Fix copy-and-paste error --- website/docs/r/relay_hybrid_connection.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/r/relay_hybrid_connection.html.markdown b/website/docs/r/relay_hybrid_connection.html.markdown index e076dbb8d593..72cf0ede0702 100644 --- a/website/docs/r/relay_hybrid_connection.html.markdown +++ b/website/docs/r/relay_hybrid_connection.html.markdown @@ -62,8 +62,8 @@ The following attributes are exported: ## Import -Azure Relay Namespace's can be imported using the `resource id`, e.g. +Azure Relay Hybrid Connection's can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_relay_namespace.relay1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Relay/namespaces/relay1/hybridConnections/hconn1 +terraform import azurerm_relay_hybrid_connection.relay1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Relay/namespaces/relay1/hybridConnections/hconn1 ``` From bbb4c9f53a00452ad4ff49eaacd6fbfd9729c92d Mon Sep 17 00:00:00 2001 From: DSakura207 <4421906+DSakura207@users.noreply.github.com> Date: Thu, 7 Nov 2019 13:36:25 -0600 Subject: [PATCH 19/20] Add subcategory --- website/docs/r/relay_hybrid_connection.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/relay_hybrid_connection.html.markdown b/website/docs/r/relay_hybrid_connection.html.markdown index 72cf0ede0702..4f9e24525320 100644 --- a/website/docs/r/relay_hybrid_connection.html.markdown +++ b/website/docs/r/relay_hybrid_connection.html.markdown @@ -1,4 +1,5 @@ --- +subcategory: "Messaging" layout: "azurerm" page_title: "Azure Resource Manager: azurerm_relay_hybrid_connection" sidebar_current: "docs-azurerm-resource-messaging-relay-hybrid-connection" From 4d782e426f8e1a36eed97c10b7b8e213e0d116a0 Mon Sep 17 00:00:00 2001 From: Da Tao Date: Thu, 7 Nov 2019 18:39:36 -0600 Subject: [PATCH 20/20] Apply code review --- azurerm/internal/services/relay/client.go | 3 +- azurerm/provider.go | 2 +- .../resource_arm_relay_hybrid_connection.go | 7 +- ...source_arm_relay_hybrid_connection_test.go | 72 +++++++++---------- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/azurerm/internal/services/relay/client.go b/azurerm/internal/services/relay/client.go index 9f3046c85b3f..170427a377d3 100644 --- a/azurerm/internal/services/relay/client.go +++ b/azurerm/internal/services/relay/client.go @@ -12,8 +12,9 @@ type Client struct { func BuildClient(o *common.ClientOptions) *Client { NamespacesClient := relay.NewNamespacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) - HybridConnectionsClient := relay.NewHybridConnectionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&NamespacesClient.Client, o.ResourceManagerAuthorizer) + + HybridConnectionsClient := relay.NewHybridConnectionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&HybridConnectionsClient.Client, o.ResourceManagerAuthorizer) return &Client{ diff --git a/azurerm/provider.go b/azurerm/provider.go index 439ae2799cb3..bd5ac6517aaf 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -395,8 +395,8 @@ func Provider() terraform.ResourceProvider { "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), "azurerm_redis_cache": resourceArmRedisCache(), "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), - "azurerm_relay_namespace": resourceArmRelayNamespace(), "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), + "azurerm_relay_namespace": resourceArmRelayNamespace(), "azurerm_resource_group": resourceArmResourceGroup(), "azurerm_role_assignment": resourceArmRoleAssignment(), "azurerm_role_definition": resourceArmRoleDefinition(), diff --git a/azurerm/resource_arm_relay_hybrid_connection.go b/azurerm/resource_arm_relay_hybrid_connection.go index 1c2540c01ddd..790fe9ffb011 100644 --- a/azurerm/resource_arm_relay_hybrid_connection.go +++ b/azurerm/resource_arm_relay_hybrid_connection.go @@ -57,8 +57,9 @@ func resourceArmHybridConnection() *schema.Resource { Optional: true, }, "user_metadata": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.NoEmptyStrings, }, }, } @@ -165,7 +166,7 @@ func resourceArmHybridConnectionDelete(d *schema.ResourceData, meta interface{}) Pending: []string{"Pending"}, Target: []string{"Deleted"}, Refresh: hybridConnectionDeleteRefreshFunc(ctx, client, resourceGroup, relayNamespace, name), - Timeout: 60 * time.Minute, + Timeout: 30 * time.Minute, MinTimeout: 15 * time.Second, } diff --git a/azurerm/resource_arm_relay_hybrid_connection_test.go b/azurerm/resource_arm_relay_hybrid_connection_test.go index 854d9642f95b..061113a4adf4 100644 --- a/azurerm/resource_arm_relay_hybrid_connection_test.go +++ b/azurerm/resource_arm_relay_hybrid_connection_test.go @@ -11,19 +11,19 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) -func TestAccAzureRMHybridConnection_basic(t *testing.T) { +func TestAccAzureRMRelayHybridConnection_basic(t *testing.T) { resourceName := "azurerm_relay_hybrid_connection.test" ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMHybridConnectionDestroy, + CheckDestroy: testCheckAzureRMRelayHybridConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMHybridConnection_basic(ri, testLocation()), + Config: testAccAzureRMRelayHybridConnection_basic(ri, testLocation()), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHybridConnectionExists(resourceName), + testCheckAzureRMRelayHybridConnectionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "requires_client_authorization"), ), }, @@ -36,19 +36,19 @@ func TestAccAzureRMHybridConnection_basic(t *testing.T) { }) } -func TestAccAzureRMHybridConnection_full(t *testing.T) { +func TestAccAzureRMRelayHybridConnection_full(t *testing.T) { resourceName := "azurerm_relay_hybrid_connection.test" ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMHybridConnectionDestroy, + CheckDestroy: testCheckAzureRMRelayHybridConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMHybridConnection_full(ri, testLocation()), + Config: testAccAzureRMRelayHybridConnection_full(ri, testLocation()), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHybridConnectionExists(resourceName), + testCheckAzureRMRelayHybridConnectionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "requires_client_authorization"), resource.TestCheckResourceAttr(resourceName, "user_metadata", "metadatatest"), ), @@ -62,24 +62,24 @@ func TestAccAzureRMHybridConnection_full(t *testing.T) { }) } -func TestAccAzureRMHybridConnection_update(t *testing.T) { +func TestAccAzureRMRelayHybridConnection_update(t *testing.T) { resourceName := "azurerm_relay_hybrid_connection.test" rInt := tf.AccRandTimeInt() location := testLocation() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMHybridConnectionDestroy, + CheckDestroy: testCheckAzureRMRelayHybridConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMHybridConnection_basic(rInt, location), + Config: testAccAzureRMRelayHybridConnection_basic(rInt, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHybridConnectionExists(resourceName), + testCheckAzureRMRelayHybridConnectionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "requires_client_authorization"), ), }, { - Config: testAccAzureRMHybridConnection_update(rInt, location), + Config: testAccAzureRMRelayHybridConnection_update(rInt, location), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "requires_client_authorization", "false"), resource.TestCheckResourceAttr(resourceName, "user_metadata", "metadataupdated"), @@ -89,7 +89,7 @@ func TestAccAzureRMHybridConnection_update(t *testing.T) { }) } -func TestAccAzureRMHybridConnection_requiresImport(t *testing.T) { +func TestAccAzureRMRelayHybridConnection_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") return @@ -101,24 +101,24 @@ func TestAccAzureRMHybridConnection_requiresImport(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMHybridConnectionDestroy, + CheckDestroy: testCheckAzureRMRelayHybridConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMHybridConnection_basic(ri, testLocation()), + Config: testAccAzureRMRelayHybridConnection_basic(ri, testLocation()), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHybridConnectionExists(resourceName), + testCheckAzureRMRelayHybridConnectionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "requires_client_authorization"), ), }, { - Config: testAccAzureRMHybridConnection_requiresImport(ri, testLocation()), + Config: testAccAzureRMRelayHybridConnection_requiresImport(ri, testLocation()), ExpectError: testRequiresImportError("azurerm_relay_hybrid_connection"), }, }, }) } -func testAccAzureRMHybridConnection_basic(rInt int, location string) string { +func testAccAzureRMRelayHybridConnection_basic(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -135,13 +135,13 @@ resource "azurerm_relay_namespace" "test" { resource "azurerm_relay_hybrid_connection" "test" { name = "acctestrnhc-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - relay_namespace_name = "${azurerm_relay_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + relay_namespace_name = "${azurerm_relay_namespace.test.name}" } `, rInt, location, rInt, rInt) } -func testAccAzureRMHybridConnection_full(rInt int, location string) string { +func testAccAzureRMRelayHybridConnection_full(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -158,14 +158,14 @@ resource "azurerm_relay_namespace" "test" { resource "azurerm_relay_hybrid_connection" "test" { name = "acctestrnhc-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - relay_namespace_name = "${azurerm_relay_namespace.test.name}" - user_metadata = "metadatatest" + resource_group_name = "${azurerm_resource_group.test.name}" + relay_namespace_name = "${azurerm_relay_namespace.test.name}" + user_metadata = "metadatatest" } `, rInt, location, rInt, rInt) } -func testAccAzureRMHybridConnection_update(rInt int, location string) string { +func testAccAzureRMRelayHybridConnection_update(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -181,28 +181,28 @@ resource "azurerm_relay_namespace" "test" { } resource "azurerm_relay_hybrid_connection" "test" { - name = "acctestrnhc-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - relay_namespace_name = "${azurerm_relay_namespace.test.name}" + name = "acctestrnhc-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + relay_namespace_name = "${azurerm_relay_namespace.test.name}" requires_client_authorization = false - user_metadata = "metadataupdated" + user_metadata = "metadataupdated" } `, rInt, location, rInt, rInt) } -func testAccAzureRMHybridConnection_requiresImport(rInt int, location string) string { +func testAccAzureRMRelayHybridConnection_requiresImport(rInt int, location string) string { return fmt.Sprintf(` %s resource "azurerm_relay_namespace" "import" { name = "acctestrnhc-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - relay_namespace_name = "${azurerm_relay_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + relay_namespace_name = "${azurerm_relay_namespace.test.name}" } -`, testAccAzureRMHybridConnection_basic(rInt, location), rInt) +`, testAccAzureRMRelayHybridConnection_basic(rInt, location), rInt) } -func testCheckAzureRMHybridConnectionExists(resourceName string) resource.TestCheckFunc { +func testCheckAzureRMRelayHybridConnectionExists(resourceName 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[resourceName] @@ -231,7 +231,7 @@ func testCheckAzureRMHybridConnectionExists(resourceName string) resource.TestCh } } -func testCheckAzureRMHybridConnectionDestroy(s *terraform.State) error { +func testCheckAzureRMRelayHybridConnectionDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*ArmClient).Relay.HybridConnectionsClient ctx := testAccProvider.Meta().(*ArmClient).StopContext