.tf file

Directory

  • A root module is required. Terraform command run here.

  • 0 or more child modules

  • (optional) variable.tf, outputs.tf

Type of .tf file

-- main.tf

-- providers.tf

Terraform providers include Amazon Web Services (AWS), Azure, Google Cloud Platform (GCP), Kubernetes, Helm, GitHub, Splunk, DataDog, and many more.

In GCP, the project can also be declared within provider block

{
  "provider": {
    "aws": [
      {
        "region": "us-east-1"
      },
      {
        "alias": "usw1",
        "region": "us-west-1"
      }
    ]
  }
}

-- variables.tf

Parameterize resource arguments to eliminate hard coding its values.

Ex: region, project ID, zone...

-- outputs.tf

Output values are stored in outputs.tf file.

Base template

The name field allows you to name the resource, and the type field allows you to specify the resource that you want to create.

# Create the mynetwork network
resource [RESOURCE_TYPE] "mynetwork" {
name = [RESOURCE_NAME]
# RESOURCE properties go here
}

Last updated