Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam Terraform Associate topic 1 question 22 discussion

Actual exam question from HashiCorp's Terraform Associate
Question #: 22
Topic #: 1
[All Terraform Associate Questions]

terraform init initializes a sample main.tf file in the current directory.

  • A. True
  • B. False
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Jlee7
Highly Voted 10 months, 2 weeks ago
The answer is False. The terraform init command does not initialize a sample main.tf file in the current directory. It initializes the working directory by downloading and installing provider plugins, downloading modules, and creating a Terraform state file. If you do not have a main.tf file in your working directory, Terraform will create one for you. However, the file will be empty. You will need to add your Terraform configuration to the main.tf file. You can find more information about the terraform init command in the Terraform documentation: https://www.terraform.io/docs/cli/commands/init.html
upvoted 15 times
vibzr2023
1 month, 1 week ago
The answer is False but terraform init will not create a empty main.tf file but will still initialize the directory for use with Terraform, setting up the necessary internal data structures and downloading providers specified in any Terraform configuration files that are present. If you run terraform init in an empty directory or a directory without any .tf files, Terraform will complete the initialization process but will indicate that no configuration files were found. You'll need to create main.tf or other .tf files manually. I ran a test ------ PS C:\Users\rajna\OneDrive\Documents\TerraformCI> terraform init Terraform initialized in an empty directory! The directory has no Terraform configuration files. You may begin working with Terraform immediately by creating Terraform configuration files. PS C:\Users\rajna\OneDrive\Documents\TerraformCI>
upvoted 2 times
...
...
aanataliya
Highly Voted 8 months ago
Selected Answer: A
Answer is A. See below points. 1. Question does not ask if it creates main.tf or not. it asks wheather main.tf initializes or not. 2. Ran terraform init in empty directory and it warns "The directory has no Terraform configuration files." it means it tries to find configuration file to initialize. 3. configuration file can be of any name with .tf extension. 4. ran command with main.tf in directory with extra curly braces and initialization fails. because it try to initialize main.tf 5. rename main.tf with sample.tf with extra curly braces and it still gives same error. 6. Official documentation says "command initializes a working directory containing Terraform configuration files". main.tf is a configuration file. Again, question never says it creates it. question clearly asks if main.tf is initialized. it means main.tf is already exists w.r.t. this question Reference: https://developer.hashicorp.com/terraform/cli/commands/init Please vote for this correct answer
upvoted 5 times
aanataliya
8 months ago
Those who are thinking its about creating main.tf. Question should have been "terrafom init creates sample init file" not initializes.
upvoted 2 times
...
Tyler2023
6 months, 2 weeks ago
The answer is B The question says terraform init initializes a sample main.tf file, think about the word "sample" meaning it creates the file which is terraform will not create that for you By default, terraform init assumes that the working directory already contains a configuration and will attempt to initialize that configuration. It will never try to create a sample file with sample configuration for you. But the question says it creates that sample file, meaning the direction is empty.
upvoted 1 times
...
...
SilentH
Most Recent 3 weeks, 4 days ago
Selected Answer: B
Even if the answer is somehow A, I'm voting B on principle.
upvoted 2 times
...
DianaPopal
4 months, 1 week ago
The correct answer is B. False. The terraform init command in Terraform is used to initialize a Terraform configuration in the current directory. It downloads the necessary provider plugins and sets up the backend configuration. However, terraform init does not create a sample main.tf file in the current directory. The main.tf file is the main configuration file in Terraform where you define your infrastructure resources and their configurations. It is typically created manually by the user and contains the desired state of the infrastructure. When you run terraform init, it looks for an existing main.tf file in the current directory to load the configuration. If the main.tf file does not exist, Terraform will not create it automatically.
upvoted 1 times
...
Hp45
8 months, 1 week ago
A lot of people are taking this question as init command is creating a main.tf. The context in the question is - if there was a sample main.tf in current folder then init would initialize the file. I vote for A.
upvoted 3 times
...
Shane_C
10 months ago
It absolutely does not generate a main.tf; B is the correct answer
upvoted 2 times
...
DuboisNicolasDuclair
10 months, 2 weeks ago
A Because terraform initialize *a sample main.tf* it means that we can have a multiple types of files like *.tf So A is a good answer
upvoted 2 times
Shane_C
10 months ago
It absolutely does not generate a main.tf; B is the correct answer
upvoted 2 times
...
...
karendavtyan
1 year ago
Selected Answer: B
B. False
upvoted 1 times
...
Ni33
1 year ago
Selected Answer: B
B is correct. It initializes versions and providers irrespective of name of the tf files.
upvoted 2 times
...
Rezi
1 year ago
A is correct 100% terraform init initializes any file with the extension ".tf" in the pwd. it says "a" sample main.tf, it didn't say "the" sample main.tf. Please note the difference.
upvoted 2 times
...
AzRNoob
1 year ago
B. False. The terraform init command initializes a new or existing Terraform working directory by downloading and installing any necessary plugins and modules specified in the configuration. It does not create a main.tf file or any other configuration file in the current directory. You will need to create a main.tf file (or another configuration file with a different name) manually and write the necessary configuration code for your infrastructure. Once you have done so, you can run terraform init to prepare the working directory for use with Terraform.
upvoted 2 times
...
Faaizz
1 year, 1 month ago
Selected Answer: B
BBBBBBBB
upvoted 1 times
...
Power123
1 year, 1 month ago
B for sure
upvoted 1 times
...
sagunala5
1 year, 1 month ago
By default, terraform init assumes that the working directory already contains a configuration and will attempt to initialize that configuration.
upvoted 2 times
...
Nunyabiznes
1 year, 1 month ago
Selected Answer: B
The terraform init command initializes a new or existing Terraform working directory by downloading and installing any required providers and modules, as well as setting up the backend. It does not create a sample main.tf file in the current directory. The main.tf file is a configuration file where you define the resources that you want to create using Terraform. It needs to be created manually by the user.
upvoted 2 times
sagunala5
1 year, 1 month ago
who asked whether sample main.tf was created, they are asking if is it initialising. so my answer is A
upvoted 1 times
Shane_C
10 months ago
Not correct, init does not generate a main.tf for you; B is the correct answer
upvoted 1 times
...
...
...
Nunyabiznes
1 year, 1 month ago
The terraform init command initializes a new or existing Terraform working directory by downloading and installing any required providers and modules, as well as setting up the backend. It does not create a sample main.tf file in the current directory. The main.tf file is a configuration file where you define the resources that you want to create using Terraform. It needs to be created manually by the user.
upvoted 1 times
...
Mal_8
1 year, 2 months ago
Selected Answer: B
It's not a must for the file name to be "main.tf". It checks all .tf files in the current directory and does the needful.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...