-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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 support for package SSM document type #11492
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -39,6 +39,32 @@ func resourceAwsSsmDocument() *schema.Resource { | |||||||
Required: true, | ||||||||
ValidateFunc: validateAwsSSMName, | ||||||||
}, | ||||||||
"attachments": { | ||||||||
Type: schema.TypeList, | ||||||||
Optional: true, | ||||||||
Elem: &schema.Resource{ | ||||||||
Schema: map[string]*schema.Schema{ | ||||||||
"key": { | ||||||||
Type: schema.TypeString, | ||||||||
Required: true, | ||||||||
ValidateFunc: validation.StringInSlice([]string{ | ||||||||
ssm.AttachmentsSourceKeySourceUrl, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additional value is available:
Suggested change
|
||||||||
ssm.AttachmentsSourceKeyS3fileUrl, | ||||||||
}, false), | ||||||||
}, | ||||||||
"name": { | ||||||||
Type: schema.TypeString, | ||||||||
Optional: true, | ||||||||
}, | ||||||||
"values": { | ||||||||
Type: schema.TypeList, | ||||||||
MinItems: 1, | ||||||||
Required: true, | ||||||||
Elem: &schema.Schema{Type: schema.TypeString}, | ||||||||
}, | ||||||||
}, | ||||||||
}, | ||||||||
}, | ||||||||
"content": { | ||||||||
Type: schema.TypeString, | ||||||||
Required: true, | ||||||||
|
@@ -60,6 +86,7 @@ func resourceAwsSsmDocument() *schema.Resource { | |||||||
ssm.DocumentTypePolicy, | ||||||||
ssm.DocumentTypeAutomation, | ||||||||
ssm.DocumentTypeSession, | ||||||||
ssm.DocumentTypePackage, | ||||||||
}, false), | ||||||||
}, | ||||||||
"schema_version": { | ||||||||
|
@@ -164,6 +191,10 @@ func resourceAwsSsmDocumentCreate(d *schema.ResourceData, meta interface{}) erro | |||||||
docInput.Tags = keyvaluetags.New(v.(map[string]interface{})).IgnoreAws().SsmTags() | ||||||||
} | ||||||||
|
||||||||
if v, ok := d.GetOk("attachments"); ok { | ||||||||
docInput.Attachments = expandAttachments(v.([]interface{})) | ||||||||
} | ||||||||
|
||||||||
log.Printf("[DEBUG] Waiting for SSM Document %q to be created", d.Get("name").(string)) | ||||||||
var resp *ssm.CreateDocumentOutput | ||||||||
err := resource.Retry(5*time.Minute, func() *resource.RetryError { | ||||||||
|
@@ -266,6 +297,11 @@ func resourceAwsSsmDocumentRead(d *schema.ResourceData, meta interface{}) error | |||||||
|
||||||||
d.Set("status", doc.Status) | ||||||||
|
||||||||
if v, ok := d.GetOk("attachments"); ok { | ||||||||
// The API doesn't currently return attachment information so it has to be set this way | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears that the SSM Since the Create/Update and Read APIs do not share a common API structure, this would have potentially been a case where we could smooth over the user experience in Terraform and support a configuration like the following: attachment {
name = ""
url = ""
} Where on Create/Update the Terraform logic converted those to the requisite However, it appears It may be best in this case then to just rename this attribute directly We can also skip this |
||||||||
d.Set("attachments", v) | ||||||||
} | ||||||||
|
||||||||
gp, err := getDocumentPermissions(d, meta) | ||||||||
|
||||||||
if err != nil { | ||||||||
|
@@ -384,6 +420,31 @@ func resourceAwsSsmDocumentDelete(d *schema.ResourceData, meta interface{}) erro | |||||||
return nil | ||||||||
} | ||||||||
|
||||||||
func expandAttachments(a []interface{}) []*ssm.AttachmentsSource { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Resources and their functions currently live in the shared
Suggested change
|
||||||||
if len(a) == 0 { | ||||||||
return nil | ||||||||
} | ||||||||
|
||||||||
results := make([]*ssm.AttachmentsSource, 0) | ||||||||
for _, raw := range a { | ||||||||
at := raw.(map[string]interface{}) | ||||||||
s := &ssm.AttachmentsSource{} | ||||||||
if val, ok := at["key"]; ok { | ||||||||
s.Key = aws.String(val.(string)) | ||||||||
} | ||||||||
if val, ok := at["name"]; ok && val != "" { | ||||||||
s.Name = aws.String(val.(string)) | ||||||||
} | ||||||||
if val, ok := at["values"]; ok { | ||||||||
s.Values = expandStringList(val.([]interface{})) | ||||||||
} | ||||||||
|
||||||||
results = append(results, s) | ||||||||
} | ||||||||
return results | ||||||||
|
||||||||
} | ||||||||
|
||||||||
func setDocumentPermissions(d *schema.ResourceData, meta interface{}) error { | ||||||||
ssmconn := meta.(*AWSClient).ssmconn | ||||||||
|
||||||||
|
@@ -572,6 +633,10 @@ func updateAwsSSMDocument(d *schema.ResourceData, meta interface{}) error { | |||||||
DocumentVersion: aws.String(d.Get("default_version").(string)), | ||||||||
} | ||||||||
|
||||||||
if d.HasChange("attachments") { | ||||||||
updateDocInput.Attachments = expandAttachments(d.Get("attachments").([]interface{})) | ||||||||
} | ||||||||
|
||||||||
newDefaultVersion := d.Get("default_version").(string) | ||||||||
|
||||||||
ssmconn := meta.(*AWSClient).ssmconn | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -48,12 +48,21 @@ DOC | |||||
The following arguments are supported: | ||||||
|
||||||
* `name` - (Required) The name of the document. | ||||||
* `attachments` - (Optional) A list of key/value pairs describing attachments to a version of a document. Defined below. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Recommend shying away from "list" and "key/value pairs" when referring to a configuration block attributes, since in Terraform 0.12+ they all mean semantically different things (and Terraform 0.12 removed the old
Suggested change
|
||||||
* `content` - (Required) The JSON or YAML content of the document. | ||||||
* `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: `Command`, `Policy`, `Automation` and `Session` | ||||||
* `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. | ||||||
* `tags` - (Optional) A mapping of tags to assign to the object. | ||||||
|
||||||
## attachments | ||||||
|
||||||
The `attachments` block supports the following: | ||||||
|
||||||
* `key` - (Required) The key describing the location of an attachment to a document. Valid key types include: `SourceUrl` and `S3FileUrl` | ||||||
* `values` - (Required) The value describing the location of an attachment to a document | ||||||
* `name` - (Optional) The name of the document attachment file | ||||||
|
||||||
## Attributes Reference | ||||||
|
||||||
In addition to all arguments above, the following attributes are exported: | ||||||
|
@@ -90,3 +99,21 @@ SSM Documents can be imported using the name, e.g. | |||||
``` | ||||||
$ terraform import aws_ssm_document.example example | ||||||
``` | ||||||
|
||||||
The `attachments` argument does not have an SSM API method for reading the attachment information detail after creation. If the argument is set in the Terraform configuration on an imported resource, Terraform will always show a difference. To workaround this behavior, either omit the argument from the Terraform configuration or use [`ignore_changes`](/docs/configuration/resources.html#ignore_changes) to hide the difference, e.g. | ||||||
|
||||||
```hcl | ||||||
resource "aws_ssm_document" "test" { | ||||||
name = "test_document" | ||||||
document_type = "Package" | ||||||
|
||||||
attachments { | ||||||
key = "SourceUrl" | ||||||
values = ["s3://${aws_s3_bucket.object_bucket.bucket}/test.zip"] | ||||||
} | ||||||
|
||||||
# There is no AWS SSM API for reading attachments | ||||||
lifecycle { | ||||||
ignore_changes = ["attachments"] | ||||||
} | ||||||
} |
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.
Per comment in read function, recommend naming this
attachments_source
(singular for configuration blocks)