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

New Resource(s)/Data Sources for HDInsights Cluster #3196

Merged
merged 35 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6656450
registering the required resource providers for HDInsight
tombuildsstuff Apr 5, 2019
71d274f
Vendoring the HDInsights Clients
tombuildsstuff Apr 5, 2019
ba9b42f
HDInsight: common schema and helpers
tombuildsstuff Apr 5, 2019
659f851
New Resource: `azurerm_hdinsight_hadoop_cluster`
tombuildsstuff Apr 5, 2019
e00e84f
New Resource: `azurerm_hdinsight_hbase_cluster`
tombuildsstuff Apr 5, 2019
9c46324
New Resource: `azurerm_hdinsight_interactive_query_cluster`
tombuildsstuff Apr 5, 2019
3f4b4b8
New Resource: `azurerm_hdinsight_kafka_cluster`
tombuildsstuff Apr 5, 2019
1c9a524
New Resource: `azurerm_hdinsight_ml_services_cluster`
tombuildsstuff Apr 5, 2019
d263fc8
New Resource: `azurerm_hdinsight_rserver_cluster`
tombuildsstuff Apr 5, 2019
bd6a505
New Resource: `azurerm_hdinsight_spark_cluster`
tombuildsstuff Apr 5, 2019
bd196f0
New Resource: `azurerm_hdinsight_storm_cluster`
tombuildsstuff Apr 5, 2019
5370125
New Data Source: `azurerm_hdinsight_cluster`
tombuildsstuff Apr 5, 2019
d57f3ee
Registering/Linking to the HDInsight Resources
tombuildsstuff Apr 5, 2019
bb59833
Fixing a crash where the edge node didn't exist in the schema
tombuildsstuff Apr 5, 2019
61fd71f
r/hdinsight: removing irrelevant todo's
tombuildsstuff Apr 5, 2019
1f08567
r/hdinsight_interactive_query_cluster: loading the hive version from …
tombuildsstuff Apr 5, 2019
ba68216
r/hdinsight: setting `rserver` at the right location for MLServices/R…
tombuildsstuff Apr 5, 2019
01dd34b
r/hdinsight: standardizing the vm sku's
tombuildsstuff Apr 5, 2019
bec362d
r/hdinsight: ignoring the casing on sku
tombuildsstuff Apr 5, 2019
a4a4936
r/hdinsights_interactive_query: fixing the cluster kind
tombuildsstuff Apr 8, 2019
453af3a
r/hdinsights: allowing `Standard_A3` as a type
tombuildsstuff Apr 8, 2019
efab846
r/hdinsight_interactive_query: using `Standard_A4_V2` instances
tombuildsstuff Apr 8, 2019
2ca7596
hdinsight: switching out the example vm sku's
tombuildsstuff Apr 8, 2019
5e7c26a
r/hdinsight: adding a test for the cluster version diff suppress func
tombuildsstuff Apr 8, 2019
0002762
r/hdinsight: validation for the cluster version field
tombuildsstuff Apr 8, 2019
1023dad
r/hdinsight: documenting the password requirements
tombuildsstuff Apr 8, 2019
a9d1413
r/hdinsights_interactive_query: switching to large instances.
tombuildsstuff Apr 8, 2019
b6c7024
r/hdinsight_spark: adding a fixed target count
tombuildsstuff Apr 8, 2019
8552769
d/hdinsight_cluster: setting the id
tombuildsstuff Apr 8, 2019
58a57b7
d/hdinsight_cluster: loading the values from the config, rather than …
tombuildsstuff Apr 8, 2019
1a22656
d/hdinsight_cluster: fixing the casing on the test
tombuildsstuff Apr 8, 2019
63304cc
d/hdinsight: force lower-casing the kind
tombuildsstuff Apr 8, 2019
2740d05
r/hdinsights: addressing comments from PR review
tombuildsstuff Apr 9, 2019
ac37aa2
r/hdinsight: documenting why this pattern is different
tombuildsstuff Apr 9, 2019
455dc3d
fixing the import
tombuildsstuff Apr 9, 2019
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
177 changes: 177 additions & 0 deletions azurerm/common_hdinsight.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package azurerm

import (
"fmt"
"log"

"github.com/Azure/azure-sdk-for-go/services/preview/hdinsight/mgmt/2018-06-01-preview/hdinsight"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func hdinsightClusterUpdate(clusterKind string, readFunc schema.ReadFunc) schema.UpdateFunc {
return func(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).hdinsightClustersClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
if err != nil {
return err
}

resourceGroup := id.ResourceGroup
name := id.Path["clusters"]

if d.HasChange("tags") {
tags := d.Get("tags").(map[string]interface{})
params := hdinsight.ClusterPatchParameters{
Tags: expandTags(tags),
}
if _, err := client.Update(ctx, resourceGroup, name, params); err != nil {
return fmt.Errorf("Error updating Tags for HDInsight %q Cluster %q (Resource Group %q): %+v", clusterKind, name, resourceGroup, err)
}
}

if d.HasChange("roles") {
log.Printf("[DEBUG] Resizing the HDInsight %q Cluster", clusterKind)
rolesRaw := d.Get("roles").([]interface{})
roles := rolesRaw[0].(map[string]interface{})
headNodes := roles["worker_node"].([]interface{})
headNode := headNodes[0].(map[string]interface{})
targetInstanceCount := headNode["target_instance_count"].(int)
params := hdinsight.ClusterResizeParameters{
TargetInstanceCount: utils.Int32(int32(targetInstanceCount)),
}

future, err := client.Resize(ctx, resourceGroup, name, params)
if err != nil {
return fmt.Errorf("Error resizing the HDInsight %q Cluster %q (Resource Group %q): %+v", clusterKind, name, resourceGroup, err)
}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("Error waiting for the HDInsight %q Cluster %q (Resource Group %q) to finish resizing: %+v", clusterKind, name, resourceGroup, err)
}
}

return readFunc(d, meta)
}
}

func hdinsightClusterDelete(clusterKind string) schema.DeleteFunc {
return func(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).hdinsightClustersClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
if err != nil {
return err
}

resourceGroup := id.ResourceGroup
name := id.Path["clusters"]

future, err := client.Delete(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error deleting HDInsight %q Cluster %q (Resource Group %q): %+v", clusterKind, name, resourceGroup, err)
}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("Error waiting for deletion of HDInsight %q Cluster %q (Resource Group %q): %+v", clusterKind, name, resourceGroup, err)
}

return nil
}
}

type hdInsightRoleDefinition struct {
HeadNodeDef azure.HDInsightNodeDefinition
WorkerNodeDef azure.HDInsightNodeDefinition
ZookeeperNodeDef azure.HDInsightNodeDefinition
EdgeNodeDef *azure.HDInsightNodeDefinition
}

func expandHDInsightRoles(input []interface{}, definition hdInsightRoleDefinition) (*[]hdinsight.Role, error) {
v := input[0].(map[string]interface{})

headNodeRaw := v["head_node"].([]interface{})
headNode, err := azure.ExpandHDInsightNodeDefinition("headnode", headNodeRaw, definition.HeadNodeDef)
if err != nil {
return nil, fmt.Errorf("Error expanding `head_node`: %+v", err)
}

workerNodeRaw := v["worker_node"].([]interface{})
workerNode, err := azure.ExpandHDInsightNodeDefinition("workernode", workerNodeRaw, definition.WorkerNodeDef)
if err != nil {
return nil, fmt.Errorf("Error expanding `worker_node`: %+v", err)
}

zookeeperNodeRaw := v["zookeeper_node"].([]interface{})
zookeeperNode, err := azure.ExpandHDInsightNodeDefinition("zookeepernode", zookeeperNodeRaw, definition.ZookeeperNodeDef)
if err != nil {
return nil, fmt.Errorf("Error expanding `zookeeper_node`: %+v", err)
}

roles := []hdinsight.Role{
*headNode,
*workerNode,
*zookeeperNode,
}

if definition.EdgeNodeDef != nil {
edgeNodeRaw := v["edge_node"].([]interface{})
edgeNode, err := azure.ExpandHDInsightNodeDefinition("edgenode", edgeNodeRaw, *definition.EdgeNodeDef)
if err != nil {
return nil, fmt.Errorf("Error expanding `edge_node`: %+v", err)
}
roles = append(roles, *edgeNode)
}

return &roles, nil
}

func flattenHDInsightRoles(d *schema.ResourceData, input *hdinsight.ComputeProfile, definition hdInsightRoleDefinition) []interface{} {
if input == nil || input.Roles == nil {
return []interface{}{}
}

var existingEdgeNodes, existingHeadNodes, existingWorkerNodes, existingZookeeperNodes []interface{}

existingVs := d.Get("roles").([]interface{})
if len(existingVs) > 0 {
existingV := existingVs[0].(map[string]interface{})

if definition.EdgeNodeDef != nil {
existingEdgeNodes = existingV["edge_node"].([]interface{})
}

existingHeadNodes = existingV["head_node"].([]interface{})
existingWorkerNodes = existingV["worker_node"].([]interface{})
existingZookeeperNodes = existingV["zookeeper_node"].([]interface{})
}

headNode := azure.FindHDInsightRole(input.Roles, "headnode")
headNodes := azure.FlattenHDInsightNodeDefinition(headNode, existingHeadNodes, definition.HeadNodeDef)

workerNode := azure.FindHDInsightRole(input.Roles, "workernode")
workerNodes := azure.FlattenHDInsightNodeDefinition(workerNode, existingWorkerNodes, definition.WorkerNodeDef)

zookeeperNode := azure.FindHDInsightRole(input.Roles, "zookeepernode")
zookeeperNodes := azure.FlattenHDInsightNodeDefinition(zookeeperNode, existingZookeeperNodes, definition.ZookeeperNodeDef)

result := map[string]interface{}{
"head_node": headNodes,
"worker_node": workerNodes,
"zookeeper_node": zookeeperNodes,
}

if definition.EdgeNodeDef != nil {
edgeNode := azure.FindHDInsightRole(input.Roles, "edgenode")
edgeNodes := azure.FlattenHDInsightNodeDefinition(edgeNode, existingEdgeNodes, *definition.EdgeNodeDef)
result["edge_node"] = edgeNodes
}

return []interface{}{
result,
}
}
59 changes: 59 additions & 0 deletions azurerm/common_hdinsight_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package azurerm

import (
"fmt"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func testCheckAzureRMHDInsightClusterDestroy(terraformResourceName string) func(s *terraform.State) error {
return func(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != terraformResourceName {
continue
}

client := testAccProvider.Meta().(*ArmClient).hdinsightClustersClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
name := rs.Primary.Attributes["name"]
resourceGroup := rs.Primary.Attributes["resource_group_name"]
resp, err := client.Get(ctx, resourceGroup, name)

if err != nil {
if !utils.ResponseWasNotFound(resp.Response) {
return err
}
}
}

return nil
}
}

func testCheckAzureRMHDInsightClusterExists(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)
}

clusterName := rs.Primary.Attributes["name"]
resourceGroup := rs.Primary.Attributes["resource_group_name"]

client := testAccProvider.Meta().(*ArmClient).hdinsightClustersClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
resp, err := client.Get(ctx, resourceGroup, clusterName)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Bad: HDInsight Cluster %q (Resource Group: %q) does not exist", clusterName, resourceGroup)
}

return fmt.Errorf("Bad: Get on hdinsightClustersClient: %+v", err)
}

return nil
}
}
21 changes: 21 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/preview/devspaces/mgmt/2018-06-01-preview/devspaces"
"github.com/Azure/azure-sdk-for-go/services/preview/dns/mgmt/2018-03-01-preview/dns"
"github.com/Azure/azure-sdk-for-go/services/preview/eventgrid/mgmt/2018-09-15-preview/eventgrid"
"github.com/Azure/azure-sdk-for-go/services/preview/hdinsight/mgmt/2018-06-01-preview/hdinsight"
"github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2018-12-01-preview/devices"
"github.com/Azure/azure-sdk-for-go/services/preview/mariadb/mgmt/2018-06-01-preview/mariadb"
"github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2018-03-01/insights"
Expand Down Expand Up @@ -234,6 +235,11 @@ type ArmClient struct {
// Databricks
databricksWorkspacesClient databricks.WorkspacesClient

// HDInsight
hdinsightApplicationsClient hdinsight.ApplicationsClient
hdinsightClustersClient hdinsight.ClustersClient
hdinsightConfigurationsClient hdinsight.ConfigurationsClient

// KeyVault
keyVaultClient keyvault.VaultsClient
keyVaultManagementClient keyVault.BaseClient
Expand Down Expand Up @@ -479,6 +485,7 @@ func getArmClient(c *authentication.Config, skipProviderRegistration bool, partn
client.registerDNSClients(endpoint, c.SubscriptionID, auth)
client.registerEventGridClients(endpoint, c.SubscriptionID, auth)
client.registerEventHubClients(endpoint, c.SubscriptionID, auth)
client.registerHDInsightsClients(endpoint, c.SubscriptionID, auth)
client.registerKeyVaultClients(endpoint, c.SubscriptionID, auth, keyVaultAuth)
client.registerLogicClients(endpoint, c.SubscriptionID, auth)
client.registerMediaServiceClients(endpoint, c.SubscriptionID, auth)
Expand Down Expand Up @@ -958,6 +965,20 @@ func (c *ArmClient) registerEventHubClients(endpoint, subscriptionId string, aut
c.eventHubNamespacesClient = ehnc
}

func (c *ArmClient) registerHDInsightsClients(endpoint, subscriptionId string, auth autorest.Authorizer) {
applicationsClient := hdinsight.NewApplicationsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&applicationsClient.Client, auth)
c.hdinsightApplicationsClient = applicationsClient

clustersClient := hdinsight.NewClustersClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&clustersClient.Client, auth)
c.hdinsightClustersClient = clustersClient

configurationsClient := hdinsight.NewConfigurationsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&configurationsClient.Client, auth)
c.hdinsightConfigurationsClient = configurationsClient
}

func (c *ArmClient) registerKeyVaultClients(endpoint, subscriptionId string, auth autorest.Authorizer, keyVaultAuth autorest.Authorizer) {
keyVaultClient := keyvault.NewVaultsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&keyVaultClient.Client, auth)
Expand Down
Loading