diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index 5032b7f..22f03db 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -63,6 +63,7 @@ jobs: matrix: format: ["true", "false"] validate: ["true", "false"] + test: ["true", "false"] plan: ["true", "false"] apply: ["true", "false"] destroy: ["true", "false"] @@ -77,6 +78,7 @@ jobs: init: true format: ${{ matrix.format }} validate: ${{ matrix.validate }} + test: ${{ matrix.test }} plan: ${{ matrix.plan }} apply: ${{ matrix.apply }} destroy: ${{ matrix.destroy }} @@ -88,6 +90,7 @@ jobs: init: true format: ${{ matrix.format }} validate: ${{ matrix.validate }} + test: ${{ matrix.test }} plan: ${{ matrix.plan }} apply: ${{ matrix.apply }} destroy: ${{ matrix.destroy }} @@ -99,17 +102,40 @@ jobs: init: false format: ${{ matrix.format }} validate: ${{ matrix.validate }} + test: ${{ matrix.test }} plan: ${{ matrix.plan }} apply: ${{ matrix.apply }} destroy: ${{ matrix.destroy }} directory: "test/terraform" + test-terraform-test: + name: Test terraform test + runs-on: ubuntu-latest + strategy: + matrix: + test-args: ["-json", ""] + fail-fast: true + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Test + uses: "./" + with: + directory: "test/terraform" + test-directory: "test/terraform" + test-args: ${{ matrix.test-args }} + format: false + validate: false + plan: false + test: true + release: name: Release needs: - test-setup - test-args - test-jobs + - test-terraform-test runs-on: ubuntu-latest steps: - name: Checkout diff --git a/.releaserc.json b/.releaserc.json index cc5830f..0e4eb1d 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -27,8 +27,8 @@ { "file": "README.md", "hasChanged": true, - "numMatches": 3, - "numReplacements": 3 + "numMatches": 4, + "numReplacements": 4 } ], "countMatches": true @@ -48,4 +48,4 @@ ], "@semantic-release/github" ] -} \ No newline at end of file +} diff --git a/README.md b/README.md index 2f3cb37..6d8ceb8 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ on: branches: ["main"] pull_request: branches: ["main"] - + permissions: contents: read @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@v4 - name: Deploy With Value 1 uses: "infinite-automations/terraform-all-in-one@v1.1.0" - with: + with: directory: "./terraform" apply: true env: @@ -36,17 +36,23 @@ jobs: echo "Running test 1..." - name: Deploy With Value 2 uses: "infinite-automations/terraform-all-in-one@v1.1.0" - with: + with: directory: "./terraform" apply: true env: TF_VAR_my_var: "value2" - name: Run Test 2 - run: | - echo "Running test 2..." + uses: "infinite-automations/terraform-all-in-one@v1.1.0" + with: + directory: "./terraform" + test-directory: "./terraform" + format: false + validate: false + plan: false + test: true - name: Destroy uses: "infinite-automations/terraform-all-in-one@v1.1.0" - with: + with: directory: "./terraform" setup: false init: false @@ -61,25 +67,28 @@ You can configure additional command arguments with inputs. ## Inputs -| Input Name | Description | Required | Default | -| ----------------- | ----------------------------------------------------------------- | -------- | --------- | -| directory | The directory where the Terraform configuration files are located | false | . | -| terraform-version | The version of Terraform to use | false | latest | -| plan-file | The path to the plan file | false | plan.json | -| common-args | The arguments to pass to all terraform commands | false | | -| init-args | The arguments to pass to terraform init | false | | -| validate-args | The arguments to pass to terraform validate | false | | -| fmt-args | The arguments to pass to terraform fmt | false | -check | -| plan-args | The arguments to pass to terraform plan | false | | -| apply-args | The arguments to pass to terraform apply | false | | -| destroy-args | The arguments to pass to terraform destroy | false | | -| setup | Whether to setup | false | true | -| init | Whether to init | false | true | -| format | Whether to format | false | true | -| validate | Whether to validate | false | true | -| plan | Whether to plan | false | true | -| apply | Whether to apply | false | false | -| destroy | Whether to destroy | false | false | +| Input Name | Description | Required | Default | +| ----------------- | ---------------------------------------------------------------------- | -------- | --------- | +| directory | The directory where the Terraform configuration files are located | false | . | +| test-directory | The directory where the Terraform test configuration files are located | false | . | +| terraform-version | The version of Terraform to use | false | latest | +| plan-file | The path to the plan file | false | plan.json | +| common-args | The arguments to pass to all terraform commands | false | | +| init-args | The arguments to pass to terraform init | false | | +| validate-args | The arguments to pass to terraform validate | false | | +| fmt-args | The arguments to pass to terraform fmt | false | -check | +| test-args | The arguments to pass to terraform test | false | | +| plan-args | The arguments to pass to terraform plan | false | | +| apply-args | The arguments to pass to terraform apply | false | | +| destroy-args | The arguments to pass to terraform destroy | false | | +| setup | Whether to setup | false | true | +| init | Whether to init | false | true | +| format | Whether to format | false | true | +| validate | Whether to validate | false | true | +| test | Whether to test | false | false | +| plan | Whether to plan | false | true | +| apply | Whether to apply | false | false | +| destroy | Whether to destroy | false | false | ## Outputs diff --git a/action.yml b/action.yml index c51e2ed..5171c30 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,10 @@ inputs: description: "The directory where the Terraform configuration files are located" required: false default: "." + test-directory: + description: "The directory where the Terraform test configuration files are located" + required: false + default: "." terraform-version: description: "The version of Terraform to use" required: false @@ -31,6 +35,10 @@ inputs: description: "The arguments to pass to terraform fmt" required: false default: "-check" + test-args: + description: "The arguments to pass to terraform test" + required: false + default: "" plan-args: description: "The arguments to pass to terraform plan" required: false @@ -59,6 +67,10 @@ inputs: description: "Whether to validate" required: false default: "true" + test: + description: "Whether to test" + required: false + default: "false" plan: description: "Whether to plan" required: false @@ -100,6 +112,11 @@ runs: run: terraform validate ${{ inputs.common-args }} ${{ inputs.validate-args }} working-directory: ${{ inputs.directory }} shell: bash + - name: Terraform Test + if: ${{ inputs.test == 'true' }} + run: terraform test ${{ inputs.common-args }} ${{ inputs.test-args }} + working-directory: ${{ inputs.test-directory }} + shell: bash - name: Terraform Plan if: ${{ inputs.plan == 'true' }} run: terraform plan ${{ inputs.common-args }} ${{ inputs.plan-args }} -out ${{ inputs.plan-file }} diff --git a/test/terraform/main.tftest.hcl b/test/terraform/main.tftest.hcl new file mode 100644 index 0000000..8bfbedf --- /dev/null +++ b/test/terraform/main.tftest.hcl @@ -0,0 +1 @@ +run "setup" {}