-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
bflad
merged 1 commit into
hashicorp:master
from
teraken0509:feature/add-support-for-aws_quicksight_group-resource
Jul 18, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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. 👍There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.