Table of Contents
Terraform is an open-source infrastructure as code software tool that enables you to safely and predictably create, change, and improve infrastructure. The cloud computing tool assists in building, modifying, and versioning infrastructure in a secure and efficient manner.
In this project I crafted a Terraform file to automate the process of creating a Docker container that runs a Nginx web server image.
These are instructions for Windows Users. To gather instruction for other OS please visit: https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/gcp-get-started
To get started you would want to make sure you have the following utlities installed:
- Terraform
- Docker
- WSL2
Create a directory named learn-terraform-docker-container:
mkdir learn-terraform-docker-container
Then navigate into it:
cd learn-terraform-docker-container
Paste the following Terraform configuration into a file and name it main.tf:
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = ">= 2.16.0"
}
}
}
provider "docker" {
}
resource "docker_image" "nginx" {
name = "nginx:latest"
keep_locally = false
}
resource "docker_container" "nginx" {
image = docker_image.nginx.latest
name = "tutorial"
ports {
internal = 80
external = 8000
}
}
Then initialize the project:
terraform init
And finally provision and push the configuration:
terraform apply
If all goes well you should see the Nginx container running of localhost:800 or by running docker ps:
After that is done, be sure to stop the container and destroy the Nginx webserver:
terraform destroy
For examples, please refer to the Documentation
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt for more information.
Project Link: https://github.com/iqtheengineer/gcp-terraform-project
