From f2b88a51e51a46357bcb1f2893e6b96d99cb36cb Mon Sep 17 00:00:00 2001 From: djryanj Date: Thu, 23 Nov 2023 14:39:48 -0700 Subject: [PATCH 1/2] add grafana_major_version --- .../dashboard/dashboard_grafana_resource.go | 17 ++++++ .../dashboard_grafana_resource_test.go | 58 +++++++++++++++---- .../docs/r/dashboard_grafana.html.markdown | 54 ++++++++--------- 3 files changed, 91 insertions(+), 38 deletions(-) diff --git a/internal/services/dashboard/dashboard_grafana_resource.go b/internal/services/dashboard/dashboard_grafana_resource.go index 470e1cec3fde..f99758f8c823 100644 --- a/internal/services/dashboard/dashboard_grafana_resource.go +++ b/internal/services/dashboard/dashboard_grafana_resource.go @@ -34,6 +34,7 @@ type DashboardGrafanaModel struct { ZoneRedundancyEnabled bool `tfschema:"zone_redundancy_enabled"` Endpoint string `tfschema:"endpoint"` GrafanaVersion string `tfschema:"grafana_version"` + GrafanaMajorVersion string `tfschema:"grafana_major_version"` OutboundIPs []string `tfschema:"outbound_ip"` } @@ -116,6 +117,17 @@ func (r DashboardGrafanaResource) Arguments() map[string]*pluginsdk.Schema { Default: true, }, + "grafana_major_version": { + Type: pluginsdk.TypeString, + // TODO: make this field Required (with no default) in 4.0 + Optional: true, + ForceNew: true, + Default: "9", + ValidateFunc: validation.StringInSlice([]string{ + "9", "10", + }, false), + }, + "sku": { Type: pluginsdk.TypeString, Optional: true, @@ -211,6 +223,7 @@ func (r DashboardGrafanaResource) Create() sdk.ResourceFunc { AutoGeneratedDomainNameLabelScope: &model.AutoGeneratedDomainNameLabelScope, DeterministicOutboundIP: &deterministicOutboundIP, GrafanaIntegrations: expandGrafanaIntegrationsModel(model.AzureMonitorWorkspaceIntegrations), + GrafanaMajorVersion: &model.GrafanaMajorVersion, PublicNetworkAccess: &publicNetworkAccess, ZoneRedundancy: &zoneRedundancy, }, @@ -374,6 +387,10 @@ func (r DashboardGrafanaResource) Read() sdk.ResourceFunc { state.GrafanaVersion = *properties.GrafanaVersion } + if properties.GrafanaMajorVersion != nil { + state.GrafanaMajorVersion = *properties.GrafanaMajorVersion + } + if properties.OutboundIPs != nil { state.OutboundIPs = *properties.OutboundIPs } diff --git a/internal/services/dashboard/dashboard_grafana_resource_test.go b/internal/services/dashboard/dashboard_grafana_resource_test.go index ee194f969fe6..53c3be9a365f 100644 --- a/internal/services/dashboard/dashboard_grafana_resource_test.go +++ b/internal/services/dashboard/dashboard_grafana_resource_test.go @@ -61,6 +61,20 @@ func TestAccDashboardGrafana_complete(t *testing.T) { }) } +func TestAccDashboardGrafana_nonDefaultVersion(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_dashboard_grafana", "test") + r := DashboardGrafanaResource{} + data.ResourceSequentialTest(t, r, []acceptance.TestStep{ + { + Config: r.nonDefaultVersion(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccDashboardGrafana_update(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_dashboard_grafana", "test") r := DashboardGrafanaResource{} @@ -132,9 +146,10 @@ func (r DashboardGrafanaResource) basic(data acceptance.TestData) string { %s resource "azurerm_dashboard_grafana" "test" { - name = "a-dg-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location + name = "a-dg-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + grafana_major_version = "9" } `, template, data.RandomInteger) } @@ -145,24 +160,41 @@ func (r DashboardGrafanaResource) essential(data acceptance.TestData) string { %s resource "azurerm_dashboard_grafana" "test" { - name = "a-dg-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location + name = "a-dg-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + grafana_major_version = "9" sku = "Essential" } `, template, data.RandomInteger) } +func (r DashboardGrafanaResource) nonDefaultVersion(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_dashboard_grafana" "test" { + name = "a-dg-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + grafana_major_version = "10" + +} +`, template, data.RandomInteger) +} + func (r DashboardGrafanaResource) requiresImport(data acceptance.TestData) string { config := r.basic(data) return fmt.Sprintf(` %s resource "azurerm_dashboard_grafana" "import" { - name = azurerm_dashboard_grafana.test.name - resource_group_name = azurerm_dashboard_grafana.test.resource_group_name - location = azurerm_dashboard_grafana.test.location + name = azurerm_dashboard_grafana.test.name + resource_group_name = azurerm_dashboard_grafana.test.resource_group_name + location = azurerm_dashboard_grafana.test.location + grafana_major_version = "9" } `, config) } @@ -184,6 +216,7 @@ resource "azurerm_dashboard_grafana" "test" { api_key_enabled = true deterministic_outbound_ip_enabled = true public_network_access_enabled = false + grafana_major_version = "9" identity { type = "UserAssigned" @@ -207,9 +240,10 @@ func (r DashboardGrafanaResource) update(data acceptance.TestData) string { %s resource "azurerm_dashboard_grafana" "test" { - name = "a-dg-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location + name = "a-dg-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + grafana_major_version = "9" identity { type = "SystemAssigned" diff --git a/website/docs/r/dashboard_grafana.html.markdown b/website/docs/r/dashboard_grafana.html.markdown index e31735b94687..48b57cea26f8 100644 --- a/website/docs/r/dashboard_grafana.html.markdown +++ b/website/docs/r/dashboard_grafana.html.markdown @@ -40,74 +40,76 @@ resource "azurerm_dashboard_grafana" "example" { The following arguments are supported: -* `name` - (Required) Specifies the name which should be used for this Dashboard Grafana. Changing this forces a new Dashboard Grafana to be created. +- `name` - (Required) Specifies the name which should be used for this Dashboard Grafana. Changing this forces a new Dashboard Grafana to be created. -* `resource_group_name` - (Required) Specifies the name of the Resource Group where the Dashboard Grafana should exist. Changing this forces a new Dashboard Grafana to be created. +- `resource_group_name` - (Required) Specifies the name of the Resource Group where the Dashboard Grafana should exist. Changing this forces a new Dashboard Grafana to be created. -* `location` - (Required) Specifies the Azure Region where the Dashboard Grafana should exist. Changing this forces a new Dashboard Grafana to be created. +- `location` - (Required) Specifies the Azure Region where the Dashboard Grafana should exist. Changing this forces a new Dashboard Grafana to be created. -* `api_key_enabled` - (Optional) Whether to enable the api key setting of the Grafana instance. Defaults to `false`. +- `api_key_enabled` - (Optional) Whether to enable the api key setting of the Grafana instance. Defaults to `false`. -* `auto_generated_domain_name_label_scope` - (Optional) Scope for dns deterministic name hash calculation. The only possible value is `TenantReuse`. Defaults to `TenantReuse`. +- `auto_generated_domain_name_label_scope` - (Optional) Scope for dns deterministic name hash calculation. The only possible value is `TenantReuse`. Defaults to `TenantReuse`. -* `deterministic_outbound_ip_enabled` - (Optional) Whether to enable the Grafana instance to use deterministic outbound IPs. Defaults to `false`. +- `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. +- `grafana_major_version` - (Optional) Which major version of Grafana to deploy. Defaults to `9`. Possible values are `9`, `10`. Changing this forces a new resource to be created. -* `identity` - (Optional) An `identity` block as defined below. Changing this forces a new Dashboard Grafana to be created. +- `azure_monitor_workspace_integrations` - (Optional) A `azure_monitor_workspace_integrations` block as defined below. -* `public_network_access_enabled` - (Optional) Whether to enable traffic over the public interface. Defaults to `true`. +- `identity` - (Optional) An `identity` block as defined below. Changing this forces a new Dashboard Grafana to be created. -* `sku` - (Optional) The name of the SKU used for the Grafana instance. Possible value are `Standard` and `Essential`. Defaults to `Standard`. 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`. -* `tags` - (Optional) A mapping of tags which should be assigned to the Dashboard Grafana. +- `sku` - (Optional) The name of the SKU used for the Grafana instance. The only possible value is `Standard`. Defaults to `Standard`. Changing this forces a new Dashboard Grafana to be created. -* `zone_redundancy_enabled` - (Optional) Whether to enable the zone redundancy setting of the Grafana instance. Defaults to `false`. Changing this forces a new Dashboard Grafana to be created. +- `tags` - (Optional) A mapping of tags which should be assigned to the Dashboard Grafana. + +- `zone_redundancy_enabled` - (Optional) Whether to enable the zone redundancy setting of the Grafana instance. Defaults to `false`. Changing this forces a new Dashboard Grafana to be created. --- An `azure_monitor_workspace_integrations` block supports the following: -* `resource_id` - (Required) Specifies the resource ID of the connected Azure Monitor Workspace. +- `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. Possible values are `SystemAssigned`, `UserAssigned`. Changing this forces a new resource to be created. +- `type` - (Required) Specifies the type of Managed Service Identity. Possible values are `SystemAssigned`, `UserAssigned`. Changing this forces a new resource to be created. -* `identity_ids` - (Optional) Specifies the list of User Assigned Managed Service Identity IDs which should be assigned to this Dashboard Grafana. Changing this forces a new resource to be created. +- `identity_ids` - (Optional) Specifies the list of User Assigned Managed Service Identity IDs which should be assigned to this Dashboard Grafana. Changing this forces a new resource to be created. ## Attributes Reference In addition to the Arguments listed above - the following Attributes are exported: -* `id` - The ID of the Dashboard Grafana. +- `id` - The ID of the Dashboard Grafana. -* `endpoint` - The endpoint of the Grafana instance. +- `endpoint` - The endpoint of the Grafana instance. -* `grafana_version` - The Grafana software version. +- `grafana_version` - The full Grafana software semantic version deployed. -* `identity` - An `identity` block as defined below. +- `identity` - An `identity` block as defined below. -* `outbound_ip` - List of outbound IPs if deterministicOutboundIP is enabled. +- `outbound_ip` - List of outbound IPs if deterministicOutboundIP is enabled. --- An `identity` block exports the following: -* `principal_id` - The Principal ID associated with this Managed Service Identity. +- `principal_id` - The Principal ID associated with this Managed Service Identity. -* `tenant_id` - The Tenant ID associated with this Managed Service Identity. +- `tenant_id` - The Tenant ID associated with this Managed Service Identity. ## Timeouts The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: -* `create` - (Defaults to 30 minutes) Used when creating the Dashboard Grafana. -* `read` - (Defaults to 5 minutes) Used when retrieving the Dashboard Grafana. -* `update` - (Defaults to 30 minutes) Used when updating the Dashboard Grafana. -* `delete` - (Defaults to 30 minutes) Used when deleting the Dashboard Grafana. +- `create` - (Defaults to 30 minutes) Used when creating the Dashboard Grafana. +- `read` - (Defaults to 5 minutes) Used when retrieving the Dashboard Grafana. +- `update` - (Defaults to 30 minutes) Used when updating the Dashboard Grafana. +- `delete` - (Defaults to 30 minutes) Used when deleting the Dashboard Grafana. ## Import From d4f5a025e99c6ffc4a5f6515d42407df81d3a97d Mon Sep 17 00:00:00 2001 From: djryanj Date: Thu, 23 Nov 2023 14:57:56 -0700 Subject: [PATCH 2/2] fix terraform fmt --- .../services/dashboard/dashboard_grafana_resource_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/services/dashboard/dashboard_grafana_resource_test.go b/internal/services/dashboard/dashboard_grafana_resource_test.go index 53c3be9a365f..caff513f7d02 100644 --- a/internal/services/dashboard/dashboard_grafana_resource_test.go +++ b/internal/services/dashboard/dashboard_grafana_resource_test.go @@ -240,10 +240,10 @@ func (r DashboardGrafanaResource) update(data acceptance.TestData) string { %s resource "azurerm_dashboard_grafana" "test" { - name = "a-dg-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - grafana_major_version = "9" + name = "a-dg-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + grafana_major_version = "9" identity { type = "SystemAssigned"