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

Azure monitor support for azurerm_hdinsight_*_cluster #7045

Merged
merged 51 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8f6e1c8
Enable monitor on create
kosinsky May 19, 2020
6497a82
Implement monitor changes
kosinsky May 19, 2020
20ca28b
Error message clean up
kosinsky May 19, 2020
6b8ac0d
Documentation for hadoop
kosinsky May 19, 2020
af64be0
A bit of refactoring
kosinsky May 19, 2020
e45e69a
Aze monioor HBase cluster
kosinsky May 19, 2020
5566f35
Azure Monitor for InteractiveQuery cluster
kosinsky May 19, 2020
1c55195
Azure monitor for Kafka
kosinsky May 19, 2020
475d205
Azure monitor for Spark
kosinsky May 19, 2020
416cbb2
Azure monitor for Storm
kosinsky May 20, 2020
1220e10
Azure monitor doc for all hdinsight resources
kosinsky May 20, 2020
abdd57a
Ensure that basic and monitor tests use the same roles
kosinsky May 21, 2020
1a16f34
Fixing linter errors
kosinsky May 21, 2020
6c79c3f
Merge branch 'master' into hdi_azure_monitor
kosinsky Jun 30, 2020
1bff630
Fix typo in debug output
kosinsky Jun 30, 2020
07b7624
Moved extensionsClient
kosinsky Jul 1, 2020
1a47098
Return error if disabling monitor fails
kosinsky Jul 1, 2020
1c451ff
Error messages
kosinsky Jul 7, 2020
8227f7c
Error messages
kosinsky Jul 7, 2020
cf39c28
Error messages
kosinsky Jul 7, 2020
e2a7c85
Error messages
kosinsky Jul 7, 2020
7dc5092
Error messages
kosinsky Jul 7, 2020
186a09c
Error messages
kosinsky Jul 7, 2020
b2365c1
Remove redundant ForceNew
kosinsky Jul 7, 2020
6738651
Enable monitor on create
kosinsky May 19, 2020
930b73b
Implement monitor changes
kosinsky May 19, 2020
42d8cf0
Error message clean up
kosinsky May 19, 2020
85824a6
Documentation for hadoop
kosinsky May 19, 2020
21e9d99
A bit of refactoring
kosinsky May 19, 2020
c9df321
Aze monioor HBase cluster
kosinsky May 19, 2020
b5cf744
Azure Monitor for InteractiveQuery cluster
kosinsky May 19, 2020
5fca7ae
Azure monitor for Kafka
kosinsky May 19, 2020
b1609cd
Azure monitor for Spark
kosinsky May 19, 2020
36f4e18
Azure monitor for Storm
kosinsky May 20, 2020
972c1b7
Azure monitor doc for all hdinsight resources
kosinsky May 20, 2020
da5845f
Ensure that basic and monitor tests use the same roles
kosinsky May 21, 2020
0b96308
Fixing linter errors
kosinsky May 21, 2020
dfa757a
Fix typo in debug output
kosinsky Jun 30, 2020
f5308cd
Moved extensionsClient
kosinsky Jul 1, 2020
0b89eb5
Return error if disabling monitor fails
kosinsky Jul 1, 2020
7350c63
Error messages
kosinsky Jul 7, 2020
de60a55
Error messages
kosinsky Jul 7, 2020
ef9b7a0
Error messages
kosinsky Jul 7, 2020
f9f25c6
Error messages
kosinsky Jul 7, 2020
033cb71
Error messages
kosinsky Jul 7, 2020
31c6188
post conflict rebase cleanup and catchup for hdinsight service
jackofallops Jul 8, 2020
2abd334
whitespace fixes
jackofallops Jul 8, 2020
e3d0f38
Merge branch 'hdi_azure_monitor' of github.com:kosinsky/terraform-pro…
kosinsky Jul 8, 2020
1902856
Validation for log_analytics_workspace_id
kosinsky Jul 8, 2020
bae25a4
Merge branch 'hdi_azure_monitor' of github.com:kosinsky/terraform-pro…
kosinsky Jul 8, 2020
6745f26
Fix bad merbge and move extensionsClient
kosinsky Jul 8, 2020
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
40 changes: 40 additions & 0 deletions azurerm/helpers/azure/hdinsight.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,34 @@ func SchemaHDInsightsExternalMetastore() *schema.Schema {
}
}

func SchemaHDInsightsMonitor() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"log_analytics_workspace_id": {
Type: schema.TypeString,
Required: true,
ForceNew: false,
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
},
jackofallops marked this conversation as resolved.
Show resolved Hide resolved
"primary_key": {
Type: schema.TypeString,
Required: true,
ForceNew: false,
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
Sensitive: true,
ValidateFunc: validation.StringIsNotEmpty,
// Azure doesn't return the key
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return (new == d.Get(k).(string)) && (old == "*****")
},
},
},
},
}
}

func ExpandHDInsightsConfigurations(input []interface{}) map[string]interface{} {
vs := input[0].(map[string]interface{})

Expand Down Expand Up @@ -253,6 +281,18 @@ func ExpandHDInsightsAmbariMetastore(input []interface{}) map[string]interface{}
}
}

func ExpandHDInsightsMonitor(input []interface{}) hdinsight.ClusterMonitoringRequest {
vs := input[0].(map[string]interface{})

workspace := vs["log_analytics_workspace_id"].(string)
key := vs["primary_key"].(string)

return hdinsight.ClusterMonitoringRequest{
WorkspaceID: utils.String(workspace),
PrimaryKey: utils.String(key),
}
}

func FlattenHDInsightsConfigurations(input map[string]*string) []interface{} {
enabled := false
if v, exists := input["restAuthCredential.isEnabled"]; exists && v != nil {
Expand Down
5 changes: 5 additions & 0 deletions azurerm/internal/services/hdinsight/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Client struct {
ApplicationsClient *hdinsight.ApplicationsClient
ClustersClient *hdinsight.ClustersClient
ConfigurationsClient *hdinsight.ConfigurationsClient
ExtensionsClient *hdinsight.ExtensionsClient
}

func NewClient(o *common.ClientOptions) *Client {
Expand All @@ -21,9 +22,13 @@ func NewClient(o *common.ClientOptions) *Client {
ConfigurationsClient := hdinsight.NewConfigurationsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&ConfigurationsClient.Client, o.ResourceManagerAuthorizer)

ExtensionsClient := hdinsight.NewExtensionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&ExtensionsClient.Client, o.ResourceManagerAuthorizer)

return &Client{
ApplicationsClient: &ApplicationsClient,
ClustersClient: &ClustersClient,
ConfigurationsClient: &ConfigurationsClient,
ExtensionsClient: &ExtensionsClient,
}
}
52 changes: 52 additions & 0 deletions azurerm/internal/services/hdinsight/common_hdinsight.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ func hdinsightClusterUpdate(clusterKind string, readFunc schema.ReadFunc) schema
}
}

if d.HasChange("monitor") {
log.Printf("[DEBUG] Chnage Azure Monitor for the HDInsight %q Cluster", clusterKind)
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
if v, ok := d.GetOk("monitor"); ok {
monitorRaw := v.([]interface{})
if err := enableHDInsightMonitoring(ctx, extensionsClient, resourceGroup, name, monitorRaw); err != nil {
return err
}
} else if err := disableHDInsightMonitoring(ctx, extensionsClient, resourceGroup, name); err != nil {
return nil
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
}
}

return readFunc(d, meta)
}
}
Expand Down Expand Up @@ -325,3 +338,42 @@ func flattenHDInsightsMetastores(d *schema.ResourceData, configurations map[stri
})
}
}

func flattenHDInsightMonitoring(monitor hdinsight.ClusterMonitoringResponse) []interface{} {
if *monitor.ClusterMonitoringEnabled {
return []interface{}{
map[string]string{
"log_analytics_workspace_id": *monitor.WorkspaceID,
"primary_key": "*****",
}}
}

return nil
}

func enableHDInsightMonitoring(ctx context.Context, client *hdinsight.ExtensionsClient, resourceGroup, name string, input []interface{}) error {
monitor := azure.ExpandHDInsightsMonitor(input)
future, err := client.EnableMonitoring(ctx, resourceGroup, name, monitor)
if err != nil {
return err
}

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

return nil
}

func disableHDInsightMonitoring(ctx context.Context, client *hdinsight.ExtensionsClient, resourceGroup, name string) error {
future, err := client.DisableMonitoring(ctx, resourceGroup, name)
if err != nil {
return err
}

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

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ func resourceArmHDInsightHadoopCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"monitor": azure.SchemaHDInsightsMonitor(),
},
}
}
Expand Down Expand Up @@ -309,6 +311,15 @@ func resourceArmHDInsightHadoopClusterCreate(d *schema.ResourceData, meta interf
}
}

// We can only enable monitoring after creation
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
if v, ok := d.GetOk("monitor"); ok {
monitorRaw := v.([]interface{})
if err := enableHDInsightMonitoring(ctx, extensionsClient, resourceGroup, name, monitorRaw); err != nil {
return err
}
}

return resourceArmHDInsightHadoopClusterRead(d, meta)
}

Expand Down Expand Up @@ -400,6 +411,15 @@ func resourceArmHDInsightHadoopClusterRead(d *schema.ResourceData, meta interfac
d.Set("https_endpoint", httpEndpoint)
sshEndpoint := azure.FindHDInsightConnectivityEndpoint("SSH", props.ConnectivityEndpoints)
d.Set("ssh_endpoint", sshEndpoint)

extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
kosinsky marked this conversation as resolved.
Show resolved Hide resolved

monitor, err := extensionsClient.GetMonitoringStatus(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error reading monitor configuation for HDInsight Hadoop Cluster %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.Set("monitor", flattenHDInsightMonitoring(monitor))
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func resourceArmHDInsightHBaseCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"monitor": azure.SchemaHDInsightsMonitor(),
},
}
}
Expand Down Expand Up @@ -214,6 +216,15 @@ func resourceArmHDInsightHBaseClusterCreate(d *schema.ResourceData, meta interfa

d.SetId(*read.ID)

// We can only enable monitoring after creation
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
if v, ok := d.GetOk("monitor"); ok {
monitorRaw := v.([]interface{})
if err := enableHDInsightMonitoring(ctx, extensionsClient, resourceGroup, name, monitorRaw); err != nil {
return err
}
}

return resourceArmHDInsightHBaseClusterRead(d, meta)
}

Expand Down Expand Up @@ -283,6 +294,15 @@ func resourceArmHDInsightHBaseClusterRead(d *schema.ResourceData, meta interface
d.Set("https_endpoint", httpEndpoint)
sshEndpoint := azure.FindHDInsightConnectivityEndpoint("SSH", props.ConnectivityEndpoints)
d.Set("ssh_endpoint", sshEndpoint)

extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
kosinsky marked this conversation as resolved.
Show resolved Hide resolved

monitor, err := extensionsClient.GetMonitoringStatus(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error reading monitor configuation for HDInsight Hadoop Cluster %q (Resource Group %q): %+v", name, resourceGroup, err)
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
}

d.Set("monitor", flattenHDInsightMonitoring(monitor))
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func resourceArmHDInsightInteractiveQueryCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"monitor": azure.SchemaHDInsightsMonitor(),
},
}
}
Expand Down Expand Up @@ -214,6 +216,15 @@ func resourceArmHDInsightInteractiveQueryClusterCreate(d *schema.ResourceData, m

d.SetId(*read.ID)

// We can only enable monitoring after creation
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
if v, ok := d.GetOk("monitor"); ok {
monitorRaw := v.([]interface{})
if err := enableHDInsightMonitoring(ctx, extensionsClient, resourceGroup, name, monitorRaw); err != nil {
return err
}
}

return resourceArmHDInsightInteractiveQueryClusterRead(d, meta)
}

Expand Down Expand Up @@ -283,6 +294,15 @@ func resourceArmHDInsightInteractiveQueryClusterRead(d *schema.ResourceData, met
d.Set("https_endpoint", httpEndpoint)
sshEndpoint := azure.FindHDInsightConnectivityEndpoint("SSH", props.ConnectivityEndpoints)
d.Set("ssh_endpoint", sshEndpoint)

extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
kosinsky marked this conversation as resolved.
Show resolved Hide resolved

monitor, err := extensionsClient.GetMonitoringStatus(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error reading monitor configuation for HDInsight Hadoop Cluster %q (Resource Group %q): %+v", name, resourceGroup, err)
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
}

d.Set("monitor", flattenHDInsightMonitoring(monitor))
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ func resourceArmHDInsightKafkaCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"monitor": azure.SchemaHDInsightsMonitor(),
},
}
}
Expand Down Expand Up @@ -215,6 +217,15 @@ func resourceArmHDInsightKafkaClusterCreate(d *schema.ResourceData, meta interfa

d.SetId(*read.ID)

// We can only enable monitoring after creation
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
if v, ok := d.GetOk("monitor"); ok {
monitorRaw := v.([]interface{})
if err := enableHDInsightMonitoring(ctx, extensionsClient, resourceGroup, name, monitorRaw); err != nil {
return err
}
}

return resourceArmHDInsightKafkaClusterRead(d, meta)
}

Expand Down Expand Up @@ -284,6 +295,15 @@ func resourceArmHDInsightKafkaClusterRead(d *schema.ResourceData, meta interface
d.Set("https_endpoint", httpEndpoint)
sshEndpoint := azure.FindHDInsightConnectivityEndpoint("SSH", props.ConnectivityEndpoints)
d.Set("ssh_endpoint", sshEndpoint)

extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
kosinsky marked this conversation as resolved.
Show resolved Hide resolved

monitor, err := extensionsClient.GetMonitoringStatus(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error reading monitor configuation for HDInsight Hadoop Cluster %q (Resource Group %q): %+v", name, resourceGroup, err)
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
}

d.Set("monitor", flattenHDInsightMonitoring(monitor))
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func resourceArmHDInsightSparkCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"monitor": azure.SchemaHDInsightsMonitor(),
},
}
}
Expand Down Expand Up @@ -214,6 +216,15 @@ func resourceArmHDInsightSparkClusterCreate(d *schema.ResourceData, meta interfa

d.SetId(*read.ID)

// We can only enable monitoring after creation
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
if v, ok := d.GetOk("monitor"); ok {
monitorRaw := v.([]interface{})
if err := enableHDInsightMonitoring(ctx, extensionsClient, resourceGroup, name, monitorRaw); err != nil {
return err
}
}

return resourceArmHDInsightSparkClusterRead(d, meta)
}

Expand Down Expand Up @@ -283,6 +294,15 @@ func resourceArmHDInsightSparkClusterRead(d *schema.ResourceData, meta interface
d.Set("https_endpoint", httpEndpoint)
sshEndpoint := azure.FindHDInsightConnectivityEndpoint("SSH", props.ConnectivityEndpoints)
d.Set("ssh_endpoint", sshEndpoint)

extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
kosinsky marked this conversation as resolved.
Show resolved Hide resolved

monitor, err := extensionsClient.GetMonitoringStatus(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error reading monitor configuation for HDInsight Hadoop Cluster %q (Resource Group %q): %+v", name, resourceGroup, err)
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
}

d.Set("monitor", flattenHDInsightMonitoring(monitor))
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func resourceArmHDInsightStormCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"monitor": azure.SchemaHDInsightsMonitor(),
},
}
}
Expand Down Expand Up @@ -212,6 +214,15 @@ func resourceArmHDInsightStormClusterCreate(d *schema.ResourceData, meta interfa

d.SetId(*read.ID)

// We can only enable monitoring after creation
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
if v, ok := d.GetOk("monitor"); ok {
monitorRaw := v.([]interface{})
if err := enableHDInsightMonitoring(ctx, extensionsClient, resourceGroup, name, monitorRaw); err != nil {
return err
}
}

return resourceArmHDInsightStormClusterRead(d, meta)
}

Expand Down Expand Up @@ -281,6 +292,15 @@ func resourceArmHDInsightStormClusterRead(d *schema.ResourceData, meta interface
d.Set("https_endpoint", httpEndpoint)
sshEndpoint := azure.FindHDInsightConnectivityEndpoint("SSH", props.ConnectivityEndpoints)
d.Set("ssh_endpoint", sshEndpoint)

extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
kosinsky marked this conversation as resolved.
Show resolved Hide resolved

monitor, err := extensionsClient.GetMonitoringStatus(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error reading monitor configuation for HDInsight Hadoop Cluster %q (Resource Group %q): %+v", name, resourceGroup, err)
kosinsky marked this conversation as resolved.
Show resolved Hide resolved
}

d.Set("monitor", flattenHDInsightMonitoring(monitor))
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down
Loading