[Terraform] 공식 튜토리얼 따라하기

h222ji·2022년 3월 28일
0

What is Infrastructure as Code with Terraform?

Docker 인프라 구축

AWS 인프라 구축

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.27"
    }
  }

  required_version = ">= 0.14.9"
}

provider "aws" {
  profile = "default"
  region  = "ap-northeast-2"
}

resource "aws_instance" "app_server" {
  ami           = "ami-033a6a056910d1137"
  instance_type = "t2.micro"

  tags = {
    Name = "ExampleAppServerInstance"
  }
}

region check + ami(84x)
region별로 image id가 다른가봄

│ Error: Error launching source instance: InvalidAMIID.NotFound: The image id '[ami-830c94e3]' does not exist
│       status code: 400, request id: 66edaa7d-a9ac-49a9-9940-84a21978b3d5
│
│   with aws_instance.app_server,
│   on main.tf line 17, in resource "aws_instance" "app_server":17: resource "aws_instance" "app_server" {
│
╵

seoul region의 image id를 가져왔는데 또 다른 오류가 남

╷
│ Error: Error launching source instance: InvalidParameterValue: The architecture 'x86_64,i386' of the specified instance type does not match the architecture 'arm64' of the specified AMI. Specify an instance type and an AMI that have matching architectures, and try again. You can use 'describe-instance-types' or 'describe-images' to discover the architecture of the instance type or AMI.
│       status code: 400, request id: 8fa5d37e-c9b0-4763-b82d-771524f2eb29
│
│   with aws_instance.app_server,
│   on main.tf line 17, in resource "aws_instance" "app_server":17: resource "aws_instance" "app_server" {
│
╵

보니깐 instance type이 안맞는 듯해서 다시 aws에서 찾아보니

type별로 image id가 다름
그래서 64비트(x86) id로 다시 변경 후 에러 제거!

인프라 변경

인프라 파괴

입력 변수 지정

$terraform apply

$terraform apply -var "instance_name=YetAnotherName"

Query Data with Outputs

terraform apply

terraform destroy

profile
희지야 블로그 좀 쓰쟈.. plz....

0개의 댓글