diff --git a/.github/workflows/tftest.yaml b/.github/workflows/tftest.yaml new file mode 100644 index 0000000..d81a127 --- /dev/null +++ b/.github/workflows/tftest.yaml @@ -0,0 +1,65 @@ +name: 'Verify Terraform syntax' + +on: + # Triggers the workflow on push or pull request events but only for default and protected branches + push: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +permissions: + contents: read + actions: read + id-token: write # Required for Octo STS + +jobs: + terraform_check: + name: 'Check ${{matrix.directory}} directory' + runs-on: [ubuntu-latest] + + strategy: + fail-fast: false + matrix: + directory: [test] + + # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest + defaults: + run: + shell: bash + + steps: + - name: Configure Git to use OAuth token instead of SSH + run: | + git config --global url."https://oauth2:${{ secrets.MY_TOKEN }}@github.com".insteadOf ssh://git@github.com + env: + MY_TOKEN: ${{ secrets.MY_TOKEN }} # Ensure your token is in GitHub secrets + # Checkout the repository to the GitHub Actions runner + - name: Checkout + uses: actions/checkout@v4 + + + + + # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_wrapper: false + terraform_version: 1.6.6 + + # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. + - name: Terraform Init + working-directory: ${{matrix.directory}} + run: terraform init -backend=false + + # Checks that all Terraform configuration files adhere to a canonical format + - name: Terraform Format + working-directory: ${{matrix.directory}} + run: terraform validate + + # Checks that all Terraform configuration files adhere to a canonical format + - name: Terraform Format + working-directory: ${{matrix.directory}} + run: | + terraform fmt -check || { echo ' + FAILURE! The above files are not properly formatted. + Run `terraform fmt` in the ${{matrix.directory}} directory, commit the changed files and push to fix the issue' >&2; exit 1; } \ No newline at end of file diff --git a/test/main.tf b/test/main.tf new file mode 100644 index 0000000..e21194d --- /dev/null +++ b/test/main.tf @@ -0,0 +1,25 @@ +module "cloudsql_test" { + source = "ssh://git@github.com/kartverket/terraform-modules.git?ref=cloud_sql/0.1.0" + env = "sandbox" + instance_name = "test2" + project_id = "skip-sandbox-37c2" + iam_users = { + some-user = { + app_namespace = "foo-main" + app_name = "some-api-backend" + }, + } +} + +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "6.3.0" + } + } +} + +provider "google" { + region = "europe-north1" +}