diff --git a/azurerm/helpers/azure/hdinsight.go b/azurerm/helpers/azure/hdinsight.go index ca129004101e..d60bfcfe5da2 100644 --- a/azurerm/helpers/azure/hdinsight.go +++ b/azurerm/helpers/azure/hdinsight.go @@ -2,7 +2,6 @@ package azure import ( "fmt" - "strconv" "strings" "github.com/Azure/azure-sdk-for-go/services/preview/hdinsight/mgmt/2018-06-01-preview/hdinsight" @@ -93,10 +92,20 @@ func SchemaHDInsightsGateway() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + // TODO 3.0: remove this attribute "enabled": { - Type: schema.TypeBool, - Required: true, - ForceNew: true, + Type: schema.TypeBool, + Optional: true, + Default: true, + Deprecated: "HDInsight doesn't support disabling gateway anymore", + ValidateFunc: func(i interface{}, k string) (warnings []string, errors []error) { + enabled := i.(bool) + + if !enabled { + errors = append(errors, fmt.Errorf("Only true is supported, because HDInsight doesn't support disabling gateway anymore. Provided value %t", enabled)) + } + return warnings, errors + }, }, // NOTE: these are Required since if these aren't present you get a `500 bad request` "username": { @@ -107,7 +116,6 @@ func SchemaHDInsightsGateway() *schema.Schema { "password": { Type: schema.TypeString, Required: true, - ForceNew: true, Sensitive: true, // Azure returns the key as *****. We'll suppress that here. DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { @@ -160,7 +168,7 @@ func ExpandHDInsightsConfigurations(input []interface{}) map[string]interface{} vs := input[0].(map[string]interface{}) // NOTE: Admin username must be different from SSH Username - enabled := vs["enabled"].(bool) + enabled := true username := vs["username"].(string) password := vs["password"].(string) @@ -254,13 +262,7 @@ func ExpandHDInsightsAmbariMetastore(input []interface{}) map[string]interface{} } func FlattenHDInsightsConfigurations(input map[string]*string) []interface{} { - enabled := false - if v, exists := input["restAuthCredential.isEnabled"]; exists && v != nil { - e, err := strconv.ParseBool(*v) - if err == nil { - enabled = e - } - } + enabled := true username := "" if v, exists := input["restAuthCredential.username"]; exists && v != nil { diff --git a/azurerm/internal/services/hdinsight/common_hdinsight.go b/azurerm/internal/services/hdinsight/common_hdinsight.go index 265c68e56dc0..f6de5aeec497 100644 --- a/azurerm/internal/services/hdinsight/common_hdinsight.go +++ b/azurerm/internal/services/hdinsight/common_hdinsight.go @@ -106,6 +106,29 @@ func hdinsightClusterUpdate(clusterKind string, readFunc schema.ReadFunc) schema } } + if d.HasChange("gateway") { + log.Printf("[DEBUG] Updating the HDInsight %q Cluster gateway", clusterKind) + vs := d.Get("gateway").([]interface{})[0].(map[string]interface{}) + + enabled := true + username := vs["username"].(string) + password := vs["password"].(string) + + future, err := client.UpdateGatewaySettings(ctx, resourceGroup, name, hdinsight.UpdateGatewaySettingsParameters{ + IsCredentialEnabled: &enabled, + UserName: utils.String(username), + Password: utils.String(password), + }) + + if err != nil { + return err + } + + if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for HDInsight Cluster %q (Resource Group %q) Gateway to be updated: %s", name, resourceGroup, err) + } + } + return readFunc(d, meta) } } diff --git a/azurerm/internal/services/hdinsight/tests/hdinsight_hadoop_cluster_resource_test.go b/azurerm/internal/services/hdinsight/tests/hdinsight_hadoop_cluster_resource_test.go index 05780c4b5fbc..835443ed53f0 100644 --- a/azurerm/internal/services/hdinsight/tests/hdinsight_hadoop_cluster_resource_test.go +++ b/azurerm/internal/services/hdinsight/tests/hdinsight_hadoop_cluster_resource_test.go @@ -435,6 +435,47 @@ func TestAccAzureRMHDInsightHadoopCluster_updateMetastore(t *testing.T) { }) } +func TestAccAzureRMHDInsightHadoopCluster_updateGateway(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hadoop_cluster", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), + Steps: []resource.TestStep{ + { + Config: testAccAzureRMHDInsightHadoopCluster_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), + ), + }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), + { + Config: testAccAzureRMHDInsightHadoopCluster_updateGateway(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), + ), + }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), + }, + }) +} + func testAccAzureRMHDInsightHadoopCluster_basic(data acceptance.TestData) string { template := testAccAzureRMHDInsightHadoopCluster_template(data) return fmt.Sprintf(` @@ -452,7 +493,6 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } gateway { - enabled = true username = "acctestusrgw" password = "TerrAform123!" } @@ -1316,3 +1356,54 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } `, template, data.RandomInteger, data.RandomInteger) } + +func testAccAzureRMHDInsightHadoopCluster_updateGateway(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHadoopCluster_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_hdinsight_hadoop_cluster" "test" { + name = "acctesthdi-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + cluster_version = "3.6" + tier = "Standard" + + component_version { + hadoop = "2.7" + } + + gateway { + username = "acctestusrgw" + password = "TerrAformne3!" + } + + storage_account { + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key + is_default = true + } + + roles { + head_node { + vm_size = "Standard_D3_v2" + username = "acctestusrvm" + password = "AccTestvdSC4daf986!" + } + + worker_node { + vm_size = "Standard_D4_V2" + username = "acctestusrvm" + password = "AccTestvdSC4daf986!" + target_instance_count = 2 + } + + zookeeper_node { + vm_size = "Standard_D3_v2" + username = "acctestusrvm" + password = "AccTestvdSC4daf986!" + } + } +} +`, template, data.RandomInteger) +} diff --git a/website/docs/r/hdinsight_hadoop_cluster.html.markdown b/website/docs/r/hdinsight_hadoop_cluster.html.markdown index bccdc6d1b00b..1df2f504a71c 100644 --- a/website/docs/r/hdinsight_hadoop_cluster.html.markdown +++ b/website/docs/r/hdinsight_hadoop_cluster.html.markdown @@ -123,9 +123,9 @@ A `component_version` block supports the following: A `gateway` block supports the following: -* `enabled` - (Required) Is the Ambari portal enabled? Changing this forces a new resource to be created. +* `enabled` - (Optional/ **Deprecated) Is the Ambari portal enabled? The HDInsight API doesn't support disabling gateway anymore. -* `password` - (Required) The password used for the Ambari Portal. Changing this forces a new resource to be created. +* `password` - (Required) The password used for the Ambari Portal. -> **NOTE:** This password must be different from the one used for the `head_node`, `worker_node` and `zookeeper_node` roles. diff --git a/website/docs/r/hdinsight_hbase_cluster.html.markdown b/website/docs/r/hdinsight_hbase_cluster.html.markdown index 4c1bb01e8d18..f09e6c421520 100644 --- a/website/docs/r/hdinsight_hbase_cluster.html.markdown +++ b/website/docs/r/hdinsight_hbase_cluster.html.markdown @@ -121,9 +121,9 @@ A `component_version` block supports the following: A `gateway` block supports the following: -* `enabled` - (Required) Is the Ambari portal enabled? Changing this forces a new resource to be created. +* `enabled` - (Optional/ **Deprecated) Is the Ambari portal enabled? The HDInsight API doesn't support disabling gateway anymore. -* `password` - (Required) The password used for the Ambari Portal. Changing this forces a new resource to be created. +* `password` - (Required) The password used for the Ambari Portal. -> **NOTE:** This password must be different from the one used for the `head_node`, `worker_node` and `zookeeper_node` roles. diff --git a/website/docs/r/hdinsight_interactive_query_cluster.html.markdown b/website/docs/r/hdinsight_interactive_query_cluster.html.markdown index e1fbd7814ab6..742443c5fd3b 100644 --- a/website/docs/r/hdinsight_interactive_query_cluster.html.markdown +++ b/website/docs/r/hdinsight_interactive_query_cluster.html.markdown @@ -119,9 +119,9 @@ A `component_version` block supports the following: A `gateway` block supports the following: -* `enabled` - (Required) Is the Ambari portal enabled? Changing this forces a new resource to be created. +* `enabled` - (Optional/ **Deprecated) Is the Ambari portal enabled? The HDInsight API doesn't support disabling gateway anymore. -* `password` - (Required) The password used for the Ambari Portal. Changing this forces a new resource to be created. +* `password` - (Required) The password used for the Ambari Portal. -> **NOTE:** This password must be different from the one used for the `head_node`, `worker_node` and `zookeeper_node` roles. diff --git a/website/docs/r/hdinsight_kafka_cluster.html.markdown b/website/docs/r/hdinsight_kafka_cluster.html.markdown index 595a1dae5110..3149632c9556 100644 --- a/website/docs/r/hdinsight_kafka_cluster.html.markdown +++ b/website/docs/r/hdinsight_kafka_cluster.html.markdown @@ -122,9 +122,9 @@ A `component_version` block supports the following: A `gateway` block supports the following: -* `enabled` - (Required) Is the Ambari portal enabled? Changing this forces a new resource to be created. +* `enabled` - (Optional/ **Deprecated) Is the Ambari portal enabled? The HDInsight API doesn't support disabling gateway anymore. -* `password` - (Required) The password used for the Ambari Portal. Changing this forces a new resource to be created. +* `password` - (Required) The password used for the Ambari Portal. -> **NOTE:** This password must be different from the one used for the `head_node`, `worker_node` and `zookeeper_node` roles. diff --git a/website/docs/r/hdinsight_ml_services_cluster.html.markdown b/website/docs/r/hdinsight_ml_services_cluster.html.markdown index fa7534e060db..4cc19eec15d4 100644 --- a/website/docs/r/hdinsight_ml_services_cluster.html.markdown +++ b/website/docs/r/hdinsight_ml_services_cluster.html.markdown @@ -116,9 +116,9 @@ The following arguments are supported: A `gateway` block supports the following: -* `enabled` - (Required) Is the Ambari portal enabled? Changing this forces a new resource to be created. +* `enabled` - (Optional/ **Deprecated) Is the Ambari portal enabled? The HDInsight API doesn't support disabling gateway anymore. -* `password` - (Required) The password used for the Ambari Portal. Changing this forces a new resource to be created. +* `password` - (Required) The password used for the Ambari Portal. -> **NOTE:** This password must be different from the one used for the `head_node`, `worker_node` and `zookeeper_node` roles. diff --git a/website/docs/r/hdinsight_rserver_cluster.html.markdown b/website/docs/r/hdinsight_rserver_cluster.html.markdown index 0f91e299245d..1dd9cfd3e248 100644 --- a/website/docs/r/hdinsight_rserver_cluster.html.markdown +++ b/website/docs/r/hdinsight_rserver_cluster.html.markdown @@ -116,9 +116,9 @@ The following arguments are supported: A `gateway` block supports the following: -* `enabled` - (Required) Is the Ambari portal enabled? Changing this forces a new resource to be created. +* `enabled` - (Optional/ **Deprecated) Is the Ambari portal enabled? The HDInsight API doesn't support disabling gateway anymore. -* `password` - (Required) The password used for the Ambari Portal. Changing this forces a new resource to be created. +* `password` - (Required) The password used for the Ambari Portal. -> **NOTE:** This password must be different from the one used for the `head_node`, `worker_node` and `zookeeper_node` roles. diff --git a/website/docs/r/hdinsight_spark_cluster.html.markdown b/website/docs/r/hdinsight_spark_cluster.html.markdown index 6fbe8ab7d4e7..3f5375e43f98 100644 --- a/website/docs/r/hdinsight_spark_cluster.html.markdown +++ b/website/docs/r/hdinsight_spark_cluster.html.markdown @@ -121,9 +121,9 @@ A `component_version` block supports the following: A `gateway` block supports the following: -* `enabled` - (Required) Is the Ambari portal enabled? Changing this forces a new resource to be created. +* `enabled` - (Optional/ **Deprecated) Is the Ambari portal enabled? The HDInsight API doesn't support disabling gateway anymore. -* `password` - (Required) The password used for the Ambari Portal. Changing this forces a new resource to be created. +* `password` - (Required) The password used for the Ambari Portal. -> **NOTE:** This password must be different from the one used for the `head_node`, `worker_node` and `zookeeper_node` roles. diff --git a/website/docs/r/hdinsight_storm_cluster.html.markdown b/website/docs/r/hdinsight_storm_cluster.html.markdown index e36adf352c20..05a6364b25b0 100644 --- a/website/docs/r/hdinsight_storm_cluster.html.markdown +++ b/website/docs/r/hdinsight_storm_cluster.html.markdown @@ -119,9 +119,9 @@ A `component_version` block supports the following: A `gateway` block supports the following: -* `enabled` - (Required) Is the Ambari portal enabled? Changing this forces a new resource to be created. +* `enabled` - (Optional/ **Deprecated) Is the Ambari portal enabled? The HDInsight API doesn't support disabling gateway anymore. -* `password` - (Required) The password used for the Ambari Portal. Changing this forces a new resource to be created. +* `password` - (Required) The password used for the Ambari Portal. -> **NOTE:** This password must be different from the one used for the `head_node`, `worker_node` and `zookeeper_node` roles.