From 5b7cc2b6520da2e892f93b8e45b95afea3d97440 Mon Sep 17 00:00:00 2001 From: Adil Chahid Date: Mon, 30 Jan 2023 06:57:40 -0500 Subject: [PATCH 1/6] configuring a Terraform builld --- .github/workflows/terraform.yml | 93 +++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .github/workflows/terraform.yml diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml new file mode 100644 index 0000000..be34550 --- /dev/null +++ b/.github/workflows/terraform.yml @@ -0,0 +1,93 @@ +# This workflow installs the latest version of Terraform CLI and configures the Terraform CLI configuration file +# with an API token for Terraform Cloud (app.terraform.io). On pull request events, this workflow will run +# `terraform init`, `terraform fmt`, and `terraform plan` (speculative plan via Terraform Cloud). On push events +# to the "main" branch, `terraform apply` will be executed. +# +# Documentation for `hashicorp/setup-terraform` is located here: https://github.com/hashicorp/setup-terraform +# +# To use this workflow, you will need to complete the following setup steps. +# +# 1. Create a `main.tf` file in the root of this repository with the `remote` backend and one or more resources defined. +# Example `main.tf`: +# # The configuration for the `remote` backend. +# terraform { +# backend "remote" { +# # The name of your Terraform Cloud organization. +# organization = "example-organization" +# +# # The name of the Terraform Cloud workspace to store Terraform state files in. +# workspaces { +# name = "example-workspace" +# } +# } +# } +# +# # An example resource that does nothing. +# resource "null_resource" "example" { +# triggers = { +# value = "A example resource that does nothing!" +# } +# } +# +# +# 2. Generate a Terraform Cloud user API token and store it as a GitHub secret (e.g. TF_API_TOKEN) on this repository. +# Documentation: +# - https://www.terraform.io/docs/cloud/users-teams-organizations/api-tokens.html +# - https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets +# +# 3. Reference the GitHub secret in step using the `hashicorp/setup-terraform` GitHub Action. +# Example: +# - name: Setup Terraform +# uses: hashicorp/setup-terraform@v1 +# with: +# cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + +name: 'Terraform' + +on: + push: + branches: [ "development" ] + pull_request: + +permissions: + contents: read + +jobs: + terraform: + name: 'Terraform' + runs-on: ubuntu-latest + environment: production + + # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest + defaults: + run: + shell: bash + + steps: + # Checkout the repository to the GitHub Actions runner + - name: Checkout + uses: actions/checkout@v3 + + # 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@v1 + with: + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + + # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. + - name: Terraform Init + run: terraform init + + # Checks that all Terraform configuration files adhere to a canonical format + - name: Terraform Format + run: terraform fmt -check + + # Generates an execution plan for Terraform + - name: Terraform Plan + run: terraform plan -input=false + + # On push to "main", build or change infrastructure according to Terraform configuration files + # Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks + - name: Terraform Apply + if: github.ref == 'refs/heads/"main"' && github.event_name == 'push' + run: terraform apply -auto-approve -input=false From e9a905e85731abed2b8ae3fa0a6bb01786523f98 Mon Sep 17 00:00:00 2001 From: AdilusPrimus Date: Mon, 30 Jan 2023 07:11:02 -0500 Subject: [PATCH 2/6] Enforcing naming conventions --- env.auto.tfvars | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/env.auto.tfvars b/env.auto.tfvars index 5cc62e8..a2ab09a 100644 --- a/env.auto.tfvars +++ b/env.auto.tfvars @@ -1,5 +1,5 @@ linode_image = "linode/ubuntu18.04" -linode_image_label = "Terraform-Web-Example" -Linode_image_group = "Terraform" +linode_image_label = "tfs-linux-node" +Linode_image_group = "Linux" linode_image_deployment_region = "us-east" linode_image_type = "g6-standard-1" \ No newline at end of file From 50c3f7548ced558d8230f2a858a3813282983607 Mon Sep 17 00:00:00 2001 From: AdilusPrimus Date: Mon, 30 Jan 2023 07:15:45 -0500 Subject: [PATCH 3/6] Precising org name --- linode-terraform-web.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linode-terraform-web.tf b/linode-terraform-web.tf index 55d0f03..e4f5932 100644 --- a/linode-terraform-web.tf +++ b/linode-terraform-web.tf @@ -34,7 +34,7 @@ terraform { cloud { - organization = "innovarelabs" + organization = "org-WLsWrHL3sHWoinT1" workspaces { name = "linode-terraform" } From da4daa5f388189faedd41af86f335e17c4413b19 Mon Sep 17 00:00:00 2001 From: AdilusPrimus Date: Mon, 30 Jan 2023 07:26:41 -0500 Subject: [PATCH 4/6] Precising org name (round 2) --- linode-terraform-web.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linode-terraform-web.tf b/linode-terraform-web.tf index e4f5932..346b2a9 100644 --- a/linode-terraform-web.tf +++ b/linode-terraform-web.tf @@ -34,7 +34,7 @@ terraform { cloud { - organization = "org-WLsWrHL3sHWoinT1" + organization = "Innovarelabs" workspaces { name = "linode-terraform" } From d3b65bffdf0a93ca60d12ac2ed0a8e09439093fd Mon Sep 17 00:00:00 2001 From: AdilusPrimus Date: Mon, 30 Jan 2023 07:36:23 -0500 Subject: [PATCH 5/6] Bug fix tf cloud build --- linode-terraform-web.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linode-terraform-web.tf b/linode-terraform-web.tf index 346b2a9..181a276 100644 --- a/linode-terraform-web.tf +++ b/linode-terraform-web.tf @@ -36,7 +36,7 @@ terraform { cloud { organization = "Innovarelabs" workspaces { - name = "linode-terraform" + name = "linode-terraform" } } required_providers { From 93004354ab7ee5819d0c539b5c7d8d0a496acc80 Mon Sep 17 00:00:00 2001 From: AdilusPrimus Date: Mon, 30 Jan 2023 07:47:25 -0500 Subject: [PATCH 6/6] Refactor variables --- env.auto.tfvars => env.tfvars | 0 variables.tf => variables.auto.tf | 6 +++++- 2 files changed, 5 insertions(+), 1 deletion(-) rename env.auto.tfvars => env.tfvars (100%) rename variables.tf => variables.auto.tf (87%) diff --git a/env.auto.tfvars b/env.tfvars similarity index 100% rename from env.auto.tfvars rename to env.tfvars diff --git a/variables.tf b/variables.auto.tf similarity index 87% rename from variables.tf rename to variables.auto.tf index fdfee62..8537a62 100644 --- a/variables.tf +++ b/variables.auto.tf @@ -23,27 +23,31 @@ variable "root_pwd" { # sensitive = false by default variable "linode_image" { description = "Image template used to build the VM (OS)" + default = "linode/ubuntu18.04" type = string } variable "linode_image_label" { description = "Name of the provisioned node" + default = "tfs-linux-node" type = string } variable "Linode_image_group" { description = "Logical grouping of provisionned environments" + default = "Linux" type = string } variable "linode_image_deployment_region" { description = "Targetted data center region for deployment" + default = "us-east" type = string } variable "linode_image_type" { description = "Type of image: resources" + default = "g6-standard-1" type = string - sensitive = true } # End of defined variables in env.tfvaresource \ No newline at end of file