How to delete local and remote tags on Git
Delete a tag local
$ git tag -d <tag_name>
Delete a tag remote
$ git push --delete origin tagname
Checkout the commit that you want to retag. Grab the SHA from your GitHub histroy
git checkout <SHA>
git tag m.m.p
git push --tags
git checkout main
Our root module structure is as follows:
PROJECT_ROOT
│
├── main.tf # everything else
├── variables.tf # stores the structure of input variables
├── providers.tf # defines required providers & configuration
├── outputs.tf # stores the outputs
├── terraform.tfvars # the data of variables we want to load into our Terraform project
└── README.md # required for root modules
In Terraform we can set two kind of variables:
- Enviroment Variables - those you would set in your bash terminal (e.g. AWS credentials)
- Terraform Variables - those that you would normally set in your
.tfvars
file
We can set Terraform Cloud variables to be sensitive so they are not shown visibliy in the UI.
We can use the -var
flag to set an input variable or override a variable in the tfvars file eg. terraform -var user_uuid="my-user_uuid"
- TODO: Document this flag
This is the default file to load in Tterraform variables in bulk
- TODO: Document this functionality for Terraform Cloud
- TODO: Document which Terraform variables takes precedence
If you lose your state files, you most likely have to tear down all you cloud infrastructure manually
You can use Terraform import but it will not work for all cloud resources. You need to check the Terraform providers documentation
terrafrom import aws_s3_bucket.bucket bucket-name
- If someone goes and delete or modifies cloud resource manually through ClickOps.
- If we run Terraform plan with the attampt to put the infrastructure back into the expected state (fixing configuration drift)
terraform apply -refresh-only -auto-approve
It is recommended to place modules in a modules
directory when eveloping modules locally
module "terrahouse_aws" {
user_uuid = var.user_uuid
bucket_name = var.bucket_name
}
We can pass input variables into our module. The module has to declare the Terraform variables in its own variables.tf
Using the source we can import the module from various place (locally, GitHub, Terraform Registry)
module "terrahouse_aws" {
source = "./modules/terrahouse_aws"clear
}
LLM such as ChatGPT may not be trained on the latest documention or information about Terraform (since it is last update in 2021)
It may likely produce older examples that could be depcrated (this often affects the providers, since they change more often)
This is a built-in Terrafom function to check the existence of a a file
validation {
condition = fileexists(var.index_html_file_path)
error_message = "The specified index.html file path is not a valid file or does not exist."
}
filemd5 is a variant of md5 that hashes the contents of a given file rather than a literal string.
In Terraform ther is special variable called path
that allows us to referece local paths
pat.module
- get the path for the current modulepat.root
- get the path for the root module
resource "aws_s3_object" "index_html" {
bucket = aws_s3_bucket.website_bucket.bucket
key = "index.html"
source = ${path.root}/public/index.html
}
Locals allow us to define local variables. They can be very useful when we need to transform data into another format and have it referenced as a variable.
locals {
s3_origin_id = "MyS3Origin"
}
This allows us to source data from cloud resources. This is useful when we want to reference cloud resources without importing them.
data "aws_caller_identity" "current" {}
output "account_id" {
value = data.aws_caller_identity.current.account_id
}
We use the jsonencode
function to create the JSON policy inline in the HCL
> jsonencode({"hello"="world"})
{"hello":"world"}
Plain data values such as Local Values and Input Variables don't have any side-effects to plan against and so they aren't valid in replace_triggered_by. You can use terraform_data's behavior of planning an action each time input changes to indirectly use a plain value to trigger replacement.