Skip to content

Commit

Permalink
chore: Update Terraform tags to use "ManagedBy" instead of "Terraform"
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Jul 3, 2024
1 parent 1a9b6a2 commit a518845
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
crash.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
# *.tfvars
# *.tfvars.json
Expand All @@ -26,7 +26,7 @@ override.tf.json
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# Include tfplan files to ignore the plan output of command: terraform plan -out tfplan
# example: *tfplan*
*tfplan*

Expand Down
2 changes: 1 addition & 1 deletion live/common-infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
Review and verify the deployment plan:
```sh
terraform plan -var-file ./configs/prod.tfvars -out=prod.tfplan
terraform plan -var-file ./configs/prod.tfvars -out prod.tfplan
```
2. **Execute the Plan:**
Expand Down
2 changes: 1 addition & 1 deletion live/core-networking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
Review and verify the deployment plan:
```sh
terraform plan -var-file ./configs/prod.tfvars -out=prod.tfplan
terraform plan -var-file ./configs/prod.tfvars -out prod.tfplan
```
2. **Execute the Plan:**
Expand Down
13 changes: 11 additions & 2 deletions live/terraform-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,31 @@
terraform init
```

2. **Workspace Management:**

Select or create a new workspace tailored to your deployment environment:

```sh
# Switch to the another workspace or create it if it doesn't exist
terraform workspace select -or-create prod
```
## Deploy
1. **Plan the Deployment:**
Generate an execution plan for Terraform:
```sh
terraform plan -var-file ./configs/common-infra.tfvars -out ./terraform-backend.tfplan
terraform plan -var-file ./configs/prod.tfvars -out ./prod.tfplan
```
2. **Apply the Configuration:**
Apply the configuration to set up the S3 bucket and DynamoDB table:
```sh
terraform apply "./terraform-backend.tfplan"
terraform apply "./prod.tfplan"
```
🚀 **NOTE:** Confirm the actions before proceeding to ensure that the correct resources are being created or modified.
Expand Down
10 changes: 6 additions & 4 deletions live/terraform-backend/backend.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ module "terraform_state_backend" {
source = "cloudposse/tfstate-backend/aws"
version = "1.1.1"

name = var.name
namespace = var.namespace
attributes = ["state"]
name = var.name
namespace = var.namespace
environment = var.environment
stage = var.stage
attributes = ["state"]

terraform_backend_config_file_path = "."
terraform_backend_config_file_name = "s3-backend.tf"
terraform_state_file = "${var.namespace}-${var.name}.tfstate"
terraform_state_file = "${module.label.id}.tfstate"

bucket_enabled = true
dynamodb_enabled = true
Expand Down
8 changes: 0 additions & 8 deletions live/terraform-backend/configs/common-infra.tfvars

This file was deleted.

10 changes: 10 additions & 0 deletions live/terraform-backend/configs/prod.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# General settings

region = "us-west-2"
name = "common-infra-tf-backend"
namespace = "nan"
environment = "prod"
tags = {
"ManagedBy" = "Terraform"
"Environment" = "prod"
}
10 changes: 10 additions & 0 deletions live/terraform-backend/configs/staging.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# General settings

region = "us-west-2"
name = "common-infra-tf-backend"
namespace = "nan"
environment = "prod"
tags = {
"ManagedBy" = "Terraform"
"Environment" = "prod"
}
28 changes: 28 additions & 0 deletions live/terraform-backend/context.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ variable "namespace" {
default = "development"
}

variable "environment" {
description = "Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT'"
type = string
default = "development"
}

variable "stage" {
description = "Stage, e.g. 'build', 'test', 'deploy', 'release'"
type = string
# not required, so no default
default = null
}

variable "tags" {
description = "Any extra tags to assign to objects"
type = map(any)
Expand All @@ -24,3 +37,18 @@ locals {
By = data.aws_caller_identity.aws.arn
}
}

// Keep labels, tags consistent
module "label" {
source = "cloudposse/label/null"
version = "0.25.0"

name = var.name
environment = var.environment
namespace = var.namespace
stage = var.stage

delimiter = "-"
label_order = ["namespace", "environment", "stage", "name", "attributes"]
tags = merge(var.tags, local.tf_tags)
}

0 comments on commit a518845

Please sign in to comment.