Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Add datasource_template_file_list #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PaulAtkins
Copy link

Adding datasource_template_file_list. This is similar to datasource_template_file and resource_template_dir, except instead of creating a rendered file, it returns an overall hash of the entire directory, plus a list of:

  • file hash (as id)
  • file name
  • file contents

This allows the file contents to be used in other resources.

Example use case is the AWS ssm_document resource. When dealing with many of these documents, instead of creating a ssm_document for every document, it's easier to pass in a list of documents.

Example usage:

data "template_file_list" "list" {
	source_dir = "./docs"
}
output "files" {
	value = "${data.template_file_list.list.files}"
}

Previously, I was using the powershell below to retrieve this list, but this seems a cleaner approach, as it's not reliant on an external executable:

data "external" "doc-list" {
  program = ["powershell", "New-Object PSObject | Add-Member -PassThru NoteProperty Name ((Get-ChildItem -Path ../../docs/linux -File -Filter '*.json').Name -join ',') | ConvertTo-Json"]
}

Not sure if this is the correct provider / naming for this, or if it should be under external

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants