0
0
Terraformcloud~10 mins

Creation-time vs destruction-time in Terraform - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Process Flow - Creation-time vs destruction-time
Start Terraform Apply
Creation-time: Create Resources
Resources Active
Start Terraform Destroy
Destruction-time: Delete Resources
Resources Removed
End
Terraform first creates resources during apply, then deletes them during destroy, each with specific timing and actions.
Execution Sample
Terraform
resource "aws_s3_bucket" "example" {
  bucket = "my-example-bucket"
}

output "bucket_name" {
  value = aws_s3_bucket.example.bucket
}
Creates an S3 bucket at creation-time and outputs its name; bucket is deleted at destruction-time.
Process Table
StepActionResource StateTerraform PhaseResult
1terraform apply startsNo resourcesCreation-timePreparing to create resources
2Create aws_s3_bucket.exampleBucket createdCreation-timeBucket 'my-example-bucket' exists
3Output bucket_nameBucket existsCreation-timeOutputs bucket name 'my-example-bucket'
4terraform apply endsResources activeCreation-timeResources ready for use
5terraform destroy startsResources activeDestruction-timePreparing to delete resources
6Delete aws_s3_bucket.exampleBucket deletedDestruction-timeBucket removed from cloud
7terraform destroy endsNo resourcesDestruction-timeAll resources destroyed
💡 terraform destroy completed, all resources removed
Status Tracker
VariableStartAfter CreationAfter Destruction
aws_s3_bucket.examplenullexistsnull
bucket_name outputnull"my-example-bucket"null
Key Moments - 3 Insights
Why can't we access the bucket output after destruction?
Because at destruction-time (see step 7), the bucket resource no longer exists, so outputs referencing it become invalid.
What happens if creation fails at step 2?
Terraform stops and does not proceed to output or resource activation, so no resources are created or output values set.
Is the bucket available immediately after step 2?
Yes, after creation at step 2, the bucket exists and can be used or referenced in outputs as shown in step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the resource state at step 4?
ANo resources
BBucket deleted
CResources active
DPreparing to delete resources
💡 Hint
Check the 'Resource State' column for step 4 in the execution_table.
At which step does Terraform start deleting resources?
AStep 3
BStep 5
CStep 2
DStep 7
💡 Hint
Look for 'terraform destroy starts' in the 'Action' column of the execution_table.
If the bucket creation failed at step 2, what would be the bucket_name output after step 3?
Anull
BError message
C"my-example-bucket"
DEmpty string
💡 Hint
Refer to variable_tracker and key_moments about creation failure effects.
Concept Snapshot
Terraform manages resources in two main phases:
- Creation-time: resources are created and become active.
- Destruction-time: resources are deleted and removed.
Outputs reflect resource state only when resources exist.
Destroy removes all created resources, cleaning the environment.
Full Transcript
Terraform works in two main phases: creation-time and destruction-time. During creation-time, Terraform creates resources like an S3 bucket and outputs their details. After creation, resources are active and usable. During destruction-time, Terraform deletes these resources, removing them from the cloud. Outputs depending on these resources become invalid after destruction. This flow ensures infrastructure is managed cleanly and predictably.