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

r/aws_quicksight_user: allow custom namespaces #23607

Merged
merged 3 commits into from
Mar 15, 2022
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
3 changes: 3 additions & 0 deletions .changelog/23607.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_quicksight_user: Allow custom values for `namespace`
```
1 change: 1 addition & 0 deletions docs/contributing/maintaining.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ Environment variables (beyond standard AWS Go SDK ones) used by acceptance testi
| `GCM_API_KEY` | API Key for Google Cloud Messaging in Pinpoint and SNS Platform Application testing. |
| `GITHUB_TOKEN` | GitHub token for CodePipeline testing. |
| `MACIE_MEMBER_ACCOUNT_ID` | Identifier of AWS Account for Macie Member testing. **DEPRECATED:** Should be replaced with standard alternate account handling for tests. |
| `QUICKSIGHT_NAMESPACE` | QuickSight namespace name for testing. |
| `ROUTE53DOMAINS_DOMAIN_NAME` | Registered domain for Route 53 Domains testing. |
| `SAGEMAKER_IMAGE_VERSION_BASE_IMAGE` | Sagemaker base image to use for tests. |
| `SERVICEQUOTAS_INCREASE_ON_CREATE_QUOTA_CODE` | Quota Code for Service Quotas testing (submits support case). |
Expand Down
8 changes: 5 additions & 3 deletions internal/service/quicksight/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package quicksight
import (
"fmt"
"log"
"regexp"
"strings"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -60,9 +61,10 @@ func ResourceUser() *schema.Resource {
Optional: true,
ForceNew: true,
Default: "default",
ValidateFunc: validation.StringInSlice([]string{
"default",
}, false),
ValidateFunc: validation.All(
validation.StringLenBetween(1, 63),
validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9._-]*$`), "must contain only alphanumeric characters, hyphens, underscores, and periods"),
),
},

"session_name": {
Expand Down
44 changes: 44 additions & 0 deletions internal/service/quicksight/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package quicksight_test

import (
"fmt"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -79,6 +80,34 @@ func TestAccQuickSightUser_withInvalidFormattedEmailStillWorks(t *testing.T) {
})
}

func TestAccQuickSightUser_withNamespace(t *testing.T) {
key := "QUICKSIGHT_NAMESPACE"
namespace := os.Getenv(key)
if namespace == "" {
t.Skipf("Environment variable %s is not set", key)
}

var user quicksight.User
rName := "tfacctest" + sdkacctest.RandString(10)
resourceName := "aws_quicksight_user." + rName

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, quicksight.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckQuickSightUserDestroy,
Steps: []resource.TestStep{
{
Config: testAccUserWithNamespaceConfig(rName, namespace),
Check: resource.ComposeTestCheckFunc(
testAccCheckQuickSightUserExists(resourceName, &user),
resource.TestCheckResourceAttr(resourceName, "namespace", namespace),
),
},
},
})
}

func TestAccQuickSightUser_disappears(t *testing.T) {
var user quicksight.User
rName := "tfacctest" + sdkacctest.RandString(10)
Expand Down Expand Up @@ -208,6 +237,21 @@ resource "aws_quicksight_user" %[1]q {
`, rName, email)
}

func testAccUserWithNamespaceConfig(rName, namespace string) string {
return fmt.Sprintf(`
data "aws_caller_identity" "current" {}

resource "aws_quicksight_user" %[1]q {
aws_account_id = data.aws_caller_identity.current.account_id
user_name = %[1]q
email = %[2]q
namespace = %[3]q
identity_type = "QUICKSIGHT"
user_role = "READER"
}
`, rName, acctest.DefaultEmailAddress, namespace)
}

func testAccUserConfig(rName string) string {
return testAccUserWithEmailConfig(rName, acctest.DefaultEmailAddress)
}
3 changes: 2 additions & 1 deletion website/docs/r/quicksight_user.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Resource for managing QuickSight User
resource "aws_quicksight_user" "example" {
session_name = "an-author"
email = "[email protected]"
namespace = "foo"
identity_type = "IAM"
iam_arn = "arn:aws:iam::123456789012:user/Example"
user_role = "AUTHOR"
Expand All @@ -33,7 +34,7 @@ The following arguments are supported:
* `user_name` - (Optional) The Amazon QuickSight user name that you want to create for the user you are registering. Only valid for registering a user with `identity_type` set to `QUICKSIGHT`.
* `aws_account_id` - (Optional) The ID for the AWS account that the user is in. Currently, you use the ID for the AWS account that contains your Amazon QuickSight account.
* `iam_arn` - (Optional) The ARN of the IAM user or role that you are registering with Amazon QuickSight.
* `namespace` - (Optional) The namespace. Currently, you should set this to `default`.
* `namespace` - (Optional) The Amazon Quicksight namespace to create the user in. Defaults to `default`.
* `session_name` - (Optional) The name of the IAM session to use when assuming roles that can embed QuickSight dashboards. Only valid for registering users using an assumed IAM role. Additionally, if registering multiple users using the same IAM role, each user needs to have a unique session name.

## Attributes Reference
Expand Down