What happens when you run terraform init for the first time?
medium
A. Terraform creates the S3 bucket automatically
B. Terraform applies the infrastructure changes immediately
C. Terraform deletes any existing state files locally
D. Terraform downloads provider plugins and configures remote state in the S3 bucket
Solution
Step 1: Understand backend init behavior
On first terraform init, Terraform downloads required plugins and sets up remote state backend.
Step 2: Check resource creation
Terraform does NOT create the S3 bucket automatically; it expects it to exist.
Final Answer:
Terraform downloads provider plugins and configures remote state in the S3 bucket -> Option D
Quick Check:
Init downloads plugins + configures backend [OK]
Hint: Init downloads plugins, configures backend; no resource creation [OK]
Common Mistakes:
Assuming S3 bucket is created automatically
Thinking init deletes local state files
Confusing init with apply
4. You changed your Terraform backend from local to remote S3 but forgot to migrate the state. What error will you likely see when running terraform init?
medium
A. Error: No existing state found in the remote backend
B. Error: Backend configuration block missing
C. Error: State file already exists locally and cannot be overwritten
D. Error: Terraform version mismatch
Solution
Step 1: Understand backend migration
When switching backend types, Terraform expects existing state in the new backend or migration.
Step 2: Identify error on missing remote state
If state is not migrated, terraform init reports no existing state found remotely.
Final Answer:
Error: No existing state found in the remote backend -> Option A
Quick Check:
Missing remote state = no existing state error [OK]
Hint: Missing migrated state causes 'no existing state' error [OK]
Common Mistakes:
Expecting backend config missing error
Confusing local state overwrite error
Blaming Terraform version mismatch
5. You want to migrate your Terraform state from a local backend to an Azure Blob Storage backend. Which sequence of steps is correct to safely migrate the state?
hard
A. 1. Update backend block to Azure Blob Storage
2. Run 'terraform init' with '-migrate-state'
3. Verify state in Azure
4. Continue with 'terraform apply'
B. 1. Delete local state file
2. Update backend block to Azure Blob Storage
3. Run 'terraform apply'
4. Run 'terraform init'
C. 1. Run 'terraform apply'
2. Update backend block to Azure Blob Storage
3. Run 'terraform init'
4. Verify state in Azure
D. 1. Update backend block to Azure Blob Storage
2. Run 'terraform init' without flags
3. Manually copy state file to Azure
4. Run 'terraform apply'
Solution
Step 1: Update backend block to new backend
Change Terraform config to use Azure Blob Storage backend.
Step 2: Run 'terraform init' with migration flag
Use terraform init -migrate-state to move existing state safely to new backend.
Step 3: Verify state is in Azure
Check Azure Blob Storage to confirm state file is present.
Step 4: Continue normal workflow
Run terraform apply to manage infrastructure with new backend.
Final Answer:
1. Update backend block to Azure Blob Storage
2. Run 'terraform init' with '-migrate-state'
3. Verify state in Azure
4. Continue with 'terraform apply' -> Option A