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_ssm_document - support VersionName parameter #14128

Merged
merged 4 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions aws/resource_aws_ssm_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ func resourceAwsSsmDocument() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"version_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Oddly enough, the UpdateDocument API operation also accepts VersionName, so going to verify its behavior on merge.

},
},
}
}
Expand Down Expand Up @@ -207,6 +213,9 @@ func resourceAwsSsmDocumentCreate(d *schema.ResourceData, meta interface{}) erro
if v, ok := d.GetOk("target_type"); ok {
docInput.TargetType = aws.String(v.(string))
}
if v, ok := d.GetOk("version_name"); ok {
docInput.VersionName = aws.String(v.(string))
}

resp, err := ssmconn.CreateDocument(docInput)

Expand Down Expand Up @@ -282,6 +291,7 @@ func resourceAwsSsmDocumentRead(d *schema.ResourceData, meta interface{}) error
d.Set("hash", doc.Hash)
d.Set("hash_type", doc.HashType)
d.Set("latest_version", doc.LatestVersion)
d.Set("version_name", doc.VersionName)
d.Set("name", doc.Name)
d.Set("owner", doc.Owner)
d.Set("platform_types", flattenStringList(doc.PlatformTypes))
Expand Down
62 changes: 62 additions & 0 deletions aws/resource_aws_ssm_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,37 @@ func TestAccAWSSSMDocument_target_type(t *testing.T) {
})
}

func TestAccAWSSSMDocument_version_name(t *testing.T) {
name := acctest.RandString(10)
resourceName := "aws_ssm_document.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSSMDocumentDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSSMDocumentBasicConfigVersionName(name, "release-1.0.0"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMDocumentExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "version_name", "release-1.0.0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSSSMDocumentBasicConfigVersionName(name, "release-1.0.1"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMDocumentExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "version_name", "release-1.0.1"),
),
},
},
})
}

func TestAccAWSSSMDocument_update(t *testing.T) {
name := acctest.RandString(10)
resourceName := "aws_ssm_document.test"
Expand Down Expand Up @@ -624,6 +655,37 @@ DOC
`, rName, typ)
}

func testAccAWSSSMDocumentBasicConfigVersionName(rName, version string) string {
return fmt.Sprintf(`
resource "aws_ssm_document" "test" {
name = "%s"
document_type = "Command"
version_name = "%s"
bflad marked this conversation as resolved.
Show resolved Hide resolved

content = <<DOC
{
"schemaVersion": "2.0",
"description": "Sample version 2.0 document v2",
"parameters": {

},
"mainSteps": [
{
"action": "aws:runPowerShellScript",
"name": "runPowerShellScript",
"inputs": {
"runCommand": [
"Get-Process"
]
}
}
]
}
DOC
}
`, rName, version)
}

func testAccAWSSSMDocument20Config(rName string) string {
return fmt.Sprintf(`
resource "aws_ssm_document" "test" {
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/ssm_document.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ The following arguments are supported:
* `document_format` - (Optional, defaults to JSON) The format of the document. Valid document types include: `JSON` and `YAML`
* `document_type` - (Required) The type of the document. Valid document types include: `Automation`, `Command`, `Package`, `Policy`, and `Session`
* `permissions` - (Optional) Additional Permissions to attach to the document. See [Permissions](#permissions) below for details.
* `target_type` - (Optional) The target type which defines the kinds of resources the document can run on. For example, /AWS::EC2::Instance. For a list of valid resource types, see AWS Resource Types Reference (http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html)
* `target_type` - (Optional) The target type which defines the kinds of resources the document can run on. For example, /AWS::EC2::Instance. For a list of valid
bflad marked this conversation as resolved.
Show resolved Hide resolved
* `version_name` - (Optional) A field specifying the version of the artifact you are creating with the document. For example, "Release 12, Update 6"
* `tags` - (Optional) A map of tags to assign to the object.

## attachments_source
Expand Down