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

resource/aws_cloudformation_stack_set: Adds guidance about required permissions to error message #37069

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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/37069.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_cloudformation_stack_set: Adds guidance on permissions when using delegated administrator account
```
9 changes: 8 additions & 1 deletion internal/service/cloudformation/stack_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
Expand Down Expand Up @@ -319,7 +320,13 @@ func resourceStackSetCreate(ctx context.Context, d *schema.ResourceData, meta in
)

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating CloudFormation StackSet (%s): %s", name, err)
var detail string
if tfawserr.ErrMessageContains(err, errCodeValidationError, "Account used is not a delegated administrator") {
detail = "If you confirm that you are using a delegated administrator account, verify that the IAM User or Role has the permission \"organizations:ListDelegatedAdministrators\"."
}

d := errs.NewErrorDiagnostic(fmt.Sprintf("creating CloudFormation StackSet (%s): %s", name, err), detail)
return append(diags, d)
}

d.SetId(name)
Expand Down
5 changes: 5 additions & 0 deletions internal/service/cloudformation/stack_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,11 @@ func TestAccCloudFormationStackSet_autoDeploymentDisabled(t *testing.T) {
}

// https://github.com/hashicorp/terraform-provider-aws/issues/32536.
// Prerequisites:
// * Organizations root account
// * Organization member account
// * Deleegated administrator not configured
gdavison marked this conversation as resolved.
Show resolved Hide resolved
// Authenticate with member account as target account and root account as alternate.
func TestAccCloudFormationStackSet_delegatedAdministrator(t *testing.T) {
ctx := acctest.Context(t)
providers := make(map[string]*schema.Provider)
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cloudformation_stack_set.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Manages a CloudFormation StackSet. StackSets allow CloudFormation templates to b

~> **NOTE:** All `NoEcho` template parameters must be ignored with the `lifecycle` configuration block `ignore_changes` argument.

~> **NOTE:** When using a delegated administrator account, ensure that your IAM User or Role has the `organizations:ListDelegatedAdministrators` permission. Otherwise, you may get an error like `ValidationError: Account used is not a delegated administrator`.

## Example Usage

```terraform
Expand Down
Loading