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

hdinsight_spark_cluster_resource: Add support for availability_zones #28149

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/services/hdinsight/common_hdinsight.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/hdinsight/2021-06-01/clusters"
"github.com/hashicorp/go-azure-sdk/resource-manager/hdinsight/2021-06-01/extensions"
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/hdinsight/custompollers"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand Down Expand Up @@ -404,6 +405,16 @@ func flattenHDInsightAzureMonitor(input *extensions.AzureMonitorResponse) []inte
return output
}

func expandHDInsightAvailabilityZones(input interface{}) []string {
output := make([]string, 0)

v := input.(*schema.Set)
for _, az := range v.List() {
output = append(output, az.(string))
}
return output
}

func enableHDInsightMonitoring(ctx context.Context, client *extensions.ExtensionsClient, clusterId commonids.HDInsightClusterId, input []interface{}) error {
payload := ExpandHDInsightsMonitor(input)

Expand Down
10 changes: 10 additions & 0 deletions internal/services/hdinsight/hdinsight_spark_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ func resourceHDInsightSparkCluster() *pluginsdk.Resource {
"monitor": SchemaHDInsightsMonitor(),

"extension": SchemaHDInsightsExtension(),

"availability_zones": commonschema.ZonesMultipleOptional(),
},
}
}
Expand Down Expand Up @@ -272,6 +274,10 @@ func resourceHDInsightSparkClusterCreate(d *pluginsdk.ResourceData, meta interfa
}
}

if v, ok := d.GetOk("availability_zones"); ok {
payload.Zones = pointer.To(expandHDInsightAvailabilityZones(v))
}

if err := client.CreateThenPoll(ctx, id, payload); err != nil {
return fmt.Errorf("creating Spark %s: %+v", id, err)
}
Expand Down Expand Up @@ -384,6 +390,10 @@ func resourceHDInsightSparkClusterRead(d *pluginsdk.ResourceData, meta interface
return fmt.Errorf("flattening setting `disk_encryption`: %+v", err)
}

if model.Zones != nil {
d.Set("availability_zones", pointer.From(model.Zones))
}

if err := d.Set("network", flattenHDInsightsNetwork(props.NetworkProperties)); err != nil {
return fmt.Errorf("flattening `network`: %+v", err)
}
Expand Down
149 changes: 149 additions & 0 deletions internal/services/hdinsight/hdinsight_spark_cluster_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ func TestAccHDInsightSparkCluster_basic(t *testing.T) {
})
}

func TestAccHDInsightSparkCluster_availabilityZones(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_hdinsight_spark_cluster", "test")
r := HDInsightSparkClusterResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.availabilityZones(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
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 TestAccHDInsightSparkCluster_roleScriptActions(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_hdinsight_spark_cluster", "test")
r := HDInsightSparkClusterResource{}
Expand Down Expand Up @@ -742,6 +762,135 @@ resource "azurerm_hdinsight_spark_cluster" "test" {
`, r.template(data), data.RandomInteger)
}

func (r HDInsightSparkClusterResource) availabilityZones(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_mssql_server" "test" {
name = "acctestsql-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
administrator_login = "sql_admin"
administrator_login_password = "TerrAform123!"
version = "12.0"
}

resource "azurerm_mssql_database" "hive" {
name = "hive"
server_id = azurerm_mssql_server.test.id
collation = "SQL_Latin1_General_CP1_CI_AS"
create_mode = "Default"
}

resource "azurerm_mssql_database" "oozie" {
name = "oozie"
server_id = azurerm_mssql_server.test.id
collation = "SQL_Latin1_General_CP1_CI_AS"
create_mode = "Default"
}

resource "azurerm_mssql_database" "ambari" {
name = "ambari"
server_id = azurerm_mssql_server.test.id
collation = "SQL_Latin1_General_CP1_CI_AS"
create_mode = "Default"
}

resource "azurerm_mssql_firewall_rule" "AzureServices" {
name = "allow-azure-services"
server_id = azurerm_mssql_server.test.id
start_ip_address = "0.0.0.0"
end_ip_address = "0.0.0.0"
}

resource "azurerm_virtual_network" "test" {
name = "acctestvirtnet%d"
address_space = ["172.16.0.0/16"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_subnet" "test" {
name = "acctestsubnet%d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["172.16.11.0/26"]
}

resource "azurerm_hdinsight_spark_cluster" "test" {
name = "acctesthdi-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
cluster_version = "4.0"
tier = "Standard"
availability_zones = ["1"]

component_version {
spark = "2.4"
}

gateway {
username = "acctestusrgw"
password = "TerrAform123!"
}

storage_account_gen2 {
storage_resource_id = azurerm_storage_account.gen2test.id
filesystem_id = azurerm_storage_data_lake_gen2_filesystem.gen2test.id
managed_identity_resource_id = azurerm_user_assigned_identity.test.id
is_default = true
}

roles {
head_node {
vm_size = "Standard_A4_V2"
username = "acctestusrvm"
password = "AccTestvdSC4daf986!"
subnet_id = azurerm_subnet.test.id
virtual_network_id = azurerm_virtual_network.test.id
}

worker_node {
vm_size = "Standard_A4_V2"
username = "acctestusrvm"
password = "AccTestvdSC4daf986!"
target_instance_count = 3
subnet_id = azurerm_subnet.test.id
virtual_network_id = azurerm_virtual_network.test.id
}

zookeeper_node {
vm_size = "Medium"
username = "acctestusrvm"
password = "AccTestvdSC4daf986!"
subnet_id = azurerm_subnet.test.id
virtual_network_id = azurerm_virtual_network.test.id
}
}
metastores {
hive {
server = azurerm_mssql_server.test.fully_qualified_domain_name
database_name = azurerm_mssql_database.hive.name
username = azurerm_mssql_server.test.administrator_login
password = azurerm_mssql_server.test.administrator_login_password
}
oozie {
server = azurerm_mssql_server.test.fully_qualified_domain_name
database_name = azurerm_mssql_database.oozie.name
username = azurerm_mssql_server.test.administrator_login
password = azurerm_mssql_server.test.administrator_login_password
}
ambari {
server = azurerm_mssql_server.test.fully_qualified_domain_name
database_name = azurerm_mssql_database.ambari.name
username = azurerm_mssql_server.test.administrator_login
password = azurerm_mssql_server.test.administrator_login_password
}
}
}
`, r.gen2template(data), data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (r HDInsightSparkClusterResource) gen2basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/hdinsight_spark_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ The following arguments are supported:

* `security_profile` - (Optional) A `security_profile` block as defined below. Changing this forces a new resource to be created.

* `availability_zones` - (Optional) A list of Availability Zones which should be used for this HDInsight Spark Cluster.

---

A `component_version` block supports the following:
Expand Down
Loading