From 404b3117ec49053cf439b6ded1a882f6615ca31a Mon Sep 17 00:00:00 2001 From: Tamir Date: Mon, 1 May 2023 11:06:29 +0300 Subject: [PATCH 1/8] add grafana_version to create. add doc --- internal/service/grafana/workspace.go | 5 +++++ website/docs/r/grafana_workspace.html.markdown | 1 + 2 files changed, 6 insertions(+) diff --git a/internal/service/grafana/workspace.go b/internal/service/grafana/workspace.go index 6854f446c04e..ab3d61c6a5b1 100644 --- a/internal/service/grafana/workspace.go +++ b/internal/service/grafana/workspace.go @@ -90,6 +90,7 @@ func ResourceWorkspace() *schema.Resource { }, "grafana_version": { Type: schema.TypeString, + Optional: true, Computed: true, }, "name": { @@ -211,6 +212,10 @@ func resourceWorkspaceCreate(ctx context.Context, d *schema.ResourceData, meta i input.WorkspaceName = aws.String(v.(string)) } + if v, ok := d.GetOk("grafana_version"); ok { + input.GrafanaVersion = aws.String(v.(string)) + } + if v, ok := d.GetOk("notification_destinations"); ok { input.WorkspaceNotificationDestinations = flex.ExpandStringList(v.([]interface{})) } diff --git a/website/docs/r/grafana_workspace.html.markdown b/website/docs/r/grafana_workspace.html.markdown index e4688131c7fc..3b6b808064bf 100644 --- a/website/docs/r/grafana_workspace.html.markdown +++ b/website/docs/r/grafana_workspace.html.markdown @@ -53,6 +53,7 @@ The following arguments are optional: * `configuration` - (Optional) The configuration string for the workspace that you create. For more information about the format and configuration options available, see [Working in your Grafana workspace](https://docs.aws.amazon.com/grafana/latest/userguide/AMG-configure-workspace.html). * `data_sources` - (Optional) The data sources for the workspace. Valid values are `AMAZON_OPENSEARCH_SERVICE`, `ATHENA`, `CLOUDWATCH`, `PROMETHEUS`, `REDSHIFT`, `SITEWISE`, `TIMESTREAM`, `XRAY` * `description` - (Optional) The workspace description. +* `grafana_version` - (Optional) Specifies the version of Grafana to support in the new workspace. Supported values are 8.4 and 9.4. If not specified, will use the latest version available. * `name` - (Optional) The Grafana workspace name. * `network_access_control` - (Optional) Configuration for network access to your workspace.See [Network Access Control](#network-access-control) below. * `notification_destinations` - (Optional) The notification destinations. If a data source is specified here, Amazon Managed Grafana will create IAM roles and permissions needed to use these destinations. Must be set to `SNS`. From 7ee8b3fb974caec9bebe4f033a1de8176614282e Mon Sep 17 00:00:00 2001 From: Tamir Date: Mon, 1 May 2023 11:18:45 +0300 Subject: [PATCH 2/8] apparently it defaults to the older version 8.4 instead of the new... in the web console it is the newer. go figure --- website/docs/r/grafana_workspace.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/grafana_workspace.html.markdown b/website/docs/r/grafana_workspace.html.markdown index 3b6b808064bf..5ad92c7811a7 100644 --- a/website/docs/r/grafana_workspace.html.markdown +++ b/website/docs/r/grafana_workspace.html.markdown @@ -53,7 +53,7 @@ The following arguments are optional: * `configuration` - (Optional) The configuration string for the workspace that you create. For more information about the format and configuration options available, see [Working in your Grafana workspace](https://docs.aws.amazon.com/grafana/latest/userguide/AMG-configure-workspace.html). * `data_sources` - (Optional) The data sources for the workspace. Valid values are `AMAZON_OPENSEARCH_SERVICE`, `ATHENA`, `CLOUDWATCH`, `PROMETHEUS`, `REDSHIFT`, `SITEWISE`, `TIMESTREAM`, `XRAY` * `description` - (Optional) The workspace description. -* `grafana_version` - (Optional) Specifies the version of Grafana to support in the new workspace. Supported values are 8.4 and 9.4. If not specified, will use the latest version available. +* `grafana_version` - (Optional) Specifies the version of Grafana to support in the new workspace. Supported values are 8.4 and 9.4. If not specified, will use the 8.4. * `name` - (Optional) The Grafana workspace name. * `network_access_control` - (Optional) Configuration for network access to your workspace.See [Network Access Control](#network-access-control) below. * `notification_destinations` - (Optional) The notification destinations. If a data source is specified here, Amazon Managed Grafana will create IAM roles and permissions needed to use these destinations. Must be set to `SNS`. From 98d8ac34811c3c05fddfa151d33d19ef08d33d8e Mon Sep 17 00:00:00 2001 From: Tamir Date: Mon, 1 May 2023 11:19:11 +0300 Subject: [PATCH 3/8] force recreation when changing. upgrading not supported atm it seems --- internal/service/grafana/workspace.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/service/grafana/workspace.go b/internal/service/grafana/workspace.go index ab3d61c6a5b1..f3aafccc2ff5 100644 --- a/internal/service/grafana/workspace.go +++ b/internal/service/grafana/workspace.go @@ -90,6 +90,7 @@ func ResourceWorkspace() *schema.Resource { }, "grafana_version": { Type: schema.TypeString, + ForceNew: true, Optional: true, Computed: true, }, From 941e0637d7fa1ce7e8b70ed21d4f1b99b225d652 Mon Sep 17 00:00:00 2001 From: Tamir Date: Mon, 1 May 2023 12:10:44 +0300 Subject: [PATCH 4/8] add test --- internal/service/grafana/workspace_test.go | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/internal/service/grafana/workspace_test.go b/internal/service/grafana/workspace_test.go index ae398568efb5..ef98a6b00e11 100644 --- a/internal/service/grafana/workspace_test.go +++ b/internal/service/grafana/workspace_test.go @@ -32,6 +32,7 @@ func TestAccGrafana_serial(t *testing.T) { "vpc": testAccWorkspace_vpc, "configuration": testAccWorkspace_configuration, "networkAccess": testAccWorkspace_networkAccess, + "grafanaVersion": testAccWorkspace_grafanaVersion, }, "ApiKey": { "basic": testAccWorkspaceAPIKey_basic, @@ -501,6 +502,33 @@ func testAccWorkspace_networkAccess(t *testing.T) { }) } +func testAccWorkspace_grafanaVersion(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_grafana_workspace.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, managedgrafana.EndpointsID) }, + ErrorCheck: acctest.ErrorCheck(t, managedgrafana.EndpointsID), + CheckDestroy: testAccCheckWorkspaceDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccWorkspaceConfig_grafanaVersion(rName, "9.4"), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckWorkspaceExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "grafana_version", "9.4"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckWorkspaceExists(ctx context.Context, name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] @@ -796,3 +824,15 @@ resource "aws_grafana_workspace" "test" { } `, configuration)) } + +func testAccWorkspaceConfig_grafanaVersion(rName, version string) string { + return acctest.ConfigCompose(testAccWorkspaceConfig_base(rName), fmt.Sprintf(` +resource "aws_grafana_workspace" "test" { + account_access_type = "CURRENT_ACCOUNT" + authentication_providers = ["SAML"] + permission_type = "SERVICE_MANAGED" + role_arn = aws_iam_role.test.arn + grafana_version = %[1]q +} +`, version)) +} From 29be39dfcedba9e3d347bf737fd618a0e1945df9 Mon Sep 17 00:00:00 2001 From: Tamir Date: Mon, 1 May 2023 12:19:00 +0300 Subject: [PATCH 5/8] fix check error --- internal/service/grafana/workspace_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/grafana/workspace_test.go b/internal/service/grafana/workspace_test.go index ef98a6b00e11..4b4b5100f202 100644 --- a/internal/service/grafana/workspace_test.go +++ b/internal/service/grafana/workspace_test.go @@ -32,7 +32,7 @@ func TestAccGrafana_serial(t *testing.T) { "vpc": testAccWorkspace_vpc, "configuration": testAccWorkspace_configuration, "networkAccess": testAccWorkspace_networkAccess, - "grafanaVersion": testAccWorkspace_grafanaVersion, + "version": testAccWorkspace_version, }, "ApiKey": { "basic": testAccWorkspaceAPIKey_basic, @@ -502,7 +502,7 @@ func testAccWorkspace_networkAccess(t *testing.T) { }) } -func testAccWorkspace_grafanaVersion(t *testing.T) { +func testAccWorkspace_version(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_grafana_workspace.test" @@ -514,7 +514,7 @@ func testAccWorkspace_grafanaVersion(t *testing.T) { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccWorkspaceConfig_grafanaVersion(rName, "9.4"), + Config: testAccWorkspaceConfig_version(rName, "9.4"), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckWorkspaceExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "grafana_version", "9.4"), @@ -825,7 +825,7 @@ resource "aws_grafana_workspace" "test" { `, configuration)) } -func testAccWorkspaceConfig_grafanaVersion(rName, version string) string { +func testAccWorkspaceConfig_version(rName, version string) string { return acctest.ConfigCompose(testAccWorkspaceConfig_base(rName), fmt.Sprintf(` resource "aws_grafana_workspace" "test" { account_access_type = "CURRENT_ACCOUNT" From 04b967a50da69a685ebdb8a6658861fefb07041b Mon Sep 17 00:00:00 2001 From: Tamir Date: Mon, 1 May 2023 12:19:08 +0300 Subject: [PATCH 6/8] add the migration tool to the documentation --- website/docs/r/grafana_workspace.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/grafana_workspace.html.markdown b/website/docs/r/grafana_workspace.html.markdown index 5ad92c7811a7..448ac4c8d800 100644 --- a/website/docs/r/grafana_workspace.html.markdown +++ b/website/docs/r/grafana_workspace.html.markdown @@ -53,7 +53,7 @@ The following arguments are optional: * `configuration` - (Optional) The configuration string for the workspace that you create. For more information about the format and configuration options available, see [Working in your Grafana workspace](https://docs.aws.amazon.com/grafana/latest/userguide/AMG-configure-workspace.html). * `data_sources` - (Optional) The data sources for the workspace. Valid values are `AMAZON_OPENSEARCH_SERVICE`, `ATHENA`, `CLOUDWATCH`, `PROMETHEUS`, `REDSHIFT`, `SITEWISE`, `TIMESTREAM`, `XRAY` * `description` - (Optional) The workspace description. -* `grafana_version` - (Optional) Specifies the version of Grafana to support in the new workspace. Supported values are 8.4 and 9.4. If not specified, will use the 8.4. +* `grafana_version` - (Optional) Specifies the version of Grafana to support in the new workspace. Supported values are `8.4` and `9.4`. If not specified, defaults to `8.4`. Upgrading the workspace version isn't supported, however it's possible to copy content from the old version to the new one using AWS official [migration tool](https://github.com/aws-observability/amazon-managed-grafana-migrator). * `name` - (Optional) The Grafana workspace name. * `network_access_control` - (Optional) Configuration for network access to your workspace.See [Network Access Control](#network-access-control) below. * `notification_destinations` - (Optional) The notification destinations. If a data source is specified here, Amazon Managed Grafana will create IAM roles and permissions needed to use these destinations. Must be set to `SNS`. From 9938da9ed87bf7c4d443922678a53b00e524b940 Mon Sep 17 00:00:00 2001 From: Tamir Date: Mon, 1 May 2023 12:20:22 +0300 Subject: [PATCH 7/8] add cl --- .changelog/31083.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/31083.txt diff --git a/.changelog/31083.txt b/.changelog/31083.txt new file mode 100644 index 000000000000..bbb3a104d4b9 --- /dev/null +++ b/.changelog/31083.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_grafana_workspace: Add optional argument `grafana_version` +``` From 9d7cb21fb430204c98a1009ffc2527d6feb1020d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 3 May 2023 08:00:17 -0400 Subject: [PATCH 8/8] Tweak CHANGELOG entry. --- .changelog/31083.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/31083.txt b/.changelog/31083.txt index bbb3a104d4b9..ef82db5c8617 100644 --- a/.changelog/31083.txt +++ b/.changelog/31083.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/aws_grafana_workspace: Add optional argument `grafana_version` +resource/aws_grafana_workspace: Make `grafana_version` optional so that its value can be specified in configuration ```