0
0
Terraformcloud~10 mins

Resource types and names in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Resource types and names
Start Terraform config
Define resource block
Specify resource type
Assign resource name
Add resource properties
Terraform processes resource
Resource created in cloud
Terraform config starts by defining a resource block with a type and a name, then properties, which Terraform uses to create the resource.
Execution Sample
Terraform
resource "aws_s3_bucket" "my_bucket" {
  bucket = "my-unique-bucket-123"
  acl    = "private"
}
Defines an AWS S3 bucket resource with type 'aws_s3_bucket' and name 'my_bucket'.
Process Table
StepActionResource TypeResource NamePropertiesResult
1Read resource block startBegin parsing resource
2Identify resource typeaws_s3_bucketResource type set
3Identify resource nameaws_s3_bucketmy_bucketResource name set
4Read propertiesaws_s3_bucketmy_bucketbucket = "my-unique-bucket-123", acl = "private"Properties stored
5Terraform plans resourceaws_s3_bucketmy_bucketbucket = "my-unique-bucket-123", acl = "private"Plan created
6Terraform applies resourceaws_s3_bucketmy_bucketbucket = "my-unique-bucket-123", acl = "private"S3 bucket created in AWS
7End of resource blockResource creation complete
💡 Resource block fully processed and resource created in cloud provider.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
resource_typeaws_s3_bucketaws_s3_bucketaws_s3_bucketaws_s3_bucket
resource_namemy_bucketmy_bucketmy_bucket
properties
bucket: my-unique-bucket-123
acl: private
bucket: my-unique-bucket-123
acl: private
Key Moments - 2 Insights
Why do we need both a resource type and a resource name?
The resource type tells Terraform what kind of cloud resource to create (like an S3 bucket), and the resource name is a local label to refer to this resource in the Terraform code. See execution_table rows 2 and 3.
Can two resources have the same name?
No, resource names must be unique within the same type in a Terraform configuration to avoid confusion. This is shown by the single resource name 'my_bucket' in execution_table row 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the resource name after step 3?
Abucket
Baws_s3_bucket
Cmy_bucket
Dprivate
💡 Hint
Check the 'Resource Name' column in execution_table row 3.
At which step does Terraform apply the resource to the cloud?
AStep 4
BStep 6
CStep 5
DStep 7
💡 Hint
Look for the 'Result' column mentioning 'S3 bucket created in AWS' in execution_table.
If you change the resource name from 'my_bucket' to 'your_bucket', which variable changes in variable_tracker?
Aresource_name
Bresource_type
Cproperties
Dnone
💡 Hint
Check the 'resource_name' row in variable_tracker for changes.
Concept Snapshot
Terraform resource blocks define cloud resources.
Syntax: resource "resource_type" "resource_name" { properties }
Resource type specifies the cloud service.
Resource name is a local label.
Properties configure the resource.
Terraform uses these to create and manage cloud infrastructure.
Full Transcript
In Terraform, you define resources using blocks that start with the keyword 'resource'. Each resource block requires a resource type, which tells Terraform what kind of cloud resource to create, such as an AWS S3 bucket. Next, you assign a resource name, which is a local identifier used within your Terraform code to refer to that resource. Inside the block, you specify properties that configure the resource, like the bucket name and access control list for an S3 bucket. Terraform reads these definitions step-by-step: it first identifies the resource type, then the resource name, then reads the properties. After parsing, Terraform plans the resource creation and then applies it, creating the actual resource in the cloud. Resource names must be unique within the same type to avoid confusion. This process ensures your infrastructure is defined clearly and managed effectively.