Skip to content

Commit

Permalink
Merge pull request #31083 from tamiros/f-grafana-version-31078
Browse files Browse the repository at this point in the history
Enhancement: Add argument `grafana_version` to r/`aws_grafana_workspace`
  • Loading branch information
ewbankkit authored May 3, 2023
2 parents cd544f4 + 9d7cb21 commit d510408
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/31083.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_grafana_workspace: Make `grafana_version` optional so that its value can be specified in configuration
```
6 changes: 6 additions & 0 deletions internal/service/grafana/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func ResourceWorkspace() *schema.Resource {
},
"grafana_version": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Computed: true,
},
"name": {
Expand Down Expand Up @@ -211,6 +213,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{}))
}
Expand Down
40 changes: 40 additions & 0 deletions internal/service/grafana/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestAccGrafana_serial(t *testing.T) {
"vpc": testAccWorkspace_vpc,
"configuration": testAccWorkspace_configuration,
"networkAccess": testAccWorkspace_networkAccess,
"version": testAccWorkspace_version,
},
"ApiKey": {
"basic": testAccWorkspaceAPIKey_basic,
Expand Down Expand Up @@ -501,6 +502,33 @@ func testAccWorkspace_networkAccess(t *testing.T) {
})
}

func testAccWorkspace_version(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_version(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]
Expand Down Expand Up @@ -796,3 +824,15 @@ resource "aws_grafana_workspace" "test" {
}
`, configuration))
}

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"
authentication_providers = ["SAML"]
permission_type = "SERVICE_MANAGED"
role_arn = aws_iam_role.test.arn
grafana_version = %[1]q
}
`, version))
}
1 change: 1 addition & 0 deletions website/docs/r/grafana_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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`.
Expand Down

0 comments on commit d510408

Please sign in to comment.