From 5fbed0f099a0a8f82ce1721be72c9611f4d8cb7f Mon Sep 17 00:00:00 2001 From: Maciej PIetrzykowski Date: Tue, 10 Jan 2023 09:28:06 +0100 Subject: [PATCH 1/7] new checkov version --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ef1de7a..3b4853b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: args: ["."] - repo: https://github.com/bridgecrewio/checkov.git - rev: "2.2.168" # Get the latest from: https://github.com/bridgecrewio/checkov/releases + rev: "2.2.246" # Get the latest from: https://github.com/bridgecrewio/checkov/releases hooks: - id: checkov From 3d348f3fdc75ae535a1fb05aa2fde7495d5387aa Mon Sep 17 00:00:00 2001 From: Maciej PIetrzykowski Date: Tue, 10 Jan 2023 09:32:14 +0100 Subject: [PATCH 2/7] add args --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3b4853b..087cdd1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,6 +19,7 @@ repos: rev: "2.2.246" # Get the latest from: https://github.com/bridgecrewio/checkov/releases hooks: - id: checkov + args: [--skip-check, "CKV2_GHA_1"] #Flase positive for top-level permissions - repo: https://github.com/pre-commit/pre-commit-hooks rev: "v4.3.0" # Get the latest from: https://github.com/pre-commit/pre-commit-hooks/releases From 6fd6d56daa55acabf4675aeb8b910dadfd2c126f Mon Sep 17 00:00:00 2001 From: Jakub Igla Date: Tue, 10 Jan 2023 09:42:08 +0100 Subject: [PATCH 3/7] feat: Allign examples --- .github/workflows/pre-commit.yml | 1 - .gitignore | 4 ++++ .tflint.hcl | 6 ++++++ README.md | 3 ++- examples/complete/.env.dist | 0 examples/complete/.envrc | 2 ++ examples/complete/Makefile | 11 +++++++++++ examples/complete/README.md | 17 +++++++++++++++++ examples/{full-example => complete}/context.tf | 0 examples/complete/fixtures.tfvars | 7 +++++++ examples/{full-example => complete}/main.tf | 0 examples/{full-example => complete}/outputs.tf | 0 .../{full-example => complete}/providers.tf | 0 examples/{full-example => complete}/versions.tf | 0 examples/simple/.env.dist | 0 examples/simple/.envrc | 2 ++ examples/simple/Makefile | 11 +++++++++++ examples/simple/README.md | 16 ++++++++++++++++ examples/simple/main.tf | 5 +++++ examples/simple/outputs.tf | 4 ++++ examples/simple/providers.tf | 3 +++ examples/simple/versions.tf | 10 ++++++++++ locals.tf | 4 +++- main.tf | 2 ++ outputs.tf | 2 +- 25 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 examples/complete/.env.dist create mode 100644 examples/complete/.envrc create mode 100644 examples/complete/Makefile create mode 100644 examples/complete/README.md rename examples/{full-example => complete}/context.tf (100%) create mode 100644 examples/complete/fixtures.tfvars rename examples/{full-example => complete}/main.tf (100%) rename examples/{full-example => complete}/outputs.tf (100%) rename examples/{full-example => complete}/providers.tf (100%) rename examples/{full-example => complete}/versions.tf (100%) create mode 100644 examples/simple/.env.dist create mode 100644 examples/simple/.envrc create mode 100644 examples/simple/Makefile create mode 100644 examples/simple/README.md create mode 100644 examples/simple/main.tf create mode 100644 examples/simple/outputs.tf create mode 100644 examples/simple/providers.tf create mode 100644 examples/simple/versions.tf diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 22fbe6c..7db5a4a 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -8,7 +8,6 @@ on: env: TERRAFORM_DOCS_VERSION: v0.16.0 - # TFLINT_VERSION: v0.41.0 # use this version with "Invicton-Labs/deepmerge/null" module jobs: collectInputs: diff --git a/.gitignore b/.gitignore index 5a4b0d9..31f9544 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,7 @@ override.tf.json # Include override files you do wish to add to version control using negated pattern # # !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* +*tfplan* diff --git a/.tflint.hcl b/.tflint.hcl index e3aef49..b3cc62f 100644 --- a/.tflint.hcl +++ b/.tflint.hcl @@ -1,3 +1,9 @@ +config { + ignore_module = { + "Invicton-Labs/deepmerge/null" = true + } +} + rule "terraform_deprecated_interpolation" { enabled = true } diff --git a/README.md b/README.md index 8b92dc8..27e25aa 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,8 @@ _Additional information that should be made public, for ex. how to solve known i ## EXAMPLES -- [Full example](examples/full-example) +- [Simple](examples/simple) - Basic usage of the module +- [Complete](examples/complete) - Advanced usage of the module diff --git a/examples/complete/.env.dist b/examples/complete/.env.dist new file mode 100644 index 0000000..e69de29 diff --git a/examples/complete/.envrc b/examples/complete/.envrc new file mode 100644 index 0000000..e948662 --- /dev/null +++ b/examples/complete/.envrc @@ -0,0 +1,2 @@ +#Override defaults +command -v dotenv && test -f .env && dotenv diff --git a/examples/complete/Makefile b/examples/complete/Makefile new file mode 100644 index 0000000..e5cd98f --- /dev/null +++ b/examples/complete/Makefile @@ -0,0 +1,11 @@ +init: + terraform init + +plan: + terraform plan -var-file fixtures.tfvars -out tfplan + +apply: + terraform apply tfplan + +destroy: + terraform destroy -var-file fixtures.tfvars diff --git a/examples/complete/README.md b/examples/complete/README.md new file mode 100644 index 0000000..ef8f8b0 --- /dev/null +++ b/examples/complete/README.md @@ -0,0 +1,17 @@ +# Complete Example + +```terraform +module "terraform_module_template" { + source = "../../" + context = module.this.context + + example_var = "This is a example value." +} +``` + +## Usage +``` +terraform init +terraform plan -var-file fixtures.tfvars -out tfplan +terraform apply tfplan +``` diff --git a/examples/full-example/context.tf b/examples/complete/context.tf similarity index 100% rename from examples/full-example/context.tf rename to examples/complete/context.tf diff --git a/examples/complete/fixtures.tfvars b/examples/complete/fixtures.tfvars new file mode 100644 index 0000000..11358b0 --- /dev/null +++ b/examples/complete/fixtures.tfvars @@ -0,0 +1,7 @@ +descriptor_formats = { + +} + +tags = { + Terraform = "True" +} diff --git a/examples/full-example/main.tf b/examples/complete/main.tf similarity index 100% rename from examples/full-example/main.tf rename to examples/complete/main.tf diff --git a/examples/full-example/outputs.tf b/examples/complete/outputs.tf similarity index 100% rename from examples/full-example/outputs.tf rename to examples/complete/outputs.tf diff --git a/examples/full-example/providers.tf b/examples/complete/providers.tf similarity index 100% rename from examples/full-example/providers.tf rename to examples/complete/providers.tf diff --git a/examples/full-example/versions.tf b/examples/complete/versions.tf similarity index 100% rename from examples/full-example/versions.tf rename to examples/complete/versions.tf diff --git a/examples/simple/.env.dist b/examples/simple/.env.dist new file mode 100644 index 0000000..e69de29 diff --git a/examples/simple/.envrc b/examples/simple/.envrc new file mode 100644 index 0000000..e948662 --- /dev/null +++ b/examples/simple/.envrc @@ -0,0 +1,2 @@ +#Override defaults +command -v dotenv && test -f .env && dotenv diff --git a/examples/simple/Makefile b/examples/simple/Makefile new file mode 100644 index 0000000..9d9205a --- /dev/null +++ b/examples/simple/Makefile @@ -0,0 +1,11 @@ +init: + terraform init + +plan: + terraform plan -out tfplan + +apply: + terraform apply tfplan + +destroy: + terraform destroy diff --git a/examples/simple/README.md b/examples/simple/README.md new file mode 100644 index 0000000..4d14a83 --- /dev/null +++ b/examples/simple/README.md @@ -0,0 +1,16 @@ +# Simple Example + +```terraform +module "terraform_module_template" { + source = "../../" + + example_var = "This is a example value." +} +``` + +## Usage +``` +terraform init +terraform plan -out tfplan +terraform apply tfplan +``` diff --git a/examples/simple/main.tf b/examples/simple/main.tf new file mode 100644 index 0000000..ca1dd7c --- /dev/null +++ b/examples/simple/main.tf @@ -0,0 +1,5 @@ +module "terraform_module_template" { + source = "../../" + + example_var = "This is a example value." +} diff --git a/examples/simple/outputs.tf b/examples/simple/outputs.tf new file mode 100644 index 0000000..c2007a2 --- /dev/null +++ b/examples/simple/outputs.tf @@ -0,0 +1,4 @@ +output "example_output" { + description = "Example output of the module" + value = module.terraform_module_template +} diff --git a/examples/simple/providers.tf b/examples/simple/providers.tf new file mode 100644 index 0000000..c793099 --- /dev/null +++ b/examples/simple/providers.tf @@ -0,0 +1,3 @@ +provider "null" { + # Configuration options +} diff --git a/examples/simple/versions.tf b/examples/simple/versions.tf new file mode 100644 index 0000000..ea4e1c7 --- /dev/null +++ b/examples/simple/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 0.13.0" + + required_providers { + null = { + source = "hashicorp/null" + version = "3.1.1" + } + } +} diff --git a/locals.tf b/locals.tf index d55ec57..c457489 100644 --- a/locals.tf +++ b/locals.tf @@ -2,6 +2,8 @@ locals { # Get a name from the descriptor. If not available, use default naming convention. # Trim and replace function are used to avoid bare delimiters on both ends of the name and situation of adjacent delimiters. name_from_descriptor = trim(replace( - lookup(module.this.descriptors, "module-resource-name", module.this.id), "/${module.this.delimiter}${module.this.delimiter}+/", "" + lookup(module.this.descriptors, "module-resource-name", module.this.id), "/${module.this.delimiter}${module.this.delimiter}+/", module.this.delimiter ), module.this.delimiter) + + enabled = module.this.enabled } diff --git a/main.tf b/main.tf index 065807b..12bec12 100644 --- a/main.tf +++ b/main.tf @@ -2,6 +2,8 @@ # echoes it's base64 encoded version locally resource "null_resource" "output_input" { + count = local.enabled ? 1 : 0 + triggers = { name = local.name_from_descriptor input = var.example_var diff --git a/outputs.tf b/outputs.tf index 6f13a49..b1bbafe 100644 --- a/outputs.tf +++ b/outputs.tf @@ -2,5 +2,5 @@ output "example_output" { description = "Example output of the module" - value = var.example_var + value = one(null_resource.output_input[*].id) } From 2ddc400c42e564130fae1ba448237f2290dde557 Mon Sep 17 00:00:00 2001 From: Jakub Igla Date: Tue, 10 Jan 2023 09:53:52 +0100 Subject: [PATCH 4/7] chore: Bump min TF version --- README.md | 2 +- versions.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 27e25aa..409c1c7 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ _Additional information that should be made public, for ex. how to solve known i | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.0 | +| [terraform](#requirement\_terraform) | >= 0.15.0 | | [null](#requirement\_null) | 3.1.1 | ## Resources diff --git a/versions.tf b/versions.tf index 32b2f24..b3db12c 100644 --- a/versions.tf +++ b/versions.tf @@ -1,7 +1,7 @@ # Example configuration of terraform providers terraform { - required_version = ">= 0.13.0" + required_version = ">= 0.15.0" required_providers { null = { From f1fab70c8a5dbf2f72b627917798d981f7879c1c Mon Sep 17 00:00:00 2001 From: Jakub Igla Date: Tue, 10 Jan 2023 10:03:24 +0100 Subject: [PATCH 5/7] docs: Improve usage example --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 409c1c7..f3bd620 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,8 @@ _Example usage of the module - terraform code snippet_ ```terraform module "template" { - source = "github.com/getindata/terraform-module-template" + source = "getindata/template/null" + # version = "x.x.x" example_var = "foo" } From 8a2b67d17746af5d6d0632d904ae6a92fa05eda5 Mon Sep 17 00:00:00 2001 From: MaciejMacQ <55737733+maciejmacq-dev@users.noreply.github.com> Date: Tue, 10 Jan 2023 11:33:41 +0100 Subject: [PATCH 6/7] Update examples/simple/versions.tf Co-authored-by: Piotr Mossakowski --- examples/simple/versions.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/simple/versions.tf b/examples/simple/versions.tf index ea4e1c7..45a914e 100644 --- a/examples/simple/versions.tf +++ b/examples/simple/versions.tf @@ -1,5 +1,5 @@ terraform { - required_version = ">= 0.13.0" + required_version = ">= 0.15.0" required_providers { null = { From 8314017b2470a030189dd7f42e060f895fc1256f Mon Sep 17 00:00:00 2001 From: Jakub Igla Date: Tue, 10 Jan 2023 11:40:33 +0100 Subject: [PATCH 7/7] chore: Bump TF version in examples --- examples/complete/versions.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf index ea4e1c7..45a914e 100644 --- a/examples/complete/versions.tf +++ b/examples/complete/versions.tf @@ -1,5 +1,5 @@ terraform { - required_version = ">= 0.13.0" + required_version = ">= 0.15.0" required_providers { null = {