-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sudoblark/feature/initial-setup
Initial module setup
- Loading branch information
Showing
11 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
All of the S3 files are templated, the difference is without input vars we simply get the content verbatim - | ||
this allows flexibility, as we can handle both templated and non-templated input with the same resource(s). | ||
*/ | ||
|
||
locals { | ||
actual_s3_files = flatten([ | ||
for file in var.raw_s3_files : { | ||
name : file.name, | ||
destination_bucket : file.destination_bucket, | ||
destination_key : file.destination_key, | ||
content : templatefile("${file.source_folder}/${file.source_file}", try(file.template_input, {})) | ||
path : "${file.source_folder}/${file.source_file}" | ||
} | ||
]) | ||
} | ||
|
||
resource "aws_s3_object" "uploaded_files" { | ||
for_each = { for file in local.actual_s3_files : file.name => file } | ||
|
||
bucket = each.value["destination_bucket"] | ||
key = each.value["destination_key"] | ||
content = each.value["content"] | ||
|
||
etag = filemd5(each.value["path"]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "plain.json", | ||
"description": "I'm a plain file with static content." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "templated.json", | ||
"description": "I'm a file that uses terraform templating syntax to dynamically do things.", | ||
"examples": { | ||
"string": ${string_input}, | ||
"number": ${number_input}, | ||
"list": ${list_input} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
locals { | ||
raw_s3_files = [ | ||
{ | ||
name : "plain", | ||
source_folder : "${path.module}/files/", | ||
source_file : "plain.json", | ||
destination_bucket : "asset-bucket", | ||
destination_key : "plain-file.json" | ||
}, | ||
{ | ||
name : "templated", | ||
source_folder : "${path.module}/files/", | ||
source_file : "templated.json", | ||
template_input : { | ||
string_input : "Hello World!", | ||
number_input : "42", | ||
list_input : jsonencode([ | ||
"All work and no play makes Jack a dull boy.", | ||
"All work and no play makes Jack a dull boy.", | ||
"All work and no play makes Jack a dull boy.", | ||
"All work and no play makes Jack a dull boy.", | ||
"All work and no play makes Jack a dull boy." | ||
]) | ||
}, | ||
destination_bucket : "asset-bucket", | ||
destination_key : "templated-file.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.61.0" | ||
} | ||
} | ||
required_version = "~> 1.5.0" | ||
} | ||
|
||
provider "aws" { | ||
region = "eu-west-2" | ||
} | ||
|
||
module "s3_files" { | ||
source = "github.com/sudoblark/sudoblark.terraform.module.aws.s3_files?ref=1.0.0" | ||
raw_s3_files = local.raw_s3_files | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.61.0" | ||
} | ||
} | ||
required_version = "~> 1.5.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
variable "raw_s3_files" { | ||
description = <<EOT | ||
Data structure | ||
--------------- | ||
A list of dictionaries, where each dictionary has the following attributes: | ||
REQUIRED | ||
--------- | ||
- name: : Friendly name used through Terraform for instantiation and cross-referencing of resources, | ||
only relates to resource naming within the module. | ||
- source_folder : Which folder where the {source_file} lives. | ||
- source_file : The path under {source_folder} corresponding to the file to upload. | ||
- destination_key : Key in S3 bucket to upload to. | ||
- destination_bucket : The S3 bucket to upload the {source_file} to. | ||
OPTIONAL | ||
--------- | ||
- template_input : A dictionary of variable input for the template file needed for instantiation (leave blank if no template required) | ||
EOT | ||
type = list( | ||
object({ | ||
name = string, | ||
source_folder = string, | ||
source_file = string, | ||
destination_key = string, | ||
destination_bucket = string, | ||
template_input = optional(map(string), {}) | ||
}) | ||
) | ||
} |