Technology Encyclopedia Home >What does Terraform's configuration file contain?

What does Terraform's configuration file contain?

Terraform's configuration file contains the definitions of the infrastructure resources that you want to create, manage, or modify. These files are written in HashiCorp Configuration Language (HCL) and describe the desired state of your infrastructure in a declarative manner.

The configuration file typically includes:

  1. Providers: Specifies the cloud provider or service that Terraform will interact with, such as AWS, Azure, or Google Cloud.

  2. Resources: Defines the specific resources to be created, such as virtual machines, storage buckets, or databases.

  3. Variables: Allows you to parameterize your configuration, making it more flexible and reusable.

  4. Outputs: Defines values that should be output after the Terraform apply command is executed, which can be useful for verifying the results or integrating with other tools.

  5. Data Sources: Provides information about existing resources that Terraform can use to configure other resources.

Example:

provider "aws" {
  region = "us-west-2"
}

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"

  tags = {
    Name = "example-instance"
  }
}

output "instance_public_ip" {
  value = aws_instance.example.public_ip
}

In this example:

  • The provider block specifies that Terraform will interact with AWS.
  • The resource block defines an AWS EC2 instance to be created.
  • The output block specifies that the public IP address of the instance should be output after the instance is created.

For those interested in using Terraform with Tencent Cloud, Tencent Cloud provides official Terraform providers that allow you to manage Tencent Cloud resources using Terraform configurations.