A CI/CD pipeline that builds infrastructure components using Terraform must be designed.
A step in the pipeline is needed that checks for errors in any of the .tf files in the working directory.
It also checks the existing state of the defined infrastructure.
Which command does the pipeline run to accomplish this goal?
Click on the arrows to vote for the correct answer
A. B. C. D.D.
The correct answer for the given scenario is D. terraform validate.
Explanation:
Terraform is an infrastructure-as-code (IaC) tool that is used to manage infrastructure resources in a declarative way. A CI/CD pipeline is used to automate the build, test, and deployment of software applications and infrastructure changes. In this scenario, a CI/CD pipeline is being designed to build infrastructure components using Terraform, and a step is required to check for errors in the .tf files and validate the existing state of the defined infrastructure.
To accomplish this goal, the pipeline must run the terraform validate command. This command is used to validate the syntax and configuration of the Terraform files in the working directory. It checks for errors such as invalid syntax, missing required arguments, and unsupported configuration options.
The terraform validate command does not apply any changes to the infrastructure. It only validates the configuration files and reports any errors or warnings. This makes it a safe command to use in the pipeline without affecting the existing state of the infrastructure.
The terraform plan command is used to generate an execution plan for the changes to the infrastructure. It calculates the changes that will be made and displays them in a human-readable format. The terraform check command is not a valid Terraform command. The terraform fmt command is used to format the Terraform files to a consistent style and syntax, but it does not validate the configuration or check the existing state of the infrastructure.
Therefore, the correct answer is D. terraform validate, as it validates the syntax and configuration of the Terraform files in the working directory without applying any changes to the existing infrastructure.