从零开始的Terraform生活
简介
对于几乎没有terraform知识的人,记录下初次接触terraform并在AWS上构建基础架构的步骤
GitHub 存储库
安装terraform。
按照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
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
安装
$ brew tap hashicorp/tap
$ brew install hashicorp/tap/terraform
$ brew upgrade hashicorp/tap/terraform
自动补全
$ terraform -install-autocomplete
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
如果无法访问此网址,请检查是否受到ESET等安全软件的影响。