<1> 환경 확인 <2> rds 배포 <3> web server 배포 <4> 삭제 <1> 환경 확인 stage - service - webserver- main.tf stage - service - data-stores -mysql - main.tf global - s3 - main.tf # 환경변수에 지정 export TF_VAR_bucket_name=<각자 닉네임>-tfstate export TF_VAR_table_name=<각자 닉네임>-t101-locks export TF_VAR_bucket_name=masterseo-t101-tfstate export TF_VAR_table_name=masterseo-t101-locks # 환경변수 확인 export | grep TF_VAR_ # (옵션) 환경변수 지정 삭제 unset TF_VAR_bucket_name unset TF_VAR_table_name # s3 cd 03-terraform-state/file-layout-example/global/s3 cat main.tf variables.tf # 초기화 및 검증 : 환경변수 적용 확인 terraform init && terraform plan # 배포 terraform apply -auto-approve # 확인 aws s3 ls aws dynamodb list-tables --output text # 이동 cd ../.. <2> rds 배포 # [터미널1] RDS 생성 모니터링 while true; do aws rds describe-db-instances --query "*[].[Endpoint.Address,Endpoint.Port,MasterUsername]" --output text ; echo "------------------------------" ; sleep 1; done # [터미널2] cd stage/data-stores/mysql cat main.tf variables.tf # 환경변수에 지정 export TF_VAR_db_username='cloudneta' export TF_VAR_db_password='cloudnetaQ!' # 환경변수 확인 export | grep TF_VAR_ # main.tf 에 백엔드 부분 수정 vi main.tf backend "s3" { # This backend configuration is filled in automatically at test time by Terratest. If you wish to run this example # manually, uncomment and fill in the config below. bucket = "masterseo-t101-tfstate" key = "stage/data-stores/mysql/terraform.tfstate" region = "us-east-2" dynamodb_table = "masterseo-t101-locks" # encrypt = true } # 초기화 및 검증 : 환경변수 적용 확인 terraform init && terraform plan # 배포 : RDS는 생성 시 6분 정도 시간 소요 terraform apply -auto-approve terraform output aws s3 ls s3://$TF_VAR_bucket_name --recursive --human-readable --summarize # 이동 cd ../.. <3> web server 배포 # cd services/webserver-cluster cat main.tf variables.tf # 환경변수에 지정 export TF_VAR_db_remote_state_bucket=$TF_VAR_bucket_name # description = "The name of the S3 bucket used for the database's remote state storage" export TF_VAR_db_remote_state_key='stage/data-stores/mysql/terraform.tfstate' # description = "The name of the key in the S3 bucket used for the database's remote state storage" # 환경변수 확인 export | grep TF_VAR_ # 초기화 및 검증 : 환경변수 적용 확인 terraform init && terraform plan # 배포 terraform apply -auto-approve # ALB DNS주소로 curl 접속 확인 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> 삭제 # 각 폴더에서 리소스 삭제 stage/services/webserver-cluster$ terraform destroy -auto-approve stage/data-stores/mysql$ terraform destroy -auto-approve global/s3$ terraform destroy -auto-approve # 이동 cd ~/terraform-up-and-running-code/code/terraform