Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_hdinsight_*_cluster - fix broken updaten due to api not allowing cluster to be disabled #7111

Merged
merged 13 commits into from Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 15 additions & 13 deletions azurerm/helpers/azure/hdinsight.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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": {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions azurerm/internal/services/hdinsight/common_hdinsight.go
Expand Up @@ -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)
}
}
Expand Down
Expand Up @@ -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(`
Expand All @@ -452,7 +493,6 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" {
}

gateway {
enabled = true
username = "acctestusrgw"
password = "TerrAform123!"
}
Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions website/docs/r/hdinsight_hadoop_cluster.html.markdown
Expand Up @@ -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) Is the Ambari portal enabled? Deprecated: HDInsight doesn't support disabling gateway anymore.
katbyte marked this conversation as resolved.
Show resolved Hide resolved

* `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.

Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/hdinsight_hbase_cluster.html.markdown
Expand Up @@ -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) Is the Ambari portal enabled? Deprecated: HDInsight doesn't support disabling gateway anymore.
katbyte marked this conversation as resolved.
Show resolved Hide resolved

* `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.

Expand Down
Expand Up @@ -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) Is the Ambari portal enabled? Deprecated: HDInsight doesn't support disabling gateway anymore.
katbyte marked this conversation as resolved.
Show resolved Hide resolved

* `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.

Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/hdinsight_kafka_cluster.html.markdown
Expand Up @@ -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) Is the Ambari portal enabled? Deprecated: HDInsight doesn't support disabling gateway anymore.
katbyte marked this conversation as resolved.
Show resolved Hide resolved

* `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.

Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/hdinsight_ml_services_cluster.html.markdown
Expand Up @@ -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) Is the Ambari portal enabled? Deprecated: HDInsight doesn't support disabling gateway anymore.
katbyte marked this conversation as resolved.
Show resolved Hide resolved

* `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.

Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/hdinsight_rserver_cluster.html.markdown
Expand Up @@ -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) Is the Ambari portal enabled? Deprecated: HDInsight doesn't support disabling gateway anymore.
katbyte marked this conversation as resolved.
Show resolved Hide resolved

* `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.

Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/hdinsight_spark_cluster.html.markdown
Expand Up @@ -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) Is the Ambari portal enabled? Deprecated: HDInsight doesn't support disabling gateway anymore.
katbyte marked this conversation as resolved.
Show resolved Hide resolved

* `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.

Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/hdinsight_storm_cluster.html.markdown
Expand Up @@ -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) Is the Ambari portal enabled? Deprecated: HDInsight doesn't support disabling gateway anymore.
katbyte marked this conversation as resolved.
Show resolved Hide resolved

* `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.

Expand Down