Terraform
From Halfface
Jump to navigationJump to search
what does it mean
aws_iam_role_policy_attachment Attaches a Managed IAM Policy to an IAM role coalesce Function. Takes any number of arguments and returns the first one that isn't null or an empty string. locals.tf Locals also known as local values or local variables, locals provide the means for expressing and storing values in the context of a specific code block. variables.tf variable "cluster_name" { description = "The name of the kubernetes cluster" type = string }
install terraform
sudo dnf install -y dnf-plugins-core sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo sudo dnf install terraform
Hardcoded install
cd /tmp/ ; curl -sk -L https://releases.hashicorp.com/terraform/1.5.5/terraform_1.5.5_linux_amd64.zip -O ; cd /usr/bin/ ; sudo unzip /tmp/terraform_1.5.5_linux_amd64.zip
file completion
complete -C /usr/bin/terraform terraform
Initiate terraform
terraform init
plan
Creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure.
terraform plan
show
Show what has been done.
terraform show
state
list resources within a Terraform state.
terraform state list
Show more info about individual entity.
terraform state show openstack_networking_network_v2.net3
Import state
terraform import module.kafka_eks.kubernetes_manifest.configmap_kafka_akhq "apiVersion=v1,kind=ConfigMap,namespace=kafka,name=akhq" terraform import module.kafka_eks.helm_release.akhq kafka/akhq
Name of statefile
terraform.tfstate
state nuke
rm -rf .terraform* terraform*
save and restore s3 state
Save state
terraform state pull > terraform.tfstate.backup-$(date +%F_%H-%M-%S)
Restore state
terraform state push terraform.tfstate.backup-YYYYMMDDHHMMSS
apply
Performs a plan just like terraform plan does, but then actually carries out the planned changes to each resource using the relevant infrastructure provider's API.
terraform apply
debug
TF_LOG=trace terraform init TRACE DEBUG INFO WARN ERROR
terraform output
Reads and output variable from a Terraform state file
cloud-init
set password on user
ssh_pwauth: false chpasswd: expire: false users: - name: root password: password type: text
tofu
Apply without asking.
tofu apply -auto-approve
destroy without asking
tofu destroy -auto-approve
tfk8s
contvert k8s yaml to terraform
tfk8s --strip --file <input> --output <output>
dynamodb
List tables
aws dynamodb list-tables
Look at table.
aws dynamodb scan --table-name
Delete row from table. aws dynamodb delete-item --table-name <your-lock-table> --key '{"LockID": {"S": "<lock-id>"}}'Remove terraform infrastructure
terraform destroy