All technological notes.
Resources
Resource Behavior
Meta-Arguments section
Provisioners
provisioners are non-declarative and potentially unpredictable, we strongly recommend that you treat them as a last resort.resource block
Resource names must
# declear an ec2 instance
resource "aws_instance" "web" {
ami = "ami-a1b2c3d4"
instance_type = "t2.micro"
}
Within the block body (between { and }) are the configuration arguments for the resource itself.
resource is associated with a single resource type, which determines the kind of infrastructure object it manages and what arguments and other attributes the resource supports.Providers
provider.provider provides resources to manage a single cloud or on-premises infrastructure platform.To manage resources, a Terraform module must specify the required providers.
Most providers need some configuration to access their remote API, which is provided by the root module.
provider meta-argument to manually choose a provider configuration.Most of the arguments within the body of a resource block are specific to the selected resource type.
The resource type’s documentation lists which arguments are available and how their values should be formatted.
The values for resource arguments can make full use of expressions and other dynamic Terraform language features.
Meta-arguments are defined by Terraform and apply across all resource types.
Every Terraform provider has its own documentation, describing its resource types and their arguments.
Some provider documentation is still part of Terraform’s core documentation, but the Terraform Registry is the main home for all publicly available provider docs.
depends_on:for specifying hidden dependenciescount: for creating multiple resource instances according to a countfor_each: to create multiple instances according to a map, or set of stringsprovider: for selecting a non-default provider configurationlifecycle: for lifecycle customizationsprovisioner: for taking extra actions after resource creationTo remove a resource from Terraform, simply delete the resource block from your Terraform configuration.
resource block, Terraform will plan to destroy any real infrastructure object managed by that resource.Sometimes you may wish to remove a resource from your Terraform configuration without destroying the real infrastructure object it manages. In this case, the resource will be removed from the Terraform state, but the real infrastructure object will not be destroyed.
To declare that a resource was removed from Terraform configuration but that its managed object should not be destroyed, remove the resource block from your configuration and replace it with a removed block:
removed {
from = aws_instance.example
lifecycle {
destroy = false
}
}