{"id":1072,"date":"2023-05-15T21:33:30","date_gmt":"2023-05-15T12:33:30","guid":{"rendered":"https:\/\/www.gyuroot.com\/wordpress\/?p=1072"},"modified":"2023-07-04T22:10:46","modified_gmt":"2023-07-04T13:10:46","slug":"sprint-terraform-x-aws","status":"publish","type":"post","link":"https:\/\/www.gyuroot.com\/wordpress\/?p=1072","title":{"rendered":"[Sprint] Terraform x AWS"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_63 counter-hierarchy ez-toc-counter ez-toc-white ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >\ubaa9\ucc28<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#_%ED%95%99%EC%8A%B5_%EB%AA%A9%ED%91%9C\" title=\"# \ud559\uc2b5 \ubaa9\ud45c\"># \ud559\uc2b5 \ubaa9\ud45c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#_%ED%95%B4%EA%B2%B0_%EA%B3%BC%EC%A0%9C\" title=\"# \ud574\uacb0 \uacfc\uc81c\"># \ud574\uacb0 \uacfc\uc81c<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#STEP_1_%EC%9E%90%EC%8A%B5%EC%84%9C_DB_%EC%9D%B8%EC%8A%A4%ED%84%B4%EC%8A%A4%EC%97%90_%EC%82%AC%EC%9A%A9%ED%95%A0_Amazon_VPC_%EC%83%9D%EC%84%B1\" title=\"STEP 1: \uc790\uc2b5\uc11c: DB \uc778\uc2a4\ud134\uc2a4\uc5d0 \uc0ac\uc6a9\ud560 Amazon VPC \uc0dd\uc131\">STEP 1: \uc790\uc2b5\uc11c: DB \uc778\uc2a4\ud134\uc2a4\uc5d0 \uc0ac\uc6a9\ud560 Amazon VPC \uc0dd\uc131<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#STEP_2_EC2_%EC%9D%B8%EC%8A%A4%ED%84%B4%EC%8A%A4_%EC%83%9D%EC%84%B1\" title=\"STEP 2: EC2 \uc778\uc2a4\ud134\uc2a4 \uc0dd\uc131\">STEP 2: EC2 \uc778\uc2a4\ud134\uc2a4 \uc0dd\uc131<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#Advanced_Challenges\" title=\"Advanced Challenges\">Advanced Challenges<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#STEP_3_%EC%9E%90%EC%8A%B5%EC%84%9C_DB_%EC%9D%B8%EC%8A%A4%ED%84%B4%EC%8A%A4_%EC%83%9D%EC%84%B1\" title=\"STEP 3: \uc790\uc2b5\uc11c: DB \uc778\uc2a4\ud134\uc2a4 \uc0dd\uc131\">STEP 3: \uc790\uc2b5\uc11c: DB \uc778\uc2a4\ud134\uc2a4 \uc0dd\uc131<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#STEP_4_%EC%95%A0%ED%94%8C%EB%A6%AC%EC%BC%80%EC%9D%B4%EC%85%98_%EB%A1%9C%EB%93%9C_%EB%B0%B8%EB%9F%B0%EC%84%9C_%EB%B0%8F_Auto_Scaling_Group_%EC%A0%81%EC%9A%A9\" title=\"STEP 4: \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \ub85c\ub4dc \ubc38\ub7f0\uc11c \ubc0f Auto Scaling Group \uc801\uc6a9\">STEP 4: \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \ub85c\ub4dc \ubc38\ub7f0\uc11c \ubc0f Auto Scaling Group \uc801\uc6a9<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#_%EC%8B%A4%EC%8A%B5_%EC%9E%90%EB%A3%8C\" title=\"# \uc2e4\uc2b5 \uc790\ub8cc\"># \uc2e4\uc2b5 \uc790\ub8cc<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#_%EA%B3%BC%EC%A0%9C_%ED%95%AD%EB%AA%A9%EB%B3%84_%EC%A7%84%ED%96%89_%EC%83%81%ED%99%A9\" title=\"# \uacfc\uc81c \ud56d\ubaa9\ubcc4 \uc9c4\ud589 \uc0c1\ud669\"># \uacfc\uc81c \ud56d\ubaa9\ubcc4 \uc9c4\ud589 \uc0c1\ud669<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#%EB%8B%A8%EC%9D%BC_%ED%8C%8C%EC%9D%BC%EB%A1%9C_%EA%B5%AC%EC%84%B1%ED%95%9C_%EC%98%88\" title=\"\ub2e8\uc77c \ud30c\uc77c\ub85c \uad6c\uc131\ud55c \uc608\">\ub2e8\uc77c \ud30c\uc77c\ub85c \uad6c\uc131\ud55c \uc608<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#%EB%AA%A8%EB%93%88_%EB%8B%A8%EC%9C%84%EB%A1%9C_%EA%B5%AC%EC%84%B1%ED%95%9C_%EC%98%88\" title=\"\ubaa8\ub4c8 \ub2e8\uc704\ub85c \uad6c\uc131\ud55c \uc608\">\ubaa8\ub4c8 \ub2e8\uc704\ub85c \uad6c\uc131\ud55c \uc608<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#1_vpc\" title=\"1. vpc\">1. vpc<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#2_ec2\" title=\"2. ec2\">2. ec2<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#3_rds\" title=\"3. rds\">3. rds<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#_TROUBLE_SHOOTING_LOG\" title=\"# TROUBLE SHOOTING LOG\"># TROUBLE SHOOTING LOG<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#%EC%9B%90%EC%9D%B8\" title=\"\uc6d0\uc778\">\uc6d0\uc778<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#%ED%95%B4%EA%B2%B0_%EB%B0%A9%EC%95%88\" title=\"\ud574\uacb0 \ubc29\uc548\">\ud574\uacb0 \ubc29\uc548<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#%EC%9B%90%EC%9D%B8-2\" title=\"\uc6d0\uc778\">\uc6d0\uc778<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#%ED%95%B4%EA%B2%B0_%EB%B0%A9%EC%95%88-2\" title=\"\ud574\uacb0 \ubc29\uc548\">\ud574\uacb0 \ubc29\uc548<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#_%ED%94%BC%EB%93%9C%EB%B0%B1\" title=\"# \ud53c\ub4dc\ubc31\"># \ud53c\ub4dc\ubc31<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\/#References\" title=\"#References\">#References<\/a><\/li><\/ul><\/nav><\/div>\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"_%ED%95%99%EC%8A%B5_%EB%AA%A9%ED%91%9C\"><\/span># \ud559\uc2b5 \ubaa9\ud45c<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n<p class=\"has-text-color\" style=\"color: rgb(0, 0, 0)\">Terraform\uc744 \uc774\uc6a9\ud55c AWS \uc544\ud0a4\ud14d\ucc98 \uad6c\uc131<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"_%ED%95%B4%EA%B2%B0_%EA%B3%BC%EC%A0%9C\"><\/span># \ud574\uacb0 \uacfc\uc81c<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n<p class=\"has-text-color\" style=\"color: rgb(0, 0, 0)\">\ub2e4\uc74c\uc758 \uc544\ud0a4\ud14d\ucc98\ub97c terraform\uc744 \uc774\uc6a9\ud574 \uc791\uc131\ud569\ub2c8\ub2e4.<\/p>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.gyuroot.com\/wordpress\/wp-content\/uploads\/image-281.png?v=1688460203\" alt=\"\"\/><\/figure>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"STEP_1_%EC%9E%90%EC%8A%B5%EC%84%9C_DB_%EC%9D%B8%EC%8A%A4%ED%84%B4%EC%8A%A4%EC%97%90_%EC%82%AC%EC%9A%A9%ED%95%A0_Amazon_VPC_%EC%83%9D%EC%84%B1\"><\/span><strong>STEP 1: <\/strong><a href=\"https:\/\/docs.aws.amazon.com\/ko_kr\/AmazonRDS\/latest\/UserGuide\/CHAP_Tutorials.WebServerDB.CreateVPC.html\"><strong>\uc790\uc2b5\uc11c: DB \uc778\uc2a4\ud134\uc2a4\uc5d0 \uc0ac\uc6a9\ud560 Amazon VPC \uc0dd\uc131<\/strong><\/a><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<ol>\n<li>VPC \ubc0f \uc11c\ube0c\ub137 \uc0dd\uc131<\/li>\n\n\n<li>VPC \ubcf4\uc548 \uadf8\ub8f9 \uc0dd\uc131<\/li>\n\n\n<li>DB \uc11c\ube0c\ub137 \uadf8\ub8f9 \uc0dd\uc131<\/li>\n\n<\/ol>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"STEP_2_EC2_%EC%9D%B8%EC%8A%A4%ED%84%B4%EC%8A%A4_%EC%83%9D%EC%84%B1\"><\/span><strong>STEP 2: EC2 \uc778\uc2a4\ud134\uc2a4 \uc0dd\uc131<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<p class=\"has-text-color\" style=\"color: rgb(0, 0, 0)\">\ub9cc\ub4e4\uc5b4\uc57c \ud558\ub294 \uc0ac\uc591\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n<ul>\n<li>AMI: Ubuntu Server 18<\/li>\n\n\n<li>\uc778\uc2a4\ud134\uc2a4 \ud0c0\uc785: t2.micro<\/li>\n\n\n<li>\uc0ac\uc6a9\uc790 \ub370\uc774\ud130<\/li>\n\n\n<li>\ud0a4 \ud398\uc5b4: \uc218\ub3d9\uc73c\ub85c \ub9cc\ub4e4\uace0 EC2\uc5d0 \ud560\ub2f9\ud569\ub2c8\ub2e4.<\/li>\n\n<\/ul>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Advanced_Challenges\"><\/span><strong>Advanced Challenges<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"STEP_3_%EC%9E%90%EC%8A%B5%EC%84%9C_DB_%EC%9D%B8%EC%8A%A4%ED%84%B4%EC%8A%A4_%EC%83%9D%EC%84%B1\"><\/span><strong>STEP 3: <\/strong><a href=\"https:\/\/docs.aws.amazon.com\/ko_kr\/AmazonRDS\/latest\/UserGuide\/CHAP_Tutorials.WebServerDB.CreateDBInstance.html\"><strong>\uc790\uc2b5\uc11c: DB \uc778\uc2a4\ud134\uc2a4 \uc0dd\uc131<\/strong><\/a><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<ul>\n<li>\uc790\uc2b5\uc11c\uc5d0 \ud45c\uc2dc\ub41c \uc0ac\uc591\ub300\ub85c RDS \uc778\uc2a4\ud134\uc2a4\ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4.<\/li>\n\n<\/ul>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"STEP_4_%EC%95%A0%ED%94%8C%EB%A6%AC%EC%BC%80%EC%9D%B4%EC%85%98_%EB%A1%9C%EB%93%9C_%EB%B0%B8%EB%9F%B0%EC%84%9C_%EB%B0%8F_Auto_Scaling_Group_%EC%A0%81%EC%9A%A9\"><\/span><strong>STEP 4: \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \ub85c\ub4dc \ubc38\ub7f0\uc11c \ubc0f Auto Scaling Group \uc801\uc6a9<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<ul>\n<li>Auto Scaling Group\uc740 \ucd5c\uc18c 2\uac1c, \ucd5c\ub300 10\uac1c\ub85c \uc124\uc815\ud574 \ub193\uc2b5\ub2c8\ub2e4.<\/li>\n\n<\/ul>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"_%EC%8B%A4%EC%8A%B5_%EC%9E%90%EB%A3%8C\"><\/span># \uc2e4\uc2b5 \uc790\ub8cc<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n<p class=\"has-text-color\" style=\"color: rgb(0, 0, 0)\"><a href=\"https:\/\/github.com\/cs-devops-bootcamp\/sprint-iac-terraform\">sprint-iac-terraform<\/a><\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"_%EA%B3%BC%EC%A0%9C_%ED%95%AD%EB%AA%A9%EB%B3%84_%EC%A7%84%ED%96%89_%EC%83%81%ED%99%A9\"><\/span># \uacfc\uc81c \ud56d\ubaa9\ubcc4 \uc9c4\ud589 \uc0c1\ud669<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%EB%8B%A8%EC%9D%BC_%ED%8C%8C%EC%9D%BC%EB%A1%9C_%EA%B5%AC%EC%84%B1%ED%95%9C_%EC%98%88\"><\/span>\ub2e8\uc77c \ud30c\uc77c\ub85c \uad6c\uc131\ud55c \uc608<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<pre class=\"wp-block-code\"><code>### terraform block ###\nterraform {\n  required_version = &quot;&gt;= 1.0&quot;\n\n  required_providers {\n    aws = {\n      source  = &quot;hashicorp\/aws&quot;\n      version = &quot;&gt;= 4.35&quot;\n    }\n  }\n}\n### provider block ###\nprovider &quot;aws&quot; {\n  region = &quot;ap-northeast-2&quot;\n\n  default_tags {\n    tags = {\n      name = &quot;tf-sprint&quot;\n    }\n  }\n}\n## aws_availability_zones \uc9c0\uc815\n## ap-northeast-2b,d \uc81c\uc678 t2.micro intancetype\uc744 \uc0ac\uc6a9\ud558\uae30 \uc704\ud568\ndata &quot;aws_availability_zones&quot; &quot;available&quot; {\n  state = &quot;available&quot;\n  exclude_names = [&quot;ap-northeast-2b&quot;, &quot;ap-northeast-2d&quot;]\n}\n## VPC \uad6c\uc131\uc744 module\ub85c \uc815\uc758\n## module \uc744 \uad6c\ubb38\uc5d0 \uc0bd\uc785 \ud6c4 terraform init \uc744 \ud558\uac8c \ub418\uba74\n## \uc790\ub3d9\uc73c\ub85c module\uc774 .terraform \ud3f4\ub354\ub85c pull\uc774 \ub41c\ub2e4.\nmodule &quot;vpc&quot; {\n  source  = &quot;terraform-aws-modules\/vpc\/aws&quot;\n  version = &quot;4.0.1&quot;\n\n  name = &quot;tf-vpc&quot;\n  cidr = &quot;10.0.0.0\/16&quot;\n\n  azs                  = data.aws_availability_zones.available.names\n  public_subnets       = [&quot;10.0.1.0\/24&quot;, &quot;10.0.2.0\/24&quot;]\n  private_subnets      = [&quot;10.0.3.0\/24&quot;, &quot;10.0.4.0\/24&quot;]\n  enable_dns_hostnames = true\n  enable_dns_support   = true\n  enable_nat_gateway = true\n}\n## EC2 AMI \uc815\uc758 ubuntu\ub85c \uc124\uc815\ndata &quot;aws_ami&quot; &quot;ubuntu&quot; {\n  most_recent = true\n  owners      = [&quot;amazon&quot;]\n\n  filter {\n    name   = &quot;name&quot;\n    values = [&quot;ubuntu\/images\/hvm-ssd\/ubuntu-bionic-18.04-amd64-server-20230424&quot;]\n  }\n}\n## EC2 Instance \ud15c\ud50c\ub9bf \uc815\uc758\nresource &quot;aws_launch_template&quot; &quot;tf-ec2&quot; {\n  \n  name_prefix     = &quot;tf-sprint-ec2-&quot;\n  image_id        = data.aws_ami.ubuntu.id\n  instance_type   = &quot;t2.micro&quot;\n  user_data       = &quot;${base64encode(&lt;&lt;-EOF\n    #!\/bin\/bash    \n    sudo apt update -y;sudo apt install -y mysql-client-core-5.7\n    echo &#039;&lt;h1&gt;Terraform Apply Complete&lt;\/h1&gt;&#039; &gt; index.html\n    echo &#039;&lt;b&gt;SHOW DATABASES&lt;\/b&gt;&lt;p style=&quot;color:red; white-space:pre;&quot;&gt;&#039; &gt;&gt; index.html\n    MYSQL_PWD=&quot;${aws_db_instance.tfRDS.password}&quot; mysql -h &#039;${aws_db_instance.tfRDS.address}&#039; -u &#039;${aws_db_instance.tfRDS.username}&#039; -e &#039;show databases&#039; &gt;&gt; index.html\n    echo &#039;&lt;\/p&gt;&lt;h1&gt;DB Access Complete&lt;\/h1&gt;&#039; &gt;&gt; index.html\n    sudo nohup busybox httpd -f -p 80 &amp;\n  EOF\n  )}&quot;\n  key_name = &quot;PCKEC2&quot;\n  network_interfaces {\n  associate_public_ip_address = true\n  security_groups = [aws_security_group.tfEC2sg.id]\n  }\n}\n## Autoscaling Group \uc815\uc758\nresource &quot;aws_autoscaling_group&quot; &quot;tfASG&quot; {\n  name                 = &quot;tfASG&quot;\n  min_size             = 2\n  max_size             = 10\n  desired_capacity     = 2\n  launch_template {\n    id      = aws_launch_template.tf-ec2.id\n  }\n  vpc_zone_identifier  = module.vpc.public_subnets\n\n  tag {\n    key                 = &quot;Name&quot;\n    value               = &quot;Terraform X AWS - ASG&quot;\n    propagate_at_launch = true\n    #(\ud544\uc218)\uc774 ASG\ub97c \ud1b5\ud574 \uc2dc\uc791\ub41c Amazon EC2 \uc778\uc2a4\ud134\uc2a4\uc5d0 \ud0dc\uadf8\ub97c \uc804\ud30c\n    #EC2 Deploy \ud560\ub54c\ub9c8\ub2e4 \ud574\ub2f9 \ud0dc\uadf8\uac00 \uc124\uc815\ub428\n  }\n}\n## Application Load Balancer\nresource &quot;aws_lb&quot; &quot;tfALB&quot; {\n  name               = &quot;tfALB&quot;\n  internal           = false\n  load_balancer_type = &quot;application&quot;\n  security_groups    = [aws_security_group.tfALBsg.id,]\n  subnets            = module.vpc.public_subnets\n}\n## ALB Listener\nresource &quot;aws_lb_listener&quot; &quot;tfALBListener&quot; {\n  load_balancer_arn = aws_lb.tfALB.arn\n  port              = &quot;80&quot;\n  protocol          = &quot;HTTP&quot;\n\n  default_action {\n    type             = &quot;forward&quot;\n    target_group_arn = aws_lb_target_group.tfALBtg.arn\n  }\n}\n## ALB target group\nresource &quot;aws_lb_target_group&quot; &quot;tfALBtg&quot; {\n  name     = &quot;Terraform-ALB-TargetGroup&quot;\n  port     = 80\n  protocol = &quot;HTTP&quot;\n  vpc_id   = module.vpc.vpc_id\n}\n\n## Register targetgroup and Include as pending below\nresource &quot;aws_autoscaling_attachment&quot; &quot;tfASGattach&quot; {\n  autoscaling_group_name = aws_autoscaling_group.tfASG.id\n  alb_target_group_arn   = aws_lb_target_group.tfALBtg.arn\n}\n\n### Security Group Create ###\nresource &quot;aws_security_group&quot; &quot;tfEC2sg&quot; {\n  name = &quot;Terraform-EC2-HTTP,SSH-Access&quot;\n  ingress {\n    from_port       = 80\n    to_port         = 80\n    protocol        = &quot;tcp&quot;\n    security_groups = [aws_security_group.tfALBsg.id]\n    #ALB \ubcf4\uc548\uadf8\ub8f9(tfALBsg)\uc73c\ub85c \ub4e4\uc5b4\uc628 \ud2b8\ub798\ud53d\ub9cc \ud5c8\uc6a9\n  }\n\n  ingress {\n    from_port       = 22\n    to_port         = 22\n    protocol        = &quot;tcp&quot;\n    cidr_blocks = [&quot;0.0.0.0\/0&quot;]\n  }\n  egress {\n    from_port   = 0\n    to_port     = 0\n    protocol    = &quot;-1&quot;\n    cidr_blocks = [&quot;0.0.0.0\/0&quot;]\n  }\n  vpc_id = module.vpc.vpc_id\n}\n# IP \ud504\ub85c\ud1a0\ucf5c \ubc88\ud638 &quot;-1&quot;\uc740 \uc77c\ubc18\uc801\uc73c\ub85c &quot;\ubaa8\ub4e0 \ud504\ub85c\ud1a0\ucf5c&quot; \ub610\ub294 &quot;\uc804\uccb4&quot;\ub97c \uc758\ubbf8\n# &quot;-1&quot;\ub85c \uc124\uc815\ub41c \uacbd\uc6b0, IP \ud328\ud0b7\uc740 \ubaa8\ub4e0 \ud504\ub85c\ud1a0\ucf5c\uc744 \uc9c0\uc6d0\ud558\ub294 \uac83\uc744 \uc758\ubbf8\nresource &quot;aws_security_group&quot; &quot;tfALBsg&quot; {\n  name = &quot;Terraform-ALB-HTTP-Access&quot;\n  ingress {\n    from_port   = 80\n    to_port     = 80\n    protocol    = &quot;tcp&quot;\n    cidr_blocks = [&quot;0.0.0.0\/0&quot;]\n  }\n\n  egress {\n    from_port   = 0\n    to_port     = 0\n    protocol    = &quot;-1&quot;\n    cidr_blocks = [&quot;0.0.0.0\/0&quot;]\n  }\n\n  vpc_id = module.vpc.vpc_id\n}\n\nresource &quot;aws_security_group&quot; &quot;tfRDSsg&quot; {\n  name        = &quot;tf_RDS_sg&quot;\n  vpc_id      = module.vpc.vpc_id\n\n  ingress {\n    from_port   = 3306\n    to_port     = 3306\n    protocol    = &quot;TCP&quot;\n    cidr_blocks = [&quot;0.0.0.0\/0&quot;]\n  }\n\n  egress {\n    from_port   = 0\n    to_port     = 0\n    protocol    = &quot;-1&quot;\n    cidr_blocks = [&quot;0.0.0.0\/0&quot;]\n  }\n}\n\n##DataBase Instance \uc0dd\uc131 \uc815\uc758\nresource &quot;aws_db_instance&quot; &quot;tfRDS&quot; {\n  identifier             = &quot;mydb01&quot;\n  allocated_storage      = &quot;10&quot;\n  engine                 = &quot;mysql&quot;\n  engine_version         = &quot;8.0.32&quot;\n  instance_class         = &quot;db.t2.micro&quot;\n  db_name                = &quot;terraformRDS&quot;\n  username               = &quot;root&quot;\n  password               = &quot;toor0515&quot;\n  vpc_security_group_ids = [aws_security_group.tfRDSsg.id]\n  db_subnet_group_name   = aws_db_subnet_group.tfRDSsubnets.id\n  skip_final_snapshot  = true\n}\n\nresource &quot;aws_db_subnet_group&quot; &quot;tfRDSsubnets&quot; {\n  name        = &quot;terraform-rds-subnet-group&quot;\n  subnet_ids  = module.vpc.private_subnets\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>\ub85c\ub4dc \ubc38\ub7f0\uc2a4 DNS \ub85c \uc811\uc18d \uacb0\uacfc\n\uba54\uc778<\/strong> \ud30c\uc77c \uc548\uc5d0 \uc258 \uc2a4\ud06c\ub9bd\ud2b8\ub97c \uc0bd\uc785\ud558\uc5ec EC2\uc5d0\uc11c RDS\ub85c \uc811\uc18d\uc774 \uac00\ub2a5\ud55c\uc9c0 \uc790\ub3d9\uc73c\ub85c \ud655\uc778<\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># \uc704\uc758 main.tf \ucf54\ub4dc \ucc38\uace0 \uc544\ub798\ub294 \uc815\ud655\ud55c \ubcc0\uc218\uba85\uc744 \uc0dd\ub7b5\ud558\uc600\uc73c\uba70\n# \uc2a4\ud06c\ub9bd\ud2b8 \uc2e4\ud589\uc744 \ud558\uba74\uc11c index.html \ud30c\uc77c\ub85c \uac12\uc774 \uc5b4\ub5bb\uac8c \ub4e4\uc5b4\uac00\ub294\uc9c0 \ubcf4\uc5ec\uc90c\n#!\/bin\/bash    \nsudo apt update -y\nsudo apt install -y mysql-client-core-5.7\necho &#039;&lt;h1&gt;Terraform Apply Complete&lt;\/h1&gt;&#039; &gt; index.html\necho &#039;&lt;b&gt;SHOW DATABASES&lt;\/b&gt;&lt;p style=&quot;color:red; white-space:pre;&quot;&gt;&#039; &gt;&gt; index.html\nMYSQL_PWD=&quot;${[<span style=\"color: rgba(212, 76, 71, 1)\"><strong>DB_password<\/strong><\/span>]}&quot; mysql -h [<span style=\"color: rgba(212, 76, 71, 1)\"><strong>RDS_Endpoint<\/strong><\/span>] -u &#039;[<span style=\"color: rgba(212, 76, 71, 1)\"><strong>username<\/strong><\/span>]&#039; -e &#039;show databases&#039; &gt;&gt; index.html\necho &#039;&lt;\/p&gt;&lt;h1&gt;DB Access Complete&lt;\/h1&gt;&#039; &gt;&gt; index.html\nsudo nohup busybox httpd -f -p 80 &amp;\n\nuser_data       = &quot;${base64encode(&lt;&lt;-EOF\n    #!\/bin\/bash    \n    sudo apt update -y;sudo apt install -y mysql-client-core-5.7\n    echo &#039;&lt;h1&gt;Terraform Apply Complete&lt;\/h1&gt;&#039; &gt; index.html\n    echo &#039;&lt;b&gt;SHOW DATABASES&lt;\/b&gt;&lt;p style=&quot;color:red; white-space:pre;&quot;&gt;&#039; &gt;&gt; index.html\n    MYSQL_PWD=&quot;${aws_db_instance.tfRDS.password}&quot; mysql -h &#039;${aws_db_instance.tfRDS.address}&#039; -u &#039;${aws_db_instance.tfRDS.username}&#039; -e &#039;show databases&#039; &gt;&gt; index.html\n    echo &#039;&lt;\/p&gt;&lt;h1&gt;DB Access Complete&lt;\/h1&gt;&#039; &gt;&gt; index.html\n    sudo nohup busybox httpd -f -p 80 &amp;\n  EOF\n  )}&quot;<\/code><\/pre>\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-3\">\n<div class=\"wp-block-column is-layout-flow\">\n<pre class=\"wp-block-code\"><code>&lt;--! index.html --&gt;\n&lt;h1&gt;Terraform Apply Complete&lt;\/h1&gt;\n&lt;b&gt;SHOW DATABASES&lt;\/b&gt;&lt;p style=&quot;color:red; white-space:pre;&quot;&gt;\n&lt;--! \ucffc\ub9ac \uacb0\uacfc  --&gt;\nDatabase\ninformation_schema\nmysql\nperformance_schema\nsys\nterraformRDS\n&lt;\/p&gt;&lt;h1&gt;DB Access Complete&lt;\/h1&gt;<\/code><\/pre>\n\n<\/div>\n\n\n<div class=\"wp-block-column is-layout-flow\">\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.gyuroot.com\/wordpress\/wp-content\/uploads\/image-282.png?v=1688460205\" alt=\"\"\/><\/figure>\n\n<\/div>\n\n<\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%EB%AA%A8%EB%93%88_%EB%8B%A8%EC%9C%84%EB%A1%9C_%EA%B5%AC%EC%84%B1%ED%95%9C_%EC%98%88\"><\/span>\ubaa8\ub4c8 \ub2e8\uc704\ub85c \uad6c\uc131\ud55c \uc608<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>\ubaa8\ub4c8 \uad6c\uc870<\/strong><\/p>\n\n<\/blockquote>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.gyuroot.com\/wordpress\/wp-content\/uploads\/image-283.png?v=1688460208\" alt=\"\"\/><\/figure>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_vpc\"><\/span>1. vpc<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>main.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code>terraform {\n  # Location of vpc state file\n  backend &quot;s3&quot; {\n    bucket  = &quot;bighead-tfstate&quot;\n    key     = &quot;VPC\/terraform.tfstate&quot;\n    region  = &quot;ap-northeast-2&quot;\n    encrypt = true\n  }\n\n  required_providers {\n    aws = {\n      source  = &quot;hashicorp\/aws&quot;\n      version = &quot;~&gt; 4.16&quot;\n    }\n  }\n\n  required_version = &quot;&gt;= 1.2.0&quot;\n}\n\nprovider &quot;aws&quot; {\n  region = &quot;ap-northeast-2&quot;\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>vpc.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># Main VPC\nresource &quot;aws_vpc&quot; &quot;main_vpc&quot; {\n  cidr_block = &quot;10.0.0.0\/16&quot;\n\n  tags = {\n    Name = &quot;main_vpc&quot;\n  }\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>subnet.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># Public Subnet - AZ(a)\nresource &quot;aws_subnet&quot; &quot;web_pub_subnet_a&quot; {\n  vpc_id            = aws_vpc.main_vpc.id\n  cidr_block        = &quot;10.0.1.0\/24&quot;\n  availability_zone = &quot;ap-northeast-2a&quot;\n\n  tags = {\n    Name = &quot;WEB-Pub-subnet-a&quot;\n  }\n}\n\n# Private Subnet - AZ(a)\nresource &quot;aws_subnet&quot; &quot;rds_pvt_subnet_a&quot; {\n  vpc_id            = aws_vpc.main_vpc.id\n  cidr_block        = &quot;10.0.2.0\/24&quot;\n  availability_zone = &quot;ap-northeast-2a&quot;\n\n  tags = {\n    Name = &quot;RDS-Pvt-subnet-a&quot;\n  }\n}\n\n# Public Subnet - AZ(c)\nresource &quot;aws_subnet&quot; &quot;web_pub_subnet_c&quot; {\n  vpc_id            = aws_vpc.main_vpc.id\n  cidr_block        = &quot;10.0.3.0\/24&quot;\n  availability_zone = &quot;ap-northeast-2c&quot;\n\n  tags = {\n    Name = &quot;WEB-Pub-subnet-c&quot;\n  }\n}\n\n# Private Subnet - AZ(c)\nresource &quot;aws_subnet&quot; &quot;rds_pvt_subnet_c&quot; {\n  vpc_id            = aws_vpc.main_vpc.id\n  cidr_block        = &quot;10.0.4.0\/24&quot;\n  availability_zone = &quot;ap-northeast-2c&quot;\n\n  tags = {\n    Name = &quot;RDS-Pvt-subnet-c&quot;\n  }\n}\n\n# RDS Subnet Group\n# Private Subnet - AZ(a,c)\nresource &quot;aws_db_subnet_group&quot; &quot;rds_subnet_group&quot; {\n  name       = &quot;rds_subnet_group&quot;\n  subnet_ids = [aws_subnet.rds_pvt_subnet_a.id, aws_subnet.rds_pvt_subnet_c.id]\n\n  tags = {\n    Name = &quot;RDS-subnet-group&quot;\n  }\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>route-table.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># Public Route Table - Internet Gateway\nresource &quot;aws_route_table&quot; &quot;pub_route_table&quot; {\n  vpc_id = aws_vpc.main_vpc.id\n\n  route {\n    cidr_block = &quot;0.0.0.0\/0&quot;\n    gateway_id = aws_internet_gateway.main_igw.id\n  }\n\n  tags = {\n    Name = &quot;Pub-route-table&quot;\n  }\n}\n\n# Private Route Table - NAT Gateway\nresource &quot;aws_route_table&quot; &quot;pvt_route_table&quot; {\n  vpc_id = aws_vpc.main_vpc.id\n\n  route {\n    cidr_block = &quot;0.0.0.0\/0&quot;\n    gateway_id = aws_nat_gateway.main_ngw.id\n  }\n\n  tags = {\n    Name = &quot;Pvt-route-table&quot;\n  }\n}\n\n# Public Route Table Association - Public Subnet - AZ(a)\nresource &quot;aws_route_table_association&quot; &quot;pub_route_table_association_a&quot; {\n  subnet_id      = aws_subnet.web_pub_subnet_a.id\n  route_table_id = aws_route_table.pub_route_table.id\n}\n\n# Public Route Table Association - Public Subnet - AZ(c)\nresource &quot;aws_route_table_association&quot; &quot;pub_route_table_association_c&quot; {\n  subnet_id      = aws_subnet.web_pub_subnet_c.id\n  route_table_id = aws_route_table.pub_route_table.id\n}\n\n# Private Route Table Association - Private Subnet - AZ(a)\nresource &quot;aws_route_table_association&quot; &quot;pvt_route_table_association_a&quot; {\n  subnet_id      = aws_subnet.rds_pvt_subnet_a.id\n  route_table_id = aws_route_table.pvt_route_table.id\n}\n\n# Private Route Table Association - Private Subnet - AZ(c)\nresource &quot;aws_route_table_association&quot; &quot;pvt_route_table_association_c&quot; {\n  subnet_id      = aws_subnet.rds_pvt_subnet_c.id\n  route_table_id = aws_route_table.pvt_route_table.id\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>gateway.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># Internet Gateway\nresource &quot;aws_internet_gateway&quot; &quot;main_igw&quot; {\n  vpc_id = aws_vpc.main_vpc.id\n\n  tags = {\n    Name = &quot;main-igw&quot;\n  }\n}\n\n# NAT Gateway\nresource &quot;aws_nat_gateway&quot; &quot;main_ngw&quot; {\n  allocation_id = aws_eip.ngw_eip.id\n  subnet_id     = aws_subnet.web_pub_subnet_c.id\n\n  tags = {\n    Name = &quot;main-ngw&quot;\n  }\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>security-group.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># Web Server Security Group\nresource &quot;aws_security_group&quot; &quot;web_security_group&quot; {\n  name        = &quot;web-security-group&quot;\n  description = &quot;Web Server Security Group&quot;\n  vpc_id      = aws_vpc.main_vpc.id\n\n  tags = {\n    Name = &quot;web-security-group&quot;\n  }\n}\n\n# RDB Server Security Group\nresource &quot;aws_security_group&quot; &quot;rds_security_group&quot; {\n  name        = &quot;rds-security-group&quot;\n  description = &quot;RDB Server Security Group&quot;\n  vpc_id      = aws_vpc.main_vpc.id\n\n  tags = {\n    Name = &quot;rds-security-group&quot;\n  }\n}\n\n# ALB Security Group\nresource &quot;aws_security_group&quot; &quot;alb_security_group&quot; {\n  name        = &quot;alb-security-group&quot;\n  description = &quot;ALB Security Group&quot;\n  vpc_id      = aws_vpc.main_vpc.id\n\n  tags = {\n    Name = &quot;alb-security-group&quot;\n  }\n}\n\n# Web Server Security Group Ingress\n# 80 port\nresource &quot;aws_vpc_security_group_ingress_rule&quot; &quot;web_security_group_ingress_http&quot; {\n  security_group_id = aws_security_group.web_security_group.id\n\n  cidr_ipv4   = &quot;0.0.0.0\/0&quot;\n  from_port   = 80\n  to_port     = 80\n  ip_protocol = &quot;tcp&quot;\n}\n\n# Web Server Security Group Ingress\n# 22 port\nresource &quot;aws_vpc_security_group_ingress_rule&quot; &quot;web_security_group_ingress_ssh&quot; {\n  security_group_id = aws_security_group.web_security_group.id\n\n  cidr_ipv4   = &quot;0.0.0.0\/0&quot;\n  from_port   = 22\n  to_port     = 22\n  ip_protocol = &quot;tcp&quot;\n}\n\n# Web Server Security Group Egress\n# Any\nresource &quot;aws_vpc_security_group_egress_rule&quot; &quot;web_security_group_egress&quot; {\n  security_group_id = aws_security_group.web_security_group.id\n\n  cidr_ipv4   = &quot;0.0.0.0\/0&quot;\n  ip_protocol = -1\n}\n\n# RDB Server Security Group Ingress\n# 3306 port\nresource &quot;aws_vpc_security_group_ingress_rule&quot; &quot;rds_security_group_ingress&quot; {\n  security_group_id = aws_security_group.rds_security_group.id\n\n  referenced_security_group_id = aws_security_group.web_security_group.id\n  from_port                    = 3306\n  to_port                      = 3306\n  ip_protocol                  = &quot;tcp&quot;\n}\n\n# RDB Server Security Group Egress\n# Any\nresource &quot;aws_vpc_security_group_egress_rule&quot; &quot;rds_security_group_egress&quot; {\n  security_group_id = aws_security_group.rds_security_group.id\n\n  cidr_ipv4   = &quot;0.0.0.0\/0&quot;\n  ip_protocol = -1\n}\n\n# ALB Security Group Ingress\n# 80 port\nresource &quot;aws_vpc_security_group_ingress_rule&quot; &quot;alb_security_group_ingress_http&quot; {\n  security_group_id = aws_security_group.alb_security_group.id\n\n  cidr_ipv4   = &quot;0.0.0.0\/0&quot;\n  from_port   = 80\n  to_port     = 80\n  ip_protocol = &quot;tcp&quot;\n}\n\n# ALB Security Group Egress\n# Any\nresource &quot;aws_vpc_security_group_egress_rule&quot; &quot;alb_security_group_egress&quot; {\n  security_group_id = aws_security_group.alb_security_group.id\n\n  cidr_ipv4   = &quot;0.0.0.0\/0&quot;\n  ip_protocol = -1\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>eip.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># EIP of NAT Gateway\nresource &quot;aws_eip&quot; &quot;ngw_eip&quot; {\n  vpc = true\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>outputs.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># Main VPC ID\noutput &quot;vpc_id&quot; {\n  description = &quot;ID of the Main VPC&quot;\n  value       = aws_vpc.main_vpc.id\n}\n\n# Public Subnet ID - AZ(a)\noutput &quot;subnet_pub_a_id&quot; {\n  description = &quot;ID of the WEB-Pub-subnet-a&quot;\n  value       = aws_subnet.web_pub_subnet_a.id\n}\n\n# Private Subnet ID - AZ(a)\noutput &quot;subnet_pvt_a_id&quot; {\n  description = &quot;ID of the RDS-Pvt-subnet-a&quot;\n  value       = aws_subnet.rds_pvt_subnet_a.id\n}\n\n# Public Subnet ID - AZ(c)\noutput &quot;subnet_pub_c_id&quot; {\n  description = &quot;ID of the WEB-Pub-subnet-c&quot;\n  value       = aws_subnet.web_pub_subnet_c.id\n}\n\n# Private Subnet ID - AZ(c)\noutput &quot;subnet_pvt_c_id&quot; {\n  description = &quot;ID of the RDS-Pvt-subnet-c&quot;\n  value       = aws_subnet.rds_pvt_subnet_c.id\n}\n\n# RDS Subnet Group Name\noutput &quot;subnet_group_rds_name&quot; {\n  description = &quot;Name of the RDS-subnet-group&quot;\n  value       = aws_db_subnet_group.rds_subnet_group.name\n}\n\n# Web Server Security Group ID\noutput &quot;web_security_group_id&quot; {\n  description = &quot;ID of the Web Server Security Group&quot;\n  value       = aws_security_group.web_security_group.id\n}\n\n# RDB Server Security Group ID\noutput &quot;rds_security_group_id&quot; {\n  description = &quot;ID of the RDB Server Security Group&quot;\n  value       = aws_security_group.rds_security_group.id\n}\n\n# ALB Security Group ID\noutput &quot;alb_security_group_id&quot; {\n  description = &quot;ID of the Application Load Balancer Security Group&quot;\n  value       = aws_security_group.alb_security_group.id\n}<\/code><\/pre>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_ec2\"><\/span>2. ec2<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>main.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code>terraform {\n  # Location of ec2 state file\n  backend &quot;s3&quot; {\n    bucket  = &quot;bighead-tfstate&quot;\n    key     = &quot;EC2\/terraform.tfstate&quot;\n    region  = &quot;ap-northeast-2&quot;\n    encrypt = true\n  }\n\n  required_providers {\n    aws = {\n      source  = &quot;hashicorp\/aws&quot;\n      version = &quot;~&gt; 4.16&quot;\n    }\n  }\n\n  required_version = &quot;&gt;= 1.2.0&quot;\n}\n\nprovider &quot;aws&quot; {\n  region = &quot;ap-northeast-2&quot;\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>data.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># Remote State of VPC\ndata &quot;terraform_remote_state&quot; &quot;vpc&quot; {\n  backend = &quot;s3&quot;\n  config = {\n    bucket = &quot;bighead-tfstate&quot;\n    key    = &quot;VPC\/terraform.tfstate&quot;\n    region = &quot;ap-northeast-2&quot;\n  }\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>variables.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># Web Server Port\nvariable &quot;server_port&quot; {\n  description = &quot;Server Port of the Web Server&quot;\n  type        = number\n  default     = 80\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>ec2.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># EC2 Instance - Web Server\nresource &quot;aws_instance&quot; &quot;web_server&quot; {\n  ami                         = &quot;ami-017c15d9ff8294f00&quot;\n  instance_type               = &quot;t2.micro&quot;\n  subnet_id                   = data.terraform_remote_state.vpc.outputs.subnet_pub_c_id\n  availability_zone           = &quot;ap-northeast-2c&quot;\n  vpc_security_group_ids      = [data.terraform_remote_state.vpc.outputs.web_security_group_id]\n  associate_public_ip_address = true  # Associate a public IP address\n  key_name                    = &quot;my-instance-key-pair&quot;\n\n  # Start httpd Web Server\n  user_data                   = &lt;&lt;-EOF\n    #!\/bin\/bash    \n    echo &quot;Hello, World&quot; &gt; index.html\n    sudo nohup busybox httpd -f -p ${var.server_port} &amp;\n  EOF\n\n  tags = {\n    Name = &quot;bighead-webserver&quot;\n  }\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>alb.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># Application Load Balancer - Web Server\nresource &quot;aws_lb&quot; &quot;web_server_alb&quot; {\n  name               = &quot;bighead-webserver-alb&quot;\n  internal           = false\n  load_balancer_type = &quot;application&quot;\n  security_groups    = [data.terraform_remote_state.vpc.outputs.alb_security_group_id]\n  subnets            = [data.terraform_remote_state.vpc.outputs.subnet_pub_a_id, data.terraform_remote_state.vpc.outputs.subnet_pub_c_id]\n}\n\n# Target Group for Application Load Balancer\nresource &quot;aws_lb_target_group&quot; &quot;web_server_alb_target&quot; {\n  name     = &quot;webserver-alb-target&quot;\n  port     = 80\n  protocol = &quot;HTTP&quot;\n  vpc_id   = data.terraform_remote_state.vpc.outputs.vpc_id\n}\n\n# Listener for Application Load Balancer\nresource &quot;aws_lb_listener&quot; &quot;web_server_alb_listener&quot; {\n  load_balancer_arn = aws_lb.web_server_alb.arn\n  port              = &quot;80&quot;\n  protocol          = &quot;HTTP&quot;\n\n  default_action {\n    type             = &quot;forward&quot;\n    target_group_arn = aws_lb_target_group.web_server_alb_target.id\n  }\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>autoscaling.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># Launch Template - Web Server\nresource &quot;aws_launch_template&quot; &quot;web_server_template&quot; {\n  name          = &quot;webserver-template&quot;\n  image_id      = &quot;ami-017c15d9ff8294f00&quot;\n  instance_type = &quot;t2.micro&quot;\n  key_name      = &quot;my-instance-key-pair&quot;\n\n  network_interfaces {\n    associate_public_ip_address = true  # Associate a public IP address\n    security_groups             = [data.terraform_remote_state.vpc.outputs.web_security_group_id]\n  }\n\n  tag_specifications {\n    resource_type = &quot;instance&quot;\n\n    tags = {\n      Name = &quot;bighead-webserver&quot;\n    }\n  }\n  \n  # Start httpd Web Server\n  user_data = &quot;${base64encode(&lt;&lt;-EOF\n    #!\/bin\/bash    \n    echo &quot;Hello, World&quot; &gt; index.html\n    sudo nohup busybox httpd -f -p ${var.server_port} &amp;\n  EOF\n  )}&quot;\n}\n\n# Autoscaling Group - Web Server\nresource &quot;aws_autoscaling_group&quot; &quot;web_server_asg&quot; {\n  name                = &quot;webserver-autoscaling-group&quot;\n  vpc_zone_identifier = [data.terraform_remote_state.vpc.outputs.subnet_pub_a_id, data.terraform_remote_state.vpc.outputs.subnet_pub_c_id]\n  desired_capacity    = 2\n  max_size            = 10\n  min_size            = 2\n  target_group_arns   = [aws_lb_target_group.web_server_alb_target.id]\n\n  launch_template {\n    id      = aws_launch_template.web_server_template.id\n    version = &quot;$Latest&quot;\n  }\n}<\/code><\/pre>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_rds\"><\/span>3. rds<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>main.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code>terraform {\n  # Location of rds state file\n  backend &quot;s3&quot; {\n    bucket  = &quot;bighead-tfstate&quot;\n    key     = &quot;RDS\/terraform.tfstate&quot;\n    region  = &quot;ap-northeast-2&quot;\n    encrypt = true\n  }\n\n  required_providers {\n    aws = {\n      source  = &quot;hashicorp\/aws&quot;\n      version = &quot;~&gt; 4.16&quot;\n    }\n  }\n\n  required_version = &quot;&gt;= 1.2.0&quot;\n}\n\nprovider &quot;aws&quot; {\n  region = &quot;ap-northeast-2&quot;\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>data.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># Remote State of VPC\ndata &quot;terraform_remote_state&quot; &quot;vpc&quot; {\n  backend = &quot;s3&quot;\n  config = {\n    bucket = &quot;bighead-tfstate&quot;\n    key    = &quot;VPC\/terraform.tfstate&quot;\n    region = &quot;ap-northeast-2&quot;\n  }\n}<\/code><\/pre>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><strong>rds.tf<\/strong><\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code># RDS Instance - MySQL\nresource &quot;aws_db_instance&quot; &quot;mysql-db&quot; {\n  allocated_storage           = 10\n  identifier                  = &quot;mysql-bighead&quot;\n  db_name                     = &quot;bighead&quot;\n  engine                      = &quot;mysql&quot;\n  engine_version              = &quot;8.0.28&quot;\n  instance_class              = &quot;db.t3.micro&quot;\n  username                    = &quot;admin&quot;\n  manage_master_user_password = true  # Managing the master password with Secrets Manager\n  parameter_group_name        = &quot;default.mysql8.0&quot;\n  db_subnet_group_name        = data.terraform_remote_state.vpc.outputs.subnet_group_rds_name\n  vpc_security_group_ids      = [data.terraform_remote_state.vpc.outputs.rds_security_group_id]\n  skip_final_snapshot         = true\n  port                        = 3306\n}<\/code><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"_TROUBLE_SHOOTING_LOG\"><\/span># TROUBLE SHOOTING LOG<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n<p class=\"has-background\" style=\"background-color: rgb(251, 243, 219)\">&#x1f4a1; <strong>Autoscaling Group \uc0dd\uc131 \uc2dc \uc624\ub958 \ubc1c\uc0dd\n\nError: creating Auto Scaling Group (webserver-autoscaling-group): ValidationError: You must use a valid fully-formed launch template. Security group sg-063a69a18d2ceb979 and subnet subnet-0c524365a4ac5a7d9 belong to different networks.<\/strong><\/p>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%EC%9B%90%EC%9D%B8\"><\/span>\uc6d0\uc778<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p>Autoscaling Group \uc0dd\uc131 \uc2dc <code>availability_zones<\/code> \uc635\uc158\uc744 \uc9c0\uc815\ud558\uba74,\n\ud574\ub2f9 \uac00\uc6a9 \uc601\uc5ed\uc758 \uae30\ubcf8 \uc11c\ube0c\ub137\uc774 Autoscaling Group\uc758 \uc11c\ube0c\ub137\uc73c\ub85c \uc120\ud0dd\ub418\ub294\ub370,\n\ud574\ub2f9 \uc11c\ube0c\ub137\uc774 Launch Template\uc5d0 \uc9c0\uc815\ub418\uc5b4 \uc788\ub294 \ubcf4\uc548 \uadf8\ub8f9\uc758 \uc11c\ube0c\ub137\uacfc \ub2ec\ub77c \uc624\ub958\uac00 \ubc1c\uc0dd\ud568.<\/p>\n\n<\/blockquote>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%ED%95%B4%EA%B2%B0_%EB%B0%A9%EC%95%88\"><\/span>\ud574\uacb0 \ubc29\uc548<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p><code>availability_zones<\/code> \ub300\uc2e0 <code>vpc_zone_identifier<\/code> \uc635\uc158\uc744 \uc0ac\uc6a9\ud574, Autoscaling Group\uc5d0 \uc11c\ube0c\ub137\uc744 \uc9c1\uc811 \uc9c0\uc815\ud558\uc5ec \ud574\uacb0<\/p>\n\n<\/blockquote>\n\n\n<p class=\"has-background\" style=\"background-color: rgb(251, 243, 219)\">&#x1f4a1; <strong>EC2 Public DNS\ub85c SSH \uc811\uc18d \ubd88\uac00<\/strong><\/p>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%EC%9B%90%EC%9D%B8-2\"><\/span>\uc6d0\uc778<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<blockquote class=\"wp-block-quote has-text-color\" style=\"color: rgb(0, 0, 0)\">\n<p>\ubcf4\uc548\uadf8\ub8f9\uc5d0\uc11c \uc18c\uc2a4 \ub300\uc0c1\uc744 <code>ALB\uc6a9\uc73c\ub85c \uc0dd\uc131\ud55c \ubcf4\uc548\uadf8\ub8f9<\/code>\uc73c\ub85c \uc9c0\uc815\ud588\uae30 \ub54c\ubb38<\/p>\n\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\"><code>resource &quot;aws_security_group&quot; &quot;tfEC2sg&quot; {\n  name = &quot;Terraform-EC2-HTTP,SSH-Access&quot;\n  ingress {\n    from_port       = 80\n    to_port         = 80\n    protocol        = &quot;tcp&quot;\n    security_groups = [aws_security_group.tfALBsg.id]\n  }\n\n  ingress {\n    from_port       = 22\n    to_port         = 22\n    protocol        = &quot;tcp&quot;\n    security_groups = [aws_security_group.tfALBsg.id] # \ubb38\uc81c\uc758 \ucf54\ub4dc\n  }\n\n  egress {\n.\n.\n.<\/code><\/pre>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%ED%95%B4%EA%B2%B0_%EB%B0%A9%EC%95%88-2\"><\/span>\ud574\uacb0 \ubc29\uc548<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<pre class=\"wp-block-code\"><code>resource &quot;aws_security_group&quot; &quot;tfEC2sg&quot; {\n  name = &quot;Terraform-EC2-HTTP,SSH-Access&quot;\n  ingress {\n    from_port       = 80\n    to_port         = 80\n    protocol        = &quot;tcp&quot;\n    security_groups = [aws_security_group.tfALBsg.id]\n  }\n\n  ingress {\n    from_port       = 22\n    to_port         = 22\n    protocol        = &quot;tcp&quot;\n    cidr_blocks = [&quot;0.0.0.0\/0&quot;] # \ubaa8\ub4e0 \ub300\uc0c1\uc73c\ub85c \ucd94\uac00\n    <s>security_groups = [aws_security_group.tfALBsg.id]<\/s>\t\n  }\n\n  egress {\n.\n.\n.<\/code><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"_%ED%94%BC%EB%93%9C%EB%B0%B1\"><\/span># \ud53c\ub4dc\ubc31<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\uc624\ud0dc\uacbd<\/th><th>\ubc15\ucc2c\uaddc<\/th><\/tr><\/thead><tbody><tr><td>\uc9c1\uc811 \ucf54\ub4dc\ub85c \uc778\ud504\ub77c\ub97c \uad6c\uc131\ud574\ubcf4\ub2c8 AWS \ub9ac\uc18c\uc2a4\ubcc4 \uc635\uc158\uac12\ub4e4\uc744 \ub354 \uc790\uc138\ud788 \uc54c \uc218 \uc788\uc5c8\ub2e4.<\/td><td><\/td><\/tr>\n<\/tbody><\/table><\/figure>\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"References\"><\/span>#References<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n<ul>\n<li><a href=\"https:\/\/registry.terraform.io\/providers\/hashicorp\/aws\/latest\/docs\">https:\/\/registry.terraform.io\/providers\/hashicorp\/aws\/latest\/docs<\/a><\/li>\n\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p># \ud559\uc2b5 \ubaa9\ud45c Terraform\uc744 \uc774\uc6a9\ud55c AWS \uc544\ud0a4\ud14d\ucc98 \uad6c\uc131 # \ud574\uacb0 \uacfc\uc81c \ub2e4\uc74c\uc758 \uc544\ud0a4\ud14d\ucc98\ub97c terraform\uc744 \uc774\uc6a9\ud574 \uc791\uc131\ud569\ub2c8\ub2e4. STEP 1: \uc790\uc2b5\uc11c: DB \uc778\uc2a4\ud134\uc2a4\uc5d0 \uc0ac\uc6a9\ud560 Amazon VPC \uc0dd\uc131 STEP 2: EC2 \uc778\uc2a4\ud134\uc2a4 \uc0dd\uc131 \ub9cc\ub4e4\uc5b4\uc57c \ud558\ub294 \uc0ac\uc591\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4. Advanced Challenges STEP 3: \uc790\uc2b5\uc11c: DB \uc778\uc2a4\ud134\uc2a4 \uc0dd\uc131 STEP 4: \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \ub85c\ub4dc \ubc38\ub7f0\uc11c \ubc0f Auto Scaling Group \uc801\uc6a9 # \uc2e4\uc2b5 &#8230; <a title=\"[Sprint] Terraform x AWS\" class=\"read-more\" href=\"https:\/\/www.gyuroot.com\/wordpress\/?p=1072\" aria-label=\"More on [Sprint] Terraform x AWS\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":""},"categories":[45],"tags":[],"_links":{"self":[{"href":"https:\/\/www.gyuroot.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1072"}],"collection":[{"href":"https:\/\/www.gyuroot.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gyuroot.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gyuroot.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gyuroot.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1072"}],"version-history":[{"count":1,"href":"https:\/\/www.gyuroot.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1072\/revisions"}],"predecessor-version":[{"id":1126,"href":"https:\/\/www.gyuroot.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1072\/revisions\/1126"}],"wp:attachment":[{"href":"https:\/\/www.gyuroot.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gyuroot.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gyuroot.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}