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

Add aws_quicksight_group resource #8233

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
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ func Provider() terraform.ResourceProvider {
"aws_organizations_organizational_unit": resourceAwsOrganizationsOrganizationalUnit(),
"aws_placement_group": resourceAwsPlacementGroup(),
"aws_proxy_protocol_policy": resourceAwsProxyProtocolPolicy(),
"aws_quicksight_group": resourceAwsQuickSightGroup(),
"aws_ram_principal_association": resourceAwsRamPrincipalAssociation(),
"aws_ram_resource_association": resourceAwsRamResourceAssociation(),
"aws_ram_resource_share": resourceAwsRamResourceShare(),
Expand Down
187 changes: 187 additions & 0 deletions aws/resource_aws_quicksight_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
package aws

import (
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/quicksight"
)

func resourceAwsQuickSightGroup() *schema.Resource {
return &schema.Resource{
Create: resourceAwsQuickSightGroupCreate,
Read: resourceAwsQuickSightGroupRead,
Update: resourceAwsQuickSightGroupUpdate,
Delete: resourceAwsQuickSightGroupDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},

"aws_account_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"description": {
Type: schema.TypeString,
Optional: true,
},

"group_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"namespace": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "default",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While there are currently no other valid values for this attribute, it also doesn't support in-place updates either so we should include ForceNew: true for now. This can prevent potential issues in the future when other values are supported. 👍

Suggested change
Default: "default",
ForceNew: true,
Default: "default",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

ValidateFunc: validation.StringInSlice([]string{
"default",
}, false),
},
},
}
}

func resourceAwsQuickSightGroupCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).quicksightconn

awsAccountID := meta.(*AWSClient).accountid
namespace := d.Get("namespace").(string)

if v, ok := d.GetOk("aws_account_id"); ok {
awsAccountID = v.(string)
}

createOpts := &quicksight.CreateGroupInput{
AwsAccountId: aws.String(awsAccountID),
Namespace: aws.String(namespace),
GroupName: aws.String(d.Get("group_name").(string)),
}

if v, ok := d.GetOk("description"); ok {
createOpts.Description = aws.String(v.(string))
}

resp, err := conn.CreateGroup(createOpts)
if err != nil {
return fmt.Errorf("Error creating Quick Sight Group: %s", err)
}

d.SetId(fmt.Sprintf("%s/%s/%s", awsAccountID, namespace, aws.StringValue(resp.Group.GroupName)))

return resourceAwsQuickSightGroupRead(d, meta)
}

func resourceAwsQuickSightGroupRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).quicksightconn

awsAccountID, namespace, groupName, err := resourceAwsQuickSightGroupParseID(d.Id())
if err != nil {
return err
}

descOpts := &quicksight.DescribeGroupInput{
AwsAccountId: aws.String(awsAccountID),
Namespace: aws.String(namespace),
GroupName: aws.String(groupName),
}

resp, err := conn.DescribeGroup(descOpts)
if isAWSErr(err, quicksight.ErrCodeResourceNotFoundException, "") {
log.Printf("[WARN] Quick Sight Group %s is already gone", d.Id())
d.SetId("")
return nil
}
if err != nil {
return fmt.Errorf("Error describing Quick Sight Group (%s): %s", d.Id(), err)
}

d.Set("arn", resp.Group.Arn)
d.Set("aws_account_id", awsAccountID)
d.Set("group_name", resp.Group.GroupName)
d.Set("description", resp.Group.Description)
d.Set("namespace", namespace)

return nil
}

func resourceAwsQuickSightGroupUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).quicksightconn

awsAccountID, namespace, groupName, err := resourceAwsQuickSightGroupParseID(d.Id())
if err != nil {
return err
}

updateOpts := &quicksight.UpdateGroupInput{
AwsAccountId: aws.String(awsAccountID),
Namespace: aws.String(namespace),
GroupName: aws.String(groupName),
}

if v, ok := d.GetOk("description"); ok {
updateOpts.Description = aws.String(v.(string))
}

_, err = conn.UpdateGroup(updateOpts)
if isAWSErr(err, quicksight.ErrCodeResourceNotFoundException, "") {
log.Printf("[WARN] Quick Sight Group %s is already gone", d.Id())
d.SetId("")
return nil
}
if err != nil {
return fmt.Errorf("Error updating Quick Sight Group %s: %s", d.Id(), err)
}

return resourceAwsQuickSightGroupRead(d, meta)
}

func resourceAwsQuickSightGroupDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).quicksightconn

awsAccountID, namespace, groupName, err := resourceAwsQuickSightGroupParseID(d.Id())
if err != nil {
return err
}

deleteOpts := &quicksight.DeleteGroupInput{
AwsAccountId: aws.String(awsAccountID),
Namespace: aws.String(namespace),
GroupName: aws.String(groupName),
}

if _, err := conn.DeleteGroup(deleteOpts); err != nil {
if isAWSErr(err, quicksight.ErrCodeResourceNotFoundException, "") {
return nil
}
return fmt.Errorf("Error deleting Quick Sight Group %s: %s", d.Id(), err)
}

return nil
}

func resourceAwsQuickSightGroupParseID(id string) (string, string, string, error) {
parts := strings.SplitN(id, "/", 3)
if len(parts) < 3 || parts[0] == "" || parts[1] == "" || parts[2] == "" {
return "", "", "", fmt.Errorf("unexpected format of ID (%s), expected AWS_ACCOUNT_ID/NAMESPACE/GROUP_NAME", id)
}
return parts[0], parts[1], parts[2], nil
}
Loading