Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 179


Why should secrets not be hard coded into Terraform code? (Choose two.)

Show Answer
Correct Answer: AB

Hard coding secrets into Terraform code creates several issues. Firstly, it makes the code less reusable because the secrets are tied to a specific environment or set of credentials, requiring modifications for use in different contexts. Secondly, Terraform code is typically stored in version control systems and may be copied to various locations where it is executed, such as a developer's machine or CI/CD pipeline. These locations might lack robust security mechanisms, exposing the secrets to potential unauthorized access.

Discussion

26 comments
Sign in to comment
yaza
Sep 23, 2022

AB, terraform code will not be copied to target resource, if you deploy a VM the code will not copied to the VM

yaza
Oct 6, 2022

Selected Answer: AB

brax404Options: AB
Oct 18, 2023

Explanation: A. It makes the code less reusable: Hard coding secrets means the Terraform code is tied to a specific environment or set of credentials. This makes it hard to reuse the code in different contexts or environments without modifying the secrets. B. Terraform code is typically stored in version control, as well as copied to the systems from which it's run. Any of those may not have robust security mechanisms: Storing secrets directly in the Terraform code exposes those secrets to anyone who has access to the code. Furthermore, secrets may be logged in version control history, making them discoverable long after they've been removed or changed.

depal_dhirOptions: BC
Sep 7, 2022

These are DevSecOps best practice options

AShahine21
Dec 25, 2022

What the hell some people are voting for A!!!!

RVivek
Sep 27, 2022

The code will not be copied to Resources hence C is wron A is correct because if a secret to connect to a DB or backed is used in code and if the code is executed where they use a diffrent DB/backend the code cannot run. So hard coding passwords makes the code less usable

sejarOptions: AB
Nov 29, 2022

Code will not be copied to target location

gekkehenkOptions: AB
Jan 11, 2023

A, because "hard coding" in general makes code less re-usable. B, VCS is also true, this might expose the password

resnefOptions: AB
Jan 15, 2023

answer is AB C is wrong, as yaza said, terraform code will not be copied to target resource, if you deploy a VM the code will not copied to the VM

kounilascoOptions: AB
Jan 16, 2023

A and B are good answers

kiran15789Options: BC
May 8, 2023

B and C are security related

March2023Options: BC
Jun 15, 2023

B and C

Rajmane
Aug 9, 2023

Exactly 💯

vvkgp
Aug 21, 2023

Answer is B and C, as its a serious security breach. A - just mentions about best practices.

Aiwa23
Oct 15, 2023

B and C. My Terraform source code is in github repo, and when I use pipelines to run terraform, the source code gets downloaded in the CI/CD or build server or terraform server and access holder to this server could see them. The question terms this server as the target resource. Yes, hardcoding does make it less reusable, but there is a way around- using environment specific tfvars.

3cc17f1
Oct 25, 2023

I vote A and B, because C doesn't make sense. Why would the terraform code be copied to the target resources? For example, I provision an Azure Storage account using terraform. There's no point at which the terraform code ends up on that storage account.

kounilascoOptions: AB
Jan 17, 2023

i choose A and B

Daro_
Jan 25, 2023

BC in my opinion

khaled_razoukOptions: BC
Mar 10, 2023

B&C is the correct answer

campsOptions: BC
Mar 31, 2023

B. Terraform code is typically stored in version control, as well as copied to the systems from which it's run. Any of those may not have robust security mechanisms. C. The Terraform code is copied to the target resources to be applied locally and could expose secrets if a target resource is compromised. Storing secrets, such as passwords or API keys, directly in Terraform code is a bad practice for several reasons. Firstly, Terraform code is typically stored in version control, and it may be copied to multiple systems from which it's run, such as a developer's machine, a CI/CD pipeline, or a Terraform cloud workspace. Any of those systems may not have robust security mechanisms, and exposing secrets in code leaves them vulnerable to potential attacks. Secondly, the Terraform code is copied to the target resources to be applied locally, so any secrets in the code could be exposed if a target resource is compromised. Therefore, it is recommended to use a secrets management system, such as HashiCorp Vault or AWS Secrets Manager, to store and manage secrets outside of Terraform code.

090200f
Jul 23, 2024

agreed

NunyabiznesOptions: BC
Apr 2, 2023

def, BC

ChinensisOptions: AB
Apr 3, 2023

For me the answer C does not make sense...

Stanislav4907Options: BC
Apr 10, 2023

B. Terraform code is typically stored in version control, as well as copied to the systems from which it's run. Any of those may not have robust security mechanisms. Storing secrets in plain text within code, especially if it's publicly accessible or shared, increases the risk of the secrets being compromised. If the code is stored in a version control system, it's important to ensure that the secrets are not accidentally exposed in the version history. C. The Terraform code is copied to the target resources to be applied locally and could expose secrets if a target resource is compromised. If the Terraform code contains secrets, then those secrets will be copied to the target resources during the deployment process. If any of the target resources are compromised, the secrets may be exposed. It's important to keep secrets separate from the code and ensure that they are securely transmitted to the target resources when needed.

joyboy23
Jul 6, 2023

Will the code be copied though ?

FarziWaliMarziOptions: AB
Apr 22, 2023

A and B

joyboy23Options: AB
Jul 6, 2023

AB, I don't think a terraform code is copied to any place(local, backend, any modules etc.,) But, The values of the variables are rendered into the state file. where the key/secrets are exposed

090200fOptions: BC
Jul 23, 2024

Seems like BC are correct answers , A is like ambiguity type means so we've to follow the best practices seems like not related to this question

mussha
Oct 28, 2024

AB, Hardcoding secrets (like passwords) in Terraform is bad because: Sharing Risk: If the code is shared or stored, anyone can see the secrets and misuse them. Hard to Reuse: If you want to use the code somewhere else, you’d have to change the secrets every time. Keeping secrets separate is safer and makes the code easier to use again.

thureOptions: BC
Mar 31, 2025

Version Control Exposure (B): Terraform code is often stored in repositories (e.g., GitHub, GitLab). Secrets in code become visible in commit histories, even if later removed. Systems running Terraform (e.g., CI/CD pipelines) may lack proper security controls, exposing secrets in logs or environment variables. Target Resource Compromise (C): Secrets embedded in user data or scripts (e.g., cloud-init) may be stored on provisioned resources (e.g., VMs). If compromised, attackers can extract secrets directly from the resource.