Skip to content

Commit

Permalink
Test tf
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhny committed Sep 19, 2024
1 parent ca9bd4d commit 2af3afa
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/tftest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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:
- uses: octo-sts/action@6177b4481c00308b3839969c3eca88c96a91775f # v1.0.0
id: octo-sts
with:
scope: kartverket/terraform-modules
identity: kartverket_repos

# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ steps.octo-sts.outputs.token }}

- name: hack for github internal repo access
run: git config --global url."https://x-access-token:${{ secrets.GITHUB_SECRET }}@github.com".insteadOf ssh://git@github.com

# 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; }
25 changes: 25 additions & 0 deletions test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module "cloudsql_test" {
source = "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"
}

0 comments on commit 2af3afa

Please sign in to comment.