Skip to content

Commit

Permalink
Update to switch internal data source to non-deprecated provider (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKotowick authored Mar 26, 2023
1 parent 886cf74 commit f6bba7b
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 9 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: "Build"

on: [push, pull_request]

jobs:
Matrix:
runs-on: ubuntu-latest

steps:
- name: Generate Matrix
id: matrix
uses: Invicton-Labs/terraform-module-testing/matrix@v0.1.0
with:
minimum_tf_version: '0.13.0'

- name: Output Matrix
run: |
echo "Strategy: ${{ steps.matrix.outputs.strategy }}"
outputs:
strategy: ${{ steps.matrix.outputs.strategy }}

Test:
needs: [Matrix]
strategy: ${{ fromJSON(needs.Matrix.outputs.strategy)}}
runs-on: ${{ matrix.runs-on }}
container: ${{ matrix.container }}
steps:
- name: Initialize - Pass
id: init-pass
uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0
with:
tf_path: tests/pass
- name: Run Tests - Pass
id: tests-pass
uses: Invicton-Labs/terraform-module-testing/apply-destroy@v0.1.0
with:
tf_path: tests/pass

- name: Initialize - Fail
id: init-fail
uses: Invicton-Labs/terraform-module-testing/initialize@v0.1.0
with:
tf_path: tests/fail
- name: Run Tests - Fail
id: tests-fail
uses: Invicton-Labs/terraform-module-testing/apply-failure@v0.1.0
with:
tf_path: tests/fail

# This job just waits for all other jobs to pass. We have it here
# so our branch protection rule can reference a single job, instead
# of needing to list every matrix value of every job above.
Passed:
runs-on: ubuntu-latest
needs: [Test]
steps:
- name: Mark tests as passed
run: echo "🎉"
9 changes: 4 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
// Therefore, unless the "checked" output parameter was actually used somewhere in the parent module,
// the assertion check would never actually run. By putting it in a data source, it will always run
// regardless of whether any outputs of this module are used in the parent module. The `null` data
// source would be ideal, but it throws a deprecation warning. This template data source is the
// source would be ideal, but it throws a deprecation warning. This CloudInit data source is the
// next best alternative, since it is fast and doesn't interact with the operating system at all
// (unlike an external data source, for example).
data "template_file" "check" {
template = ""
vars = {
// (unlike an external data source, for example), and isn't deprecated.
data "cloudinit_config" "check" {
part {
content = var.condition ? "" : SEE_ABOVE_ERROR_MESSAGE(true ? null : "ERROR: ${var.error_message}")
}
}
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output "checked" {
description = "Whether the condition has been checked (used for assertion dependencies)."
value = data.template_file.check.rendered == "" ? true : true
value = data.cloudinit_config.check.rendered == "" ? true : true
}
22 changes: 22 additions & 0 deletions tests/fail/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/fail/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module "fail" {
source = "../../"
condition = false
error_message = "sample error"
}
22 changes: 22 additions & 0 deletions tests/pass/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/pass/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module "pass" {
source = "../../"
condition = true
error_message = "sample error"
}
6 changes: 3 additions & 3 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
terraform {
required_version = ">= 0.13.0"
required_providers {
template = {
source = "hashicorp/template"
version = ">= 2.2.0"
cloudinit = {
source = "hashicorp/cloudinit"
version = ">= 2.3.1"
}
}
}

0 comments on commit f6bba7b

Please sign in to comment.