Terraform Cloud事始めメモ#1|Dockerプロセス起動
■本家のサイトから行った
前提条件
以下作業は終了済み
1)アカウント作成
2)Organization 作成済
■Install Terraform
*ローカルからCLI経由でのパターン
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
brew update
brew upgrade hashicorp/tap/terraform
■Verify the installation
terraform -help
terraform -help plan
■Enable tab completion
touch ~/.zshrc
terraform -install-autocomplete
■Quick start tutorial
前提|Docker Desktopインストール
open -a Docker
# ワーキングディレクトリらしい
mkdir learn-terraform-docker-container
cd learn-terraform-docker-container
--
main.tf
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "~> 3.0.1"
}
}
}
provider "docker" {}
resource "docker_image" "nginx" {
name = "nginx"
keep_locally = false
}
resource "docker_container" "nginx" {
image = docker_image.nginx.image_id
name = "tutorial"
ports {
internal = 80
external = 8000
}
}
■Initialize the project
, which downloads a plugin called a provider that lets Terraform interact with Docker.
terraform init
■Provision the NGINX server,
container with apply. When Terraform asks you to confirm type yes and press ENTER.
これでNginxのDockerプロセスがRunされる
terraform apply
yesをタイプする
■To stop the container,
run terraform destroy.
terraform destroy
yesをタイプする