├── .github └── workflows │ ├── super-linter.yml │ └── terraform.yml ├── .gitignore ├── .mdlrc ├── .pre-commit-config.yaml ├── .tflint.hcl ├── LICENSE ├── README.md ├── data-sources.tf ├── images ├── pre-commit-install.gif ├── pre-commit-run-bad.gif ├── terraform-fmt-and-validate-good.gif ├── terraform-init.gif └── tflint.gif ├── outputs.tf ├── provider.tf ├── terraform.tf ├── terraform.tfvars.sample └── variables.tf /.github/workflows/super-linter.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | name: "Code Quality: Super-Linter" 4 | 5 | on: 6 | pull_request: 7 | 8 | jobs: 9 | superlinter: 10 | name: Super-Linter 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout Repository 14 | uses: actions/checkout@v2 15 | with: 16 | fetch-depth: 1 17 | 18 | - name: Lint Code 19 | uses: docker://github/super-linter:v3 20 | env: 21 | VALIDATE_ALL_CODEBASE: true 22 | DEFAULT_BRANCH: "main" 23 | DISABLE_ERRORS: false 24 | VALIDATE_BASH: true 25 | VALIDATE_JSON: true 26 | VALIDATE_MD: true 27 | VALIDATE_TERRAFORM: true 28 | VALIDATE_YAML: true 29 | -------------------------------------------------------------------------------- /.github/workflows/terraform.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | name: "Code Quality: Terraform" 4 | 5 | on: 6 | pull_request: 7 | 8 | env: 9 | # `AWS_REGION` must be specified for `terraform validate` 10 | AWS_REGION: "xx-xxxx-0" 11 | 12 | jobs: 13 | terraform: 14 | name: Terraform 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout Repository 18 | uses: actions/checkout@v2 19 | with: 20 | fetch-depth: 1 21 | 22 | - name: Setup Terraform 23 | uses: hashicorp/setup-terraform@v1 24 | with: 25 | terraform_version: "0.12.29" 26 | 27 | - name: Run `terraform fmt` 28 | run: terraform fmt -diff -check -no-color -recursive 29 | 30 | - name: Run `terraform init` 31 | run: terraform init 32 | 33 | - name: Run `terraform validate` 34 | run: terraform validate -no-color 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Terraform 2 | **/.terraform/ 3 | *.tfplan* 4 | *.tfstate* 5 | *.tfstate.* 6 | *.tfvars 7 | 8 | # Google Cloud Platform credentials 9 | google_cloud_credentials.json 10 | google_cloud_credentials-*.json 11 | -------------------------------------------------------------------------------- /.mdlrc: -------------------------------------------------------------------------------- 1 | { 2 | "MD013": false, 3 | "MD033": false 4 | } 5 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | fail_fast: true 4 | minimum_pre_commit_version: "2.6.0" 5 | 6 | repos: 7 | - 8 | repo: https://github.com/pre-commit/pre-commit-hooks 9 | rev: v3.1.0 10 | hooks: 11 | - id: check-added-large-files 12 | - id: check-case-conflict 13 | - id: check-merge-conflict 14 | - id: check-executables-have-shebangs 15 | - id: check-json 16 | - id: check-merge-conflict 17 | - id: check-symlinks 18 | - id: check-vcs-permalinks 19 | - id: check-xml 20 | - id: check-yaml 21 | - 22 | repo: https://github.com/antonbabenko/pre-commit-terraform 23 | rev: v1.31.0 24 | hooks: 25 | - id: terraform_fmt 26 | - id: terraform_validate 27 | 28 | - 29 | repo: https://github.com/igorshubovych/markdownlint-cli 30 | rev: v0.23.2 31 | hooks: 32 | - id: markdownlint 33 | args: [ 34 | "--config=.mdlrc" 35 | ] 36 | -------------------------------------------------------------------------------- /.tflint.hcl: -------------------------------------------------------------------------------- 1 | config { 2 | module = false 3 | deep_check = false 4 | force = false 5 | } 6 | 7 | rule "terraform_required_providers" { 8 | enabled = true 9 | } 10 | 11 | rule "terraform_required_version" { 12 | enabled = true 13 | } 14 | 15 | rule "terraform_naming_convention" { 16 | enabled = true 17 | format = "snake_case" 18 | } 19 | 20 | rule "terraform_typed_variables" { 21 | enabled = true 22 | } 23 | 24 | rule "terraform_unused_declarations" { 25 | enabled = true 26 | } 27 | 28 | rule "terraform_comment_syntax" { 29 | enabled = true 30 | } 31 | 32 | rule "terraform_deprecated_index" { 33 | enabled = true 34 | } 35 | 36 | rule "terraform_deprecated_interpolation" { 37 | enabled = true 38 | } 39 | 40 | rule "terraform_documented_outputs" { 41 | enabled = true 42 | } 43 | 44 | rule "terraform_documented_variables" { 45 | enabled = true 46 | } 47 | 48 | rule "terraform_module_pinned_source" { 49 | enabled = true 50 | } 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Code Quality for Terraform 2 | 3 | > This repository contains low-quality Terraform code that uses the [Google Provider](https://www.terraform.io/docs/providers/google/index.html) to showcase a handful of ways of improving code hygiene and quality. 4 | 5 | ## Table of Contents 6 | 7 | - [Code Quality for Terraform](#code-quality-for-terraform) 8 | - [Table of Contents](#table-of-contents) 9 | - [Important Links](#important-links) 10 | - [Tools](#tools) 11 | - [Usage](#usage) 12 | - [Code Quality](#code-quality) 13 | - [Using built-in tooling](#using-built-in-tooling) 14 | - [Using pre-commit locally](#using-pre-commit-locally) 15 | - [Using pre-commit via GitHub Actions](#using-pre-commit-via-github-actions) 16 | - [Using TFLint](#using-tflint) 17 | - [Using GitHub Actions](#using-github-actions) 18 | - [Notes](#notes) 19 | - [Author Information](#author-information) 20 | - [License](#license) 21 | 22 | ## Important Links 23 | 24 | - Slides: [speakerdeck.com/ksatirli/code-quality-for-terraform](https://speakerdeck.com/ksatirli/code-quality-for-terraform) 25 | - Code: [github.com/ksatirli/code-quality-for-terraform](https://github.com/ksatirli/code-quality-for-terraform) 26 | 27 | ### Tools 28 | 29 | - Local options: 30 | - [terraform fmt](https://www.terraform.io/docs/commands/fmt.html) 31 | - [terraform validate](https://www.terraform.io/docs/commands/validate.html) 32 | - [TFLint](https://github.com/terraform-linters/tflint) 33 | - [pre-commit](https://pre-commit.com) 34 | - Remote options: 35 | - [GitHub Actions](https://github.com/features/actions) 36 | - [GitHub Super-Linter](https://www.terraform.io/docs/github-actions/index.html) 37 | - [Terraform GitHub Actions](https://www.terraform.io/docs/github-actions/index.html) 38 | 39 | ## Usage 40 | 41 | Start by copying [terraform.tfvars.sample](https://github.com/ksatirli/code-quality-for-terraform/blob/main/terraform.tfvars.sample) to `terraform.tfvars` and fill in your GCP-specific information: 42 | 43 | ```hcl 44 | project_id = "my-project-identifier" # replace with your GCP Project Identifier 45 | project_domain = "my-domain.com" # replace with your GCP Project Domain 46 | ``` 47 | 48 | Then, initialize the Terraform directory (`.terraform/`) by running `terraform init`: 49 | 50 | ![CLI command: terraform init](images/terraform-init.gif) 51 | 52 | This downloads the Google Provider for Terraform (as specified in [terraform.tf](https://github.com/ksatirli/code-quality-for-terraform/blob/main/terraform.tf)) and ensures you are running the correct Terraform version. 53 | 54 | ## Code Quality 55 | 56 | Terraform projects rarely exist in isolation. A repository containing Terraform files (`.tf`) will often contain related files in one or more of the following formats: 57 | 58 | - HCL (`.hcl`) 59 | - JSON (`.json`) 60 | - Markdown (`.md` and `.mdx`) 61 | - Shell scripts (`.sh` and `.bash`) 62 | - YAML (`.yaml` and `.yml`) 63 | 64 | Ensuring proper code quality for _all_ files is important, as an uncaught error in one type of file may result in a Terraform Resources not being created, correctly. 65 | 66 | While it is outside the scope of this repository to advise you on linting rules for all the above files, you are encouraged to check out [@operatehappy/dotfiles-org](https://github.com/operatehappy/dotfiles-org) for a collection of code quality configurations that work _well_ with Terraform-adjacent code. 67 | 68 | ### Using built-in tooling 69 | 70 | Terraform includes two very useful utilities to improve the quality of your code, without the need for external applications. 71 | 72 | To format your code, using the canonical rules, use `terraform fmt`. Then, validate your code using `terraform validate`: 73 | 74 | ![CLI command: terraform fmt and terraform validate](images/terraform-fmt-and-validate-good.gif) 75 | 76 | ### Using `pre-commit` locally 77 | 78 | To use `pre-commit` locally, follow the installation instructions on [pre-commit.com](https://pre-commit.com/#install) and then initialize your repository: 79 | 80 | ![CLI command: pre-commit install](images/pre-commit-install.gif) 81 | 82 | This will configure `.git/hooks/pre-commit` to reflect your local `pre-commit` installation. 83 | 84 | On every commit, `git` (including GUI clients) will now run all checks listed in [.pre-commit-config.yaml](https://github.com/ksatirli/code-quality-for-terraform/blob/main/.pre-commit-config.yaml). 85 | 86 | Next to automated runs, it is possible to invoke these checks manually. For this, you can use `pre-commit run --all-files`: 87 | 88 | ![CLI command: pre-commit run -all-files](images/pre-commit-run-bad.gif) 89 | 90 | ### Using `pre-commit` via GitHub Actions 91 | 92 | It is _possible_ to run `pre-commit` as part of [GitHub Actions](https://github.com/features/actions). This process is involved and requires the following: 93 | 94 | - access to `pre-commit` inside of GitHub Actions 95 | - a check-out of the code you want to run `pre-commit` against 96 | 97 | Depending on the `pre-commit` handlers you want to run, you will need to install various applications that are then used as part of `pre-commit`. 98 | 99 | A sample implementation of this process, including checking out an organization-wide `pre-commit` configuration can be found in [@operatehappy/terraform-aws-route53-workmail-records](https://github.com/operatehappy/terraform-aws-route53-workmail-records/blob/master/.github/workflows/code-quality.yml). 100 | 101 | A simpler (but just as powerful) approach to running a large amount of linters remotely is to use [GitHub Super-Linter](https://github.com/github/super-linter). 102 | 103 | ### Using TFLint 104 | 105 | To use TFLint, follow the [installation instructions](https://github.com/terraform-linters/tflint#installation). Once installed, you can run `tflint`: 106 | 107 | ![CLI command: tflint](images/tflint.gif) 108 | 109 | This repository includes a sample [.tflint.hcl](https://github.com/ksatirli/code-quality-for-terraform/blob/main/.tflint.hcl) configuration that may serve as a starting point for your own ruleset. 110 | 111 | ### Using GitHub Actions 112 | 113 | GitHub Actions are enabled by default on any GitHub Repository. 114 | 115 | This repository includes two workflow definition files in [.github/workflows/](https://github.com/ksatirli/code-quality-for-terraform/tree/expands-readme/.github/workflows) that may serve as a starting point for your own workflows. 116 | 117 | ## Notes 118 | 119 | - The [main](https://github.com/ksatirli/code-quality-for-terraform/tree/main) branch includes a working example of code quality tools and some GCP-specific Terraform resources. This branch is best used to understand how things work together 120 | - The [unlinted](https://github.com/ksatirli/code-quality-for-terraform/tree/unlinted) branch includes a handful of misconfigurations (in the `.tf` files) to test the various code quality tools. 121 | - The [tools-only](https://github.com/ksatirli/code-quality-for-terraform/tree/tools-only) branch includes _just_ the configuration of `pre-commit`, `tflint` and GitHub Actions for Terraform as well as GitHub Super-Linter. This branch is best used as a starting point: just add your own `.tf` files and go! 122 | 123 | ## Author Information 124 | 125 | This repository is maintained by [Kerim Satirli](https://github.com/ksatirli). 126 | 127 | ## License 128 | 129 | Licensed under the Apache License, Version 2.0 (the "License"). 130 | 131 | You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0). 132 | 133 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an _"AS IS"_ basis, without WARRANTIES or conditions of any kind, either express or implied. 134 | 135 | See the License for the specific language governing permissions and limitations under the License. 136 | -------------------------------------------------------------------------------- /data-sources.tf: -------------------------------------------------------------------------------- 1 | # see https://www.terraform.io/docs/providers/google/d/organization.html for more information 2 | data "google_organization" "organization" { 3 | domain = var.project_domain 4 | } 5 | 6 | # see https://www.terraform.io/docs/providers/google/d/client_config.html for more information 7 | data "google_client_config" "current" {} 8 | 9 | # Retrieve all Projects for the current Region and Filter 10 | # see https://www.terraform.io/docs/providers/google/d/projects.html for more information 11 | data "google_projects" "projects" { 12 | filter = "" 13 | } 14 | 15 | # Retrieve all available Cloud Composer versions for the current region 16 | # see https://www.terraform.io/docs/providers/google/d/composer_image_versions.html for more information 17 | data "google_composer_image_versions" "versions" {} 18 | -------------------------------------------------------------------------------- /images/pre-commit-install.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksatirli/code-quality-for-terraform/e61a3aaec8a4a97314ad0ad6acd812dd13d97150/images/pre-commit-install.gif -------------------------------------------------------------------------------- /images/pre-commit-run-bad.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksatirli/code-quality-for-terraform/e61a3aaec8a4a97314ad0ad6acd812dd13d97150/images/pre-commit-run-bad.gif -------------------------------------------------------------------------------- /images/terraform-fmt-and-validate-good.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksatirli/code-quality-for-terraform/e61a3aaec8a4a97314ad0ad6acd812dd13d97150/images/terraform-fmt-and-validate-good.gif -------------------------------------------------------------------------------- /images/terraform-init.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksatirli/code-quality-for-terraform/e61a3aaec8a4a97314ad0ad6acd812dd13d97150/images/terraform-init.gif -------------------------------------------------------------------------------- /images/tflint.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksatirli/code-quality-for-terraform/e61a3aaec8a4a97314ad0ad6acd812dd13d97150/images/tflint.gif -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- 1 | output "organization_name" { 2 | description = "`name` value of the GCP Organization" 3 | value = data.google_organization.organization.name 4 | } 5 | 6 | output "organization_id" { 7 | description = "`id` value of the GCP Organization" 8 | value = data.google_organization.organization.id 9 | } 10 | 11 | output "organization_create_time" { 12 | description = "`create_time` value of the GCP Organization" 13 | value = data.google_organization.organization.create_time 14 | } 15 | 16 | output "client_config_project" { 17 | description = "`project` value of the GCP Client" 18 | value = data.google_client_config.current.project 19 | } 20 | 21 | output "client_config_region" { 22 | description = "`region` value of the GCP Client" 23 | value = data.google_client_config.current.region 24 | } 25 | 26 | output "composer_image_version_id" { 27 | description = "`image_version_id` of top-most GCP Cloud Composer Versions entry" 28 | value = data.google_composer_image_versions.versions.image_versions[0].image_version_id 29 | } 30 | -------------------------------------------------------------------------------- /provider.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | # credentials are inferred from the environment through `gcloud auth application-default login` 3 | # credentials = file("google_cloud_credentials.json") 4 | 5 | # optional, may also be configured via `gcloud config set project ` 6 | project = var.project_id 7 | 8 | # see https://cloud.google.com/compute/docs/regions-zones for more information 9 | region = var.project_region 10 | } 11 | -------------------------------------------------------------------------------- /terraform.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | google = "~> 3.31.0" 4 | } 5 | 6 | required_version = "0.13.5" 7 | } 8 | -------------------------------------------------------------------------------- /terraform.tfvars.sample: -------------------------------------------------------------------------------- 1 | project_id = "my-project-identifier" 2 | project_domain = "my-domain.com" 3 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | variable "project_id" { 2 | type = string 3 | description = "GCP Project to operate in" 4 | } 5 | 6 | variable "project_region" { 7 | type = string 8 | description = "GCP Region to operate in" 9 | default = "asia-south1" # Mumbai, India 10 | } 11 | 12 | variable "project_domain" { 13 | type = string 14 | description = "GCP Organization Domain to operate in" 15 | } 16 | --------------------------------------------------------------------------------