1Z0-997-25 Question 25
Single answerYour company is implementing Terraform-based Infrastructure as Code (IaC) on Oracle Cloud Infrastructure to manage multiple environments (development, test, and production). Each environment requires consistent resource definitions but will vary in compartment IDs, subnet OCIDs, and some shape configurations. You want to minimize code duplication while ensuring each environment can be provisioned cleanly. Which approach provides the most effective structure for handling these environment-specific differences?
- A
A) Create separate, fully independent Terraform configurations for each environment with hardcoded values.
- B
B) Use a single Terraform module with environment-specific variable files for compartment IDs and shape definitions, then specify the appropriate variable file during each environment's deployment.
- C
C) Store all environment details directly in environment variables and call them within a single Terraform configuration without variable files.
- D
D) Maintain a shared Terraform file for resource definitions but add manual conditional statements to handle each environment� unique values.
Show answer and explanation
Correct answer: B
Explanation
Using modules with environment-specific variable files is a best practice for Terraform-based Infrastructure as Code in OCI. It enables you to maintain a single codebase for core infrastructure definitions while cleanly separating environment-specific data. This keeps your provisioning process consistent, reduces duplication, and simplifies maintenance. Refer to Oracle� official Resource Manager and Terraform documentation for more details on organizing modules and variables effectively.
- A. Incorrect.
A) Incorrect. Maintaining entirely separate Terraform codebases for each environment increases complexity, duplication, and risk of configuration drift. While it isolates changes to each environment, it is not the most efficient or streamlined approach.
- B. Correct.
B) Correct. A single module used by different .tfvars files keeps your resource definitions consistent but allows environment-specific values (e.g., compartment IDs, shapes) to be passed in. This pattern streamlines code management and ensures consistent provisioning.
- C. Incorrect.
C) Incorrect. Storing all details in environment variables without variable files can lead to confusion and potential environment variable mismatches. It� also harder to maintain and track environment differences in a controlled, versioned manner.
- D. Incorrect.
D) Incorrect. Using manual conditional logic in a single Terraform configuration becomes unwieldy and error-prone as environment differences grow. It� more efficient to externalize environment-specific details to dedicated variable files.