Terraform Init and Providers
tf files
- After installation, you would start with a directory that has some file with a .tf extension.
- Convention says you should call the main configuration main.tf. but is you don't, terraform will load all files that ends with .tf
- Here's an example of the main configuration part, that should exist within one of you tf files:
1terraform {
2 required_providers {
3 aws = {
4 source = "hashicorp/aws"
5 version = "~> 3.0"
6 }
7 google = {
8 source = "hashicorp/google"
9 version = "~> 3.0"
10 }
11 }
12}
13provider "aws" {
14 region = "us-west-2"
15}
This is the main part of the configuration, and it requires the installation of 2 providers:
- aws provides (developed by Hashicorp)
- google provider (developed by Hashicorp) There is also another component (provider aws) that has configuration for the aws provider (in this case, the default region to use)
Terraform Init
- Use the terraform init command to see how terraform installs both providers.
- Look for the hidden .terraform directory, and look for the installed providers.
- You may also try the following commands:
-
terraform fmt simple syntax corrector that analyzes HCL in a given directory (including sub-directories) and corrects small syntactical issues
-
terraform validate runs a deeper scan of config to show potential issues with more complex problems such as circular dependencies and missing values
-