brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Dec 08. 2022

19탄-27. 테라폼-AWS- 프로덕션 수준의 테라폼

다음은 주말 CloudNet 테라폼 스터디 내용 참고하여  정리한 부분입니다.

https://gasidaseo.notion.site/gasidaseo/CloudNet-Blog-c9dfa44a27ff431dafdd2edacc8a1863


<1> RDS 배포

<2> ASG 배포

<3> ALB 배포

<4> 삭제



<1> RDS 배포


1

# [터미널1] RDS 생성 모니터링

while true; do aws rds describe-db-instances --query "*[].[Endpoint.Address,Endpoint.Port,MasterUsername]" --output text  ; echo "------------------------------" ; sleep 1; done



2

터미널2


# RDS 배포

cd /root/terraform-up-and-running-code/code/terraform/08-production-grade-infrastructure/small-modules/modules/data-stores/mysql



# 환경변수에 지정

export TF_VAR_db_username='cloudneta'

export TF_VAR_db_password='cloudnetaQ!'


terraform init && terraform plan

terraform apply -auto-approve


var.db_name

  The name to use for the database

  Enter a value: masterseodb



terraform-up-and-running20xx21299400000001.c7aitcdywcyg.us-east-2.rds.amazonaws.com     3306    cloudneta

------------------------------

terraform-up-and-running20x400000001.c7aitcdywcyg.us-east-2.rds.amazonaws.com     3306    cloudneta

------------------------------

terraform-up-and-running20221x0000001.c7aitcdywcyg.us-east-2.rds.amazonaws.com     3306    cloudneta




<2> ASG 배포


1

# [터미널2]

while true; do aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicIPAdd:PublicIpAddress,InstanceName:Tags[?Key=='Name']|[0].Value,Status:State.Name}" --filters Name=instance-state-name,Values=running --output text ; echo "------------------------------" ; sleep 1; done



2

터미널 1


# ASG 배포


cd ~/terraform-up-and-running-code/code/terraform/08-production-grade-infrastructure/small-modules/examples/asg


terraform init

terraform plan

terraform apply -auto-approve



3

------------------------------

terraform-up-and-running        None    running

------------------------------

terraform-up-and-running        None    running

------------------------------

terraform-up-and-running        None    running

------------------------------

terraform-up-and-running        None    running

------------------------------

terraform-up-and-running        None    running




<3> ALB 배포



1

터미널1

# ALB 배포

cd ..

cd ~/terraform-up-and-running-code/code/terraform/08-production-grade-infrastructure/small-modules/examples/alb


terraform init && terraform plan

terraform apply -auto-approve


Outputs:

alb_dns_name = "terraform-up-and-running-58544743.us-east-2.elb.amazonaws.com"




2

터미널1

# ALB DNS주소로 curl 접속 확인 

ALB 생성후 


ALBDNS=$(terraform output -raw alb_dns_name)

while true; do curl --connect-timeout 1  http://$ALBDNS ; echo; echo "------------------------------"; date; sleep 1; done


curl -s http://$ALBDNS




<4> 삭제


cd ~/terraform-up-and-running-code/code/terraform/08-production-grade-infrastructure/small-modules/examples/alb

terraform destroy -auto-approve


cd ~/terraform-up-and-running-code/code/terraform/08-production-grade-infrastructure/small-modules/examples/asg

terraform destroy -auto-approve


cd ~/terraform-up-and-running-code/code/terraform/08-production-grade-infrastructure/small-modules/examples/mysql

terraform destroy -auto-approve





다음

https://brunch.co.kr/@topasvga/2855



https://brunch.co.kr/@topasvga/2421


감사합니다.

브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari