Code Snippet

Just another Code Snippet site

[Terraform] How-To

Install Terraform on Linux server :

wget https://releases.hashicorp.com/terraform/0.12.24/terraform_0.12.24_linux_amd64.zip
unzip terraform_0.12.24_linux_amd64.zip
cp terraform /usr/local/bin/
terraform -v

Check https://www.terraform.io/downloads.html for download


Main commands :
Init :

terraform init

Dry run :

terraform plan

Apply :

terraform apply

Destroy :

terraform destroy

Define docker provider (main.tf) :

# Find the latest Nginx image.
# Access it somewhere else with ${docker_image.nginx.latest}
resource "docker_image" "nginx" {
    name = "nginx"
}

resource "docker_container" "nginx" {
    image = "${docker_image.nginx.latest}"
    # Container name
    name = "nginx-tf"
    # Port mapping
    ports {
        internal = 80
        external = 80
    }
    # See https://www.terraform.io/docs/providers/docker/r/container.html for more configuration
}


6 thoughts on “[Terraform] How-To

Leave a Reply to OLIVIER COMBE Cancel reply

Your email address will not be published. Required fields are marked *