概要
terraformの知識はほとんどなく、初めて触るレベルの人間がterraformでAWSでインフラを構築するまでの手順を記し残す
githubリポジトリ
terraformをinstall
HashiCorpのチュートリアルに沿ってインストール
- https://www.terraform.io/docs#get-started
- https://learn.hashicorp.com/terraform?utm_source=terraform_io&utm_content=terraform_io_hero AWS
- https://learn.hashicorp.com/collections/terraform/aws-get-started
- https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started
install
$ brew tap hashicorp/tap
$ brew install hashicorp/tap/terraform
$ brew upgrade hashicorp/tap/terraform
autocomplete
$ terraform -install-autocomplete
main.tf
terraform {
required_providers {
docker = {
source = "terraform-providers/docker"
}
}
}
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
}
}
docker起動
$ terraform init
$ terraform apply
http://localhost:8000/
これでアクセスできない場合、ESETなどのセキュリティソフトが起因していることがあります。