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_dashboard_grafana - Support grafana_integrations #20102

Merged
merged 2 commits into from
Feb 6, 2023
Merged
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
5 changes: 4 additions & 1 deletion .teamcity/components/settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ var serviceTestConfigurationOverrides = mapOf(
// Custom Providers is only available in certain locations
"customproviders" to testConfiguration(locationOverride = LocationConfiguration("eastus", "westus2", "westeurope", true)),

// Datadog is available only in WestUS2 region
// Dashboard is only available in certain locations
"dashboard" to testConfiguration(locationOverride = LocationConfiguration("westeurope", "westus2", "eastus2", false)),

// Datadog is available only in WestUS2 region
"datadog" to testConfiguration(locationOverride = LocationConfiguration("westus2", "westus2", "centraluseuap", false)),

// data factory uses NC class VMs which are not available in eastus2
Expand Down
71 changes: 71 additions & 0 deletions internal/services/dashboard/dashboard_grafana_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type DashboardGrafanaModel struct {
ApiKeyEnabled bool `tfschema:"api_key_enabled"`
AutoGeneratedDomainNameLabelScope grafanaresource.AutoGeneratedDomainNameLabelScope `tfschema:"auto_generated_domain_name_label_scope"`
DeterministicOutboundIPEnabled bool `tfschema:"deterministic_outbound_ip_enabled"`
AzureMonitorWorkspaceIntegrations []AzureMonitorWorkspaceIntegrationModel `tfschema:"azure_monitor_workspace_integrations"`
Location string `tfschema:"location"`
PublicNetworkAccessEnabled bool `tfschema:"public_network_access_enabled"`
Sku string `tfschema:"sku"`
Expand All @@ -33,6 +34,10 @@ type DashboardGrafanaModel struct {
OutboundIPs []string `tfschema:"outbound_ip"`
}

type AzureMonitorWorkspaceIntegrationModel struct {
ResourceId string `tfschema:"resource_id"`
}

type DashboardGrafanaResource struct{}

var _ sdk.ResourceWithUpdate = DashboardGrafanaResource{}
Expand Down Expand Up @@ -86,6 +91,20 @@ func (r DashboardGrafanaResource) Arguments() map[string]*pluginsdk.Schema {
Default: false,
},

"azure_monitor_workspace_integrations": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"resource_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},

"identity": commonschema.SystemAssignedIdentityOptionalForceNew(),

"public_network_access_enabled": {
Expand Down Expand Up @@ -187,6 +206,7 @@ func (r DashboardGrafanaResource) Create() sdk.ResourceFunc {
ApiKey: &apiKey,
AutoGeneratedDomainNameLabelScope: &model.AutoGeneratedDomainNameLabelScope,
DeterministicOutboundIP: &deterministicOutboundIP,
GrafanaIntegrations: expandGrafanaIntegrationsModel(model.AzureMonitorWorkspaceIntegrations),
PublicNetworkAccess: &publicNetworkAccess,
ZoneRedundancy: &zoneRedundancy,
},
Expand Down Expand Up @@ -254,6 +274,10 @@ func (r DashboardGrafanaResource) Update() sdk.ResourceFunc {
properties.Properties.DeterministicOutboundIP = &deterministicOutboundIP
}

if metadata.ResourceData.HasChange("azure_monitor_workspace_integrations") {
properties.Properties.GrafanaIntegrations = expandGrafanaIntegrationsModel(model.AzureMonitorWorkspaceIntegrations)
}

if metadata.ResourceData.HasChange("public_network_access_enabled") {
publicNetworkAccess := grafanaresource.PublicNetworkAccessDisabled
if model.PublicNetworkAccessEnabled {
Expand Down Expand Up @@ -340,6 +364,10 @@ func (r DashboardGrafanaResource) Read() sdk.ResourceFunc {
state.Endpoint = *properties.Endpoint
}

if properties.GrafanaIntegrations != nil {
state.AzureMonitorWorkspaceIntegrations = flattenAzureMonitorWorkspaceIntegrationModelArray(properties.GrafanaIntegrations.AzureMonitorWorkspaceIntegrations)
}

if properties.GrafanaVersion != nil {
state.GrafanaVersion = *properties.GrafanaVersion
}
Expand Down Expand Up @@ -398,6 +426,30 @@ func (r DashboardGrafanaResource) Delete() sdk.ResourceFunc {
}
}

func expandGrafanaIntegrationsModel(inputList []AzureMonitorWorkspaceIntegrationModel) *grafanaresource.GrafanaIntegrations {
if len(inputList) == 0 {
return nil
}

return &grafanaresource.GrafanaIntegrations{
AzureMonitorWorkspaceIntegrations: expandAzureMonitorWorkspaceIntegrationModelArray(inputList),
}
}

func expandAzureMonitorWorkspaceIntegrationModelArray(inputList []AzureMonitorWorkspaceIntegrationModel) *[]grafanaresource.AzureMonitorWorkspaceIntegration {
var outputList []grafanaresource.AzureMonitorWorkspaceIntegration
for _, v := range inputList {
input := v
output := grafanaresource.AzureMonitorWorkspaceIntegration{
AzureMonitorWorkspaceResourceId: &input.ResourceId,
}

outputList = append(outputList, output)
}

return &outputList
}

func expandLegacySystemAndUserAssignedMap(input []interface{}) *identity.LegacySystemAndUserAssignedMap {
identityValue, err := identity.ExpandSystemAssigned(input)
if err != nil {
Expand All @@ -409,6 +461,25 @@ func expandLegacySystemAndUserAssignedMap(input []interface{}) *identity.LegacyS
}
}

func flattenAzureMonitorWorkspaceIntegrationModelArray(inputList *[]grafanaresource.AzureMonitorWorkspaceIntegration) []AzureMonitorWorkspaceIntegrationModel {
var outputList []AzureMonitorWorkspaceIntegrationModel
if inputList == nil {
return outputList
}

for _, input := range *inputList {
output := AzureMonitorWorkspaceIntegrationModel{}

if input.AzureMonitorWorkspaceResourceId != nil {
output.ResourceId = *input.AzureMonitorWorkspaceResourceId
}

outputList = append(outputList, output)
}

return outputList
}

func flattenLegacySystemAndUserAssignedMap(input *identity.LegacySystemAndUserAssignedMap) *[]interface{} {
if input == nil {
return &[]interface{}{}
Expand Down
16 changes: 14 additions & 2 deletions internal/services/dashboard/dashboard_grafana_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ resource "azurerm_dashboard_grafana" "import" {
func (r DashboardGrafanaResource) complete(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s
%[1]s

resource "azurerm_dashboard_grafana" "test" {
name = "a-dg-%d"
name = "a-dg-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
api_key_enabled = true
Expand All @@ -152,6 +152,10 @@ resource "azurerm_dashboard_grafana" "test" {
type = "SystemAssigned"
}

azure_monitor_workspace_integrations {
resource_id = "${azurerm_resource_group.test.id}/providers/microsoft.monitor/accounts/a-mwr-%[2]d"
}

tags = {
key = "value"
}
Expand All @@ -173,6 +177,14 @@ resource "azurerm_dashboard_grafana" "test" {
type = "SystemAssigned"
}

azure_monitor_workspace_integrations {
resource_id = "${azurerm_resource_group.test.id}/providers/microsoft.monitor/accounts/a-mwr-%[2]d"
}

azure_monitor_workspace_integrations {
resource_id = "${azurerm_resource_group.test.id}/providers/microsoft.monitor/accounts/a-mwr-%[2]d-2"
}

tags = {
key2 = "value2"
}
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/dashboard_grafana.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ The following arguments are supported:

* `deterministic_outbound_ip_enabled` - (Optional) Whether to enable the Grafana instance to use deterministic outbound IPs. Defaults to `false`.

* `azure_monitor_workspace_integrations` - (Optional) A `azure_monitor_workspace_integrations` block as defined below.

* `identity` - (Optional) An `identity` block as defined below. Changing this forces a new Dashboard Grafana to be created.

* `public_network_access_enabled` - (Optional) Whether to enable traffic over the public interface. Defaults to `true`.
Expand All @@ -64,6 +66,12 @@ The following arguments are supported:

---

An `azure_monitor_workspace_integrations` block supports the following:

* `resource_id` - (Required) Specifies the resource ID of the connected Azure Monitor Workspace.

---

An `identity` block supports the following:

* `type` - (Required) Specifies the type of Managed Service Identity. The only possible values is `SystemAssigned`. Changing this forces a new resource to be created.
Expand Down