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 account ID to the SSM document ARN #4436

Merged
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/resource_aws_ssm_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func resourceAwsSsmDocumentRead(d *schema.ResourceData, meta interface{}) error
Partition: meta.(*AWSClient).partition,
Service: "ssm",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("document/%s", *doc.Name),
}.String()
if err := d.Set("arn", arn); err != nil {
Expand Down
15 changes: 9 additions & 6 deletions aws/resource_aws_ssm_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -19,11 +20,13 @@ func TestAccAWSSSMDocument_basic(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSSMDocumentDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccAWSSSMDocumentBasicConfig(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMDocumentExists("aws_ssm_document.foo"),
resource.TestCheckResourceAttr("aws_ssm_document.foo", "document_format", "JSON"),
resource.TestMatchResourceAttr("aws_ssm_document.foo", "arn",
regexp.MustCompile(`^arn:aws:ssm:[a-z]{2}-[a-z]+-\d{1}:\d{12}:document/.*$`)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for this very accurate test check for the Commercial partition -- we'll be making these more generic so we can also support testing in GovCloud (US) and China at some point in the near future:

regexp.MustCompile(`^arn:[^:]+:ssm:[^:]+:\d{12}:document/.*$`))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha, I originally had the regex match gov-cloud as well and figured it was a waste of time because we didn't run the tests in gov-cloud/china and so took it out to simplify the regex. Didn't think about matching all non colon characters for the region and partition though.

I'll keep that in mind for anything else I add in future.

),
},
},
Expand All @@ -37,7 +40,7 @@ func TestAccAWSSSMDocument_update(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSSMDocumentDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccAWSSSMDocument20Config(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMDocumentExists("aws_ssm_document.foo"),
Expand All @@ -49,7 +52,7 @@ func TestAccAWSSSMDocument_update(t *testing.T) {
"aws_ssm_document.foo", "default_version", "1"),
),
},
resource.TestStep{
{
Config: testAccAWSSSMDocument20UpdatedConfig(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMDocumentExists("aws_ssm_document.foo"),
Expand All @@ -70,7 +73,7 @@ func TestAccAWSSSMDocument_permission(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSSMDocumentDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccAWSSSMDocumentPermissionConfig(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMDocumentExists("aws_ssm_document.foo"),
Expand All @@ -91,7 +94,7 @@ func TestAccAWSSSMDocument_params(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSSMDocumentDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccAWSSSMDocumentParamConfig(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMDocumentExists("aws_ssm_document.foo"),
Expand Down Expand Up @@ -120,7 +123,7 @@ func TestAccAWSSSMDocument_automation(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSSMDocumentDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccAWSSSMDocumentTypeAutomationConfig(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMDocumentExists("aws_ssm_document.foo"),
Expand Down