0
0
Terraformcloud~10 mins

Creating your first resource in Terraform - Visual Walkthrough

Choose your learning style9 modes available
Process Flow - Creating your first resource
Write resource block
Run terraform init
Run terraform plan
Review plan output
Run terraform apply
Resource created in cloud
Run terraform show or state
Verify resource exists
You write a resource block, initialize Terraform, plan the changes, apply them to create the resource, then verify it exists.
Execution Sample
Terraform
resource "aws_s3_bucket" "my_bucket" {
  bucket = "my-unique-bucket-12345"
  acl    = "private"
}
This code creates a private S3 bucket named 'my-unique-bucket-12345' in AWS.
Process Table
StepCommand/ActionTerraform Output/StateResult
1Write resource block in main.tfFile saved with resource definitionResource definition ready
2terraform initInitializes backend and providersTerraform ready to run plans
3terraform planShows plan to create aws_s3_bucket.my_bucketPlan shows resource will be created
4terraform applyApplies plan, creates S3 bucketS3 bucket created in AWS
5terraform showDisplays current state with aws_s3_bucket.my_bucketConfirms resource exists
6terraform state listLists resources in stateaws_s3_bucket.my_bucket listed
7terraform apply againNo changes detectedNo resources changed, idempotent
💡 No changes after first apply, resource exists and Terraform state is up to date
Status Tracker
VariableStartAfter Step 3After Step 4Final
aws_s3_bucket.my_bucketundefinedplanned for creationcreated with IDexists in state
Key Moments - 3 Insights
Why does terraform plan show changes before apply?
Because terraform plan compares current state (empty at first) with desired config and shows what will be created, as seen in step 3 of execution_table.
What happens if you run terraform apply again without changes?
Terraform detects no changes needed and does nothing, showing 'No changes detected' as in step 7 of execution_table.
How do you verify the resource was created?
By running terraform show or terraform state list (steps 5 and 6), which confirm the resource exists in the state.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what does terraform plan show at step 3?
AResource will be destroyed
BNo changes needed
CResource aws_s3_bucket.my_bucket will be created
DError in configuration
💡 Hint
Check the 'Terraform Output/State' column at step 3 in execution_table
At which step does Terraform actually create the S3 bucket?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Look for 'Applies plan, creates S3 bucket' in the 'Command/Action' column
If you change the bucket name in the resource block and run terraform apply again, what will happen?
ATerraform will create a new bucket and delete the old one
BTerraform will ignore the change
CTerraform will update the existing bucket name in place
DTerraform will fail with an error
💡 Hint
Changing bucket name is a resource replacement, so terraform plans to create new and delete old (related to step 3 plan behavior)
Concept Snapshot
Terraform resource creation steps:
1. Write resource block in .tf file
2. Run 'terraform init' to prepare
3. Run 'terraform plan' to see changes
4. Run 'terraform apply' to create resource
5. Verify with 'terraform show' or 'terraform state list'
Terraform is idempotent: repeated apply with no changes does nothing.
Full Transcript
Creating your first resource with Terraform involves writing a resource block in a configuration file, initializing Terraform with 'terraform init', planning the changes with 'terraform plan', applying those changes with 'terraform apply', and verifying the resource exists using 'terraform show' or 'terraform state list'. The plan step shows what Terraform will do before it does it. After applying, Terraform records the resource in its state. Running apply again without changes results in no action, demonstrating idempotency.