1. Terraform Commands
2. LifeCycle Rules
- lifecycle is a nested block that can appear within a resource block. The lifecycle block and its contents are meta-arguments, available for all resource blocks regardless of type.
- prevent_destroy = true
: prevent from accident delete
:not want to be destroyed - ignore_changes
: do not want TF to update the resource as the change is just a ‘tag’ something that we are happy to ignore
:"list"
Which of the following statements is FALSE about Immutable infrastructure?
It ensures updating this way will not lead to failures
3. Terraform Taint
- The terraform taint command informs Terraform that a particular object has become degraded or damaged. Terraform represents this by marking the object as "tainted" in the Terraform state, and Terraform will propose to replace it in the next plan you create.
- $ terraform apply → FAILS
- if provisioner fails :
- resource is “Tainted” by default (next apply will re-create)
- terraform taint null_resource.run_script
- terraform apply -replace="null_resource.run_script”
- want a particular resource to be recreated
- $ terraform taint aws_instance.webserver
- $ terraform untaint aws_instance.webserver
4. Logging
check error when need to look a little deeper
$ export TF_LOG=TRACE
$ export TF_LOG_PATH = “ / / “
$ head -10 /tmp/terraform.logs
- debugging can be controlled using TF_LOG , which can be configured for different levels TRACE, DEBUG, INFO, WARN or ERROR, with TRACE being the more verbose.
- logs path can be controlled TF_LOG_PATH. TF_LOG needs to be specified
- To persist logged output you can set TF_LOG_PATH in order to force the log to always be appended to a specific file when logging is enabled. Note that even when TF_LOG_PATH is set, TF_LOG must be set in order for any logging to be enabled.
How do I export Terraform logs?
$ export TF_LOG=trace.
Which environment variable is exported to set a different log level in the terraform?
TF_LOG
5. Terraform Import
import 나오면 무조건 $terraform apply 했을 시 오류 뜨는 이유 = haven’t updated the resource with correct argument values yet
- Terraform import is used to bring resources created by other means into the management of Terraform.
= helps import already-existing external resources, not managed by Terraform, into Terraform state and allow it to manage those resources
- Terraform is not able to auto-generate configurations for those imported modules, for now, and requires you to first write the resource definition in Terraform and then import this resource
- = configuration files have to be manually updated, when the state file is automatically updated
- You should create the equivalent configuration first, and then run import to load it on the state file.
6. Terraform Workplace
- helps manage multiple distinct sets of infrastructure resources or environments with the same code.
- just need to create needed workspace and use them, instead of creating a directory for each environment to manage
- state files for each workspace are stored in the directory terraform.tfstate.d
- terraform workspace new dev creates a new workspace and switches to it as well
- terraform workspace select dev helps select workspace
- terraform workspace list lists the workspaces and shows the current active one with ``
- does not provide strong separation as it uses the same backend
- default workspace can not be renamed
'[Terraform]' 카테고리의 다른 글
7. Terraform Modules (0) | 2024.04.19 |
---|---|
6. Terraform (0) | 2024.04.19 |
4. Terraform state (0) | 2024.04.19 |
3. Variable, Resource Attributes, Dependencies (0) | 2024.04.19 |
2. Terraform Providers Basics (0) | 2024.04.19 |