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 17 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 @@ -164,6 +164,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 @@ -261,6 +289,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 := true

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,
}
}
51 changes: 51 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,18 @@ func hdinsightClusterUpdate(clusterKind string, readFunc schema.ReadFunc) schema
}
}

if d.HasChange("monitor") {
log.Printf("[DEBUG] Change Azure Monitor for the HDInsight %q Cluster", clusterKind)
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 err
}
}
if d.HasChange("gateway") {
log.Printf("[DEBUG] Updating the HDInsight %q Cluster gateway", clusterKind)
vs := d.Get("gateway").([]interface{})[0].(map[string]interface{})
Expand Down Expand Up @@ -348,3 +360,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 @@ -179,12 +179,15 @@ func resourceArmHDInsightHadoopCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"monitor": azure.SchemaHDInsightsMonitor(),
},
}
}

func resourceArmHDInsightHadoopClusterCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).HDInsight.ClustersClient
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -308,12 +311,21 @@ func resourceArmHDInsightHadoopClusterCreate(d *schema.ResourceData, meta interf
}
}

// We can only enable monitoring after creation
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)
}

func resourceArmHDInsightHadoopClusterRead(d *schema.ResourceData, meta interface{}) error {
clustersClient := meta.(*clients.Client).HDInsight.ClustersClient
configurationsClient := meta.(*clients.Client).HDInsight.ConfigurationsClient
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

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

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 @@ -117,12 +117,15 @@ func resourceArmHDInsightHBaseCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"monitor": azure.SchemaHDInsightsMonitor(),
},
}
}

func resourceArmHDInsightHBaseClusterCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).HDInsight.ClustersClient
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -213,12 +216,21 @@ func resourceArmHDInsightHBaseClusterCreate(d *schema.ResourceData, meta interfa

d.SetId(*read.ID)

// We can only enable monitoring after creation
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)
}

func resourceArmHDInsightHBaseClusterRead(d *schema.ResourceData, meta interface{}) error {
clustersClient := meta.(*clients.Client).HDInsight.ClustersClient
configurationsClient := meta.(*clients.Client).HDInsight.ConfigurationsClient
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

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

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,12 +117,15 @@ func resourceArmHDInsightInteractiveQueryCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"monitor": azure.SchemaHDInsightsMonitor(),
},
}
}

func resourceArmHDInsightInteractiveQueryClusterCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).HDInsight.ClustersClient
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -213,12 +216,21 @@ func resourceArmHDInsightInteractiveQueryClusterCreate(d *schema.ResourceData, m

d.SetId(*read.ID)

// We can only enable monitoring after creation
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)
}

func resourceArmHDInsightInteractiveQueryClusterRead(d *schema.ResourceData, meta interface{}) error {
clustersClient := meta.(*clients.Client).HDInsight.ClustersClient
configurationsClient := meta.(*clients.Client).HDInsight.ConfigurationsClient
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

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

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,12 +118,15 @@ func resourceArmHDInsightKafkaCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"monitor": azure.SchemaHDInsightsMonitor(),
},
}
}

func resourceArmHDInsightKafkaClusterCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).HDInsight.ClustersClient
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -214,12 +217,21 @@ func resourceArmHDInsightKafkaClusterCreate(d *schema.ResourceData, meta interfa

d.SetId(*read.ID)

// We can only enable monitoring after creation
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)
}

func resourceArmHDInsightKafkaClusterRead(d *schema.ResourceData, meta interface{}) error {
clustersClient := meta.(*clients.Client).HDInsight.ClustersClient
configurationsClient := meta.(*clients.Client).HDInsight.ConfigurationsClient
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

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

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,12 +117,15 @@ func resourceArmHDInsightSparkCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"monitor": azure.SchemaHDInsightsMonitor(),
},
}
}

func resourceArmHDInsightSparkClusterCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).HDInsight.ClustersClient
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -213,12 +216,21 @@ func resourceArmHDInsightSparkClusterCreate(d *schema.ResourceData, meta interfa

d.SetId(*read.ID)

// We can only enable monitoring after creation
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)
}

func resourceArmHDInsightSparkClusterRead(d *schema.ResourceData, meta interface{}) error {
clustersClient := meta.(*clients.Client).HDInsight.ClustersClient
configurationsClient := meta.(*clients.Client).HDInsight.ConfigurationsClient
extensionsClient := meta.(*clients.Client).HDInsight.ExtensionsClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

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

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