Steps: (Perform these steps for both cdn config and preference config)
- Write a valid
.tffile with resource block for configuration. - Run
terraform apply. - Verify:
- Terraform shows successful creation.
- Resource exists in backend (via API or UI).
- Terraform state file reflects the new resource.
Steps:
- Simulate backend
POSTfailure (e.g., return 500 or 400). - Run
terraform apply. - Verify:
- Terraform fails gracefully with an appropriate error.
- No resource is created on the backend.
- Terraform state is unchanged.
Steps:
- Apply the resource.
- Run
terraform refresh. - Verify: No drift is detected.
Steps:
- Create resource using Terraform.
- Delete the resource directly from the backend.
- Run
terraform plan. - Verify: Terraform marks the resource as “to be created” (shows drift).
Steps:
- Create an initial resource.
- Modify the
.tffile (e.g., change a property value). - Run
terraform apply. - Verify:
- Backend reflects the updated value.
- State file is updated.
- No additional resources are created or deleted.
Steps:
- Simulate backend
PUTfailure. - Apply the change using Terraform.
- Verify:
- Terraform reports the failure.
- Retries or fallback behavior is handled appropriately.
Steps:
- Create and verify the resource.
- Remove the resource block from the
.tffile. - Run
terraform apply. - Verify:
- Resource is deleted in the backend.
- Resource is removed from the Terraform state.
Steps:
- Simulate backend
DELETEfailure (e.g., 500 or timeout). - Run
terraform apply. - Verify:
- Terraform reports the error.
- Resource remains in state and is not falsely removed.
Steps:
- Create and apply the resource.
- Run
terraform applyagain without modifying.tffile. - Verify: No changes are applied.
Steps:
- Apply config via Terraform.
- Modify backend config manually.
- Run
terraform plan. - Verify: Drift is detected and displayed in the plan.
Steps:
- Apply the resource using Terraform.
- Inspect the
.tfstatefile. - Verify that values match the current state in the backend.
Steps:
- Create a
.tffile with missing required attributes. - Run
terraform planorapply. - Verify:
- Terraform shows a validation error.
- No resource is created or changed.
Steps:
- Use invalid data types or enums in the
.tffile. - Run
terraform apply. - Verify:
- Terraform or backend rejects the request with a clear error.
- Use
terraform plandiff to inspect changes before applying. - Validate resource existence and correctness via API clients (e.g., Postman or curl).
- Test with multiple resources in one
.tffile. - Use
terraform workspaceto test isolated environments. - Run
terraform destroyto test cleanup behavior.