[Terraform] 테라폼 약간 심화
* 테라폼으로 s3 생성해보고, ec2 생성해보려다가 배우게 된 개념 정리 글입니다.
https://juyeonee826.tistory.com/165?category=1115302
[Terraform] 테라폼 완전 기초
* 테라폼 이제 시작하는 사람이 작성하는 테라폼 완전 기초 개념 글입니다. 테라폼 구성요소 provider : AWS, Azure, Google Cloud Platform, Alibaba Cloud 와 같은 클라우드 제공업체(provider 종류) resource: AWS에서
juyeonee826.tistory.com
완전 기초를 작성할 때는 몰랐던 개념들을 더 배우게 되었다.
테라폼 구성요소
provider : AWS, Azure, Google Cloud Platform, Alibaba Cloud 와 같은 클라우드 제공업체(provider 종류)
resource: AWS에서 EC2 인스턴스, S3 버킷, RDS 데이터베이스 와 같은 인프라 리소스(resource는 provider document에서 확인)
variables : 실수하기 쉬운 변수 저장
variable "linux_instance_type" {
type = string
description = "EC2 instance type for Linux Server"
default = "t2.micro"
}
이렇게 작성해두고
resource "aws_instance" "linux-server" {
ami = data.aws_ami.amazon-linux-2.id
...
}
이렇게 씀
output : 테라폼 apply 후 지정된 리소스를 출력해줌, terraform output 으로 출력도 가능
output "ip" {
value = aws_eip.ip.public_ip
}
이렇게 작성해두면
$ terraform output ip
50.17.232.209
이렇게 사용
data : 이미 있는 리소스를 가져오는 것
data "aws_ami" "amazon-linux-2" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm*"]
}
}
이렇게 작성해두면
resource "aws_instance" "linux-server" {
ami = data.aws_ami.amazon-linux-2.id
...
}
이렇게 씀
destroy : 테라폼 코드를 실행하여 인프라를 삭제
# 일부 리소스만 제거
terraform destroy -target=aws_instance.linux_server
참고
https://jybaek.tistory.com/899
[Terraform] providers, resource, variables, output, data
providers, resource, data, module 등을 묶어서 뭐라고 표현해야 할지 잘 모르겠습니다. 예약어, 키워드 등으로 볼 수 있을 텐데 여기서는 키워드라고 통칭하도록 합니다. 이번 글에서는 테라폼에서 통용
jybaek.tistory.com
How to Deploy an Amazon Linux EC2 Instance in AWS using Terraform
In this story, we will learn how to deploy an Amazon Linux EC2 Instance (VM) in AWS using Terraform.
gmusumeci.medium.com
https://www.middlewareinventory.com/blog/terraform-aws-example-ec2/
Terraform AWS Example - Create EC2 instance with Terraform | DevOps Junction
Terraform AWS Example. Create EC2 instance with Terraform. Terraform AWS example on how to create AWS resources with Terraform. Create a Security Group using Terraform. Infrastructure as Code Example. Terraform aws Configuration file example and terraform
www.middlewareinventory.com