| terraform.tfvars| When you create a named terraform.tfvars file it will be automatically loaded when running terraform apply
|my_variables.tfvars| You can create additional variables files eg . dev.fvars, prod.tfvars. They will not be autoloaded( you will need to specify them in via command line)
|my_variables.auto.tfvars| if you name your file with auto.tfvars it will always be loaded.
|-var-file dev.tfvars| You can specifiv variables inline via the command line for individual overrides.
|-var ec2_type="t2.micro"| You can speific variables inline via the command line for individual overrides
|TF_VAR_my_variable_name| Terraform will watch for environment variables that begin with TF_VAR_ and apply those as variables.
Environment variables terraform.tfvars terraform.tfvars.json *.auto.tfvars or *.auto.tfvars.json -var and -var-file
Terraform language defines several meta-arguments, which can be used with any resource type to change the behavior of resources.
- depends_on : for specifying explict dependencies
- count: for creating multiple resource instances according to a count.
- for_each: to create multiple instances according to a map, or set of strings.
- provider: for selecting a non-default provider configuration.
- lifecycle: for lifecycle customizations.
- provisioner and connection: for taking extra actions after resource creation.
Lifecycle block allows you to change what happens to resource eg. create, update, destroy. Lifecycle blocks are nested within resources
- crete_before_destroy(bool) When replacing a resource first create the new resource before deleting it(the default is destroyed old first)
- prevent_destroy(bool) Ensures a resource is not destroyed
- ignore_changes(list of attributes) Don't change the resource( create,update,destroy) the resource if a change occurs for the listed attributes.