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

Mark Grafana API key as sensitive. #34105

Merged
merged 15 commits into from
Nov 16, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/34105.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_grafana_workspace_api_key: Change `key` to [`Sensitive`](https://developer.hashicorp.com/terraform/plugin/best-practices/sensitive-state#using-sensitive-flag-functionality)
```
1 change: 1 addition & 0 deletions .teamcity/scripts/provider_tests/acceptance_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ TF_ACC=1 go test \
./internal/tags/... \
./internal/tfresource/... \
./internal/types/... \
./internal/ujson/... \
./internal/vault/... \
./internal/verify/... \
-json -v -count=1 -parallel "%ACCTEST_PARALLELISM%" -timeout=0 -run=TestAcc
1 change: 1 addition & 0 deletions .teamcity/scripts/provider_tests/unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ go test \
./internal/tags/... \
./internal/tfresource/... \
./internal/types/... \
./internal/ujson/... \
./internal/vault/... \
./internal/verify/... \
-json
10 changes: 10 additions & 0 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,16 @@ func CheckResourceAttrJMESPair(nameFirst, keyFirst, jmesPath, nameSecond, keySec
}
}

// CheckResourceAttrContains ensures the Terraform state value contains the specified substr.
func CheckResourceAttrContains(name, key, substr string) resource.TestCheckFunc {
return resource.TestCheckResourceAttrWith(name, key, func(value string) error {
if strings.Contains(value, substr) {
return nil
}
return fmt.Errorf("%s: Attribute '%s' expected contains %#v, got %#v", name, key, substr, value)
})
}

// CheckResourceAttrHasPrefix ensures the Terraform state value has the specified prefix.
func CheckResourceAttrHasPrefix(name, key, prefix string) resource.TestCheckFunc {
return resource.TestCheckResourceAttrWith(name, key, func(value string) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/fms/managed_service_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/json"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/service/fms/ujson"
"github.com/hashicorp/terraform-provider-aws/internal/ujson"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)

Expand Down
55 changes: 55 additions & 0 deletions internal/service/grafana/grafana_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package grafana_test

import (
"testing"

"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func TestAccGrafana_serial(t *testing.T) {
t.Parallel()

testCases := map[string]map[string]func(t *testing.T){
"Workspace": {
"saml": testAccWorkspace_saml,
"sso": testAccWorkspace_sso,
"disappears": testAccWorkspace_disappears,
"organization": testAccWorkspace_organization,
"dataSources": testAccWorkspace_dataSources,
"permissionType": testAccWorkspace_permissionType,
"notificationDestinations": testAccWorkspace_notificationDestinations,
"tags": testAccWorkspace_tags,
"vpc": testAccWorkspace_vpc,
"configuration": testAccWorkspace_configuration,
"networkAccess": testAccWorkspace_networkAccess,
"version": testAccWorkspace_version,
},
"ApiKey": {
"basic": testAccWorkspaceAPIKey_basic,
},
"DataSource": {
"basic": testAccWorkspaceDataSource_basic,
},
"LicenseAssociation": {
"enterpriseFreeTrial": testAccLicenseAssociation_freeTrial,
},
"SamlConfiguration": {
"basic": testAccWorkspaceSAMLConfiguration_basic,
"loginValidity": testAccWorkspaceSAMLConfiguration_loginValidity,
"assertions": testAccWorkspaceSAMLConfiguration_assertions,
},
"RoleAssociation": {
"usersAdmin": testAccRoleAssociation_usersAdmin,
"usersEditor": testAccRoleAssociation_usersEditor,
"groupsAdmin": testAccRoleAssociation_groupsAdmin,
"groupsEditor": testAccRoleAssociation_groupsEditor,
"usersAndGroupsAdmin": testAccRoleAssociation_usersAndGroupsAdmin,
"usersAndGroupsEditor": testAccRoleAssociation_usersAndGroupsEditor,
},
}

acctest.RunSerialTests2Levels(t, testCases, 0)
}
11 changes: 6 additions & 5 deletions internal/service/grafana/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ func ResourceWorkspace() *schema.Resource {
},
},
"configuration": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: verify.SuppressEquivalentJSONDiffs,
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: verify.SuppressEquivalentJSONDiffs,
DiffSuppressOnRefresh: true,
StateFunc: func(v interface{}) string {
json, _ := structure.NormalizeJsonString(v)
return json
Expand Down
5 changes: 3 additions & 2 deletions internal/service/grafana/workspace_api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ func ResourceWorkspaceAPIKey() *schema.Resource {

Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
"key_name": {
Type: schema.TypeString,
Expand Down
53 changes: 4 additions & 49 deletions internal/service/grafana/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,6 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

func TestAccGrafana_serial(t *testing.T) {
t.Parallel()

testCases := map[string]map[string]func(t *testing.T){
"Workspace": {
"saml": testAccWorkspace_saml,
"sso": testAccWorkspace_sso,
"disappears": testAccWorkspace_disappears,
"organization": testAccWorkspace_organization,
"dataSources": testAccWorkspace_dataSources,
"permissionType": testAccWorkspace_permissionType,
"notificationDestinations": testAccWorkspace_notificationDestinations,
"tags": testAccWorkspace_tags,
"vpc": testAccWorkspace_vpc,
"configuration": testAccWorkspace_configuration,
"networkAccess": testAccWorkspace_networkAccess,
"version": testAccWorkspace_version,
},
"ApiKey": {
"basic": testAccWorkspaceAPIKey_basic,
},
"DataSource": {
"basic": testAccWorkspaceDataSource_basic,
},
"LicenseAssociation": {
"enterpriseFreeTrial": testAccLicenseAssociation_freeTrial,
},
"SamlConfiguration": {
"basic": testAccWorkspaceSAMLConfiguration_basic,
"loginValidity": testAccWorkspaceSAMLConfiguration_loginValidity,
"assertions": testAccWorkspaceSAMLConfiguration_assertions,
},
"RoleAssociation": {
"usersAdmin": testAccRoleAssociation_usersAdmin,
"usersEditor": testAccRoleAssociation_usersEditor,
"groupsAdmin": testAccRoleAssociation_groupsAdmin,
"groupsEditor": testAccRoleAssociation_groupsEditor,
"usersAndGroupsAdmin": testAccRoleAssociation_usersAndGroupsAdmin,
"usersAndGroupsEditor": testAccRoleAssociation_usersAndGroupsEditor,
},
}

acctest.RunSerialTests2Levels(t, testCases, 0)
}

func testAccWorkspace_saml(t *testing.T) {
ctx := acctest.Context(t)
var v managedgrafana.WorkspaceDescription
Expand Down Expand Up @@ -450,10 +405,10 @@ func testAccWorkspace_configuration(t *testing.T) {
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccWorkspaceConfig_configuration(rName, `{"unifiedAlerting": { "enabled": true }}`),
Config: testAccWorkspaceConfig_configuration(rName, `{"unifiedAlerting": { "enabled": true }, "plugins": {"pluginAdminEnabled": false}}`),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckWorkspaceExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "configuration", `{"unifiedAlerting":{"enabled":true}}`),
resource.TestCheckResourceAttr(resourceName, "configuration", `{"unifiedAlerting":{"enabled":true},"plugins":{"pluginAdminEnabled":false}}`),
),
},
{
Expand All @@ -462,10 +417,10 @@ func testAccWorkspace_configuration(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccWorkspaceConfig_configuration(rName, `{"unifiedAlerting": { "enabled": false }}`),
Config: testAccWorkspaceConfig_configuration(rName, `{"unifiedAlerting": { "enabled": false }, "plugins": {"pluginAdminEnabled": true}}`),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckWorkspaceExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "configuration", `{"unifiedAlerting":{"enabled":false}}`),
resource.TestCheckResourceAttr(resourceName, "configuration", `{"unifiedAlerting":{"enabled":false},"plugins":{"pluginAdminEnabled":true}}`),
),
},
},
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"testing"

"github.com/hashicorp/terraform-provider-aws/internal/service/fms/ujson"
"github.com/hashicorp/terraform-provider-aws/internal/ujson"
)

type quoteTest struct {
Expand Down
File renamed without changes.