├── LICENSE ├── README.md └── copilot-course ├── 1-generate-terraform ├── README.md ├── main.tf ├── outputs.tf ├── provider.tf ├── terraform.tfvars └── variables.tf ├── 2-code-suggestions ├── README.md ├── main.tf ├── outputs.tf ├── provider.tf ├── terraform.tfvars └── variables.tf ├── 3-expanding-on-code-suggestions ├── README.md ├── main.tf ├── outputs.tf ├── provider.tf ├── terraform.tfvars └── variables.tf ├── 4-using-copilot-menu ├── README.md ├── main.tf ├── outputs.tf ├── provider.tf ├── terraform.tfvars └── variables.tf ├── 5-create-a-module ├── README.md ├── main.tf ├── modules │ └── vpc │ │ ├── main.tf │ │ ├── outputs.tf │ │ └── variables.tf ├── outputs.tf ├── provider.tf ├── terraform.tfvars └── variables.tf └── 6-intro-to-copilot-chat ├── README.md ├── main.tf ├── modules └── vpc │ ├── main.tf │ ├── outputs.tf │ └── variables.tf ├── outputs.tf ├── provider.tf ├── terraform.tfvars └── variables.tf /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Terraform & Online Courses Repository 2 | 3 | Welcome to the Terraform repository focused on my online training courses! This repository contains all the materials, scripts, and resources related to HashiCorp Terraform and the courses I offer to help you master Infrastructure as Code (IaC) using Terraform, GitHub Copilot, and other DevOps tools. 4 | 5 | ### Looking for more content? Check out my primary GitHub profile here ➡️ [btk.me/btk](btk.me/btk) -------------------------------------------------------------------------------- /copilot-course/1-generate-terraform/README.md: -------------------------------------------------------------------------------- 1 | # Writing your first Terraform configurations with Copilot! 2 | 3 | This repository contains the code for the "Writing your first Terraform configurations with Copilot!" lecture. 4 | 5 | **Note:** This is NOT intended to be perfect Terraform code. The results are focused on the outputs of using only GitHub Copilot auto-suggested code. -------------------------------------------------------------------------------- /copilot-course/1-generate-terraform/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | aws = { 4 | source = "hashicorp/aws" 5 | version = "5.64.0" 6 | } 7 | } 8 | } 9 | 10 | resource "aws_vpc" "prd-vpc" { 11 | cidr_block = "10.0.0.0/16" 12 | } 13 | 14 | resource "aws_subnet" "prd-pub-subnet-1" { 15 | vpc_id = aws_vpc.prd-vpc.id 16 | cidr_block = "10.0.0.0/24" 17 | availability_zone = "us-east-1a" 18 | 19 | tags = { 20 | Name = "prd-pub-subnet-1" 21 | } 22 | } 23 | 24 | resource "aws_subnet" "prd-pub-subnet-2" { 25 | vpc_id = aws_vpc.prd-vpc.id 26 | cidr_block = "10.0.1.0/24" 27 | availability_zone = "us-east-1b" 28 | 29 | tags = { 30 | Name = "prd-pub-subnet-2" 31 | } 32 | } 33 | 34 | resource "aws_subnet" "prd-pub-subnet-3" { 35 | vpc_id = aws_vpc.prd-vpc.id 36 | cidr_block = "10.0.2.0/24" 37 | availability_zone = "us-east-1c" 38 | 39 | tags = { 40 | Name = "prd-pub-subnet-3" 41 | } 42 | } 43 | 44 | resource "aws_subnet" "prd-pri-subnet-1" { 45 | vpc_id = aws_vpc.prd-vpc.id 46 | cidr_block = "10.0.10.0/24" 47 | availability_zone = "us-east-1a" 48 | 49 | tags = { 50 | Name = "prd-pri-subnet-1" 51 | } 52 | } 53 | 54 | resource "aws_subnet" "prd-pri-subnet-2" { 55 | vpc_id = aws_vpc.prd-vpc.id 56 | cidr_block = "10.0.11.0/24" 57 | availability_zone = "us-east-1b" 58 | 59 | tags = { 60 | Name = "prd-pri-subnet-2" 61 | } 62 | } 63 | 64 | resource "aws_subnet" "prd-pri-subnet-3" { 65 | vpc_id = aws_vpc.prd-vpc.id 66 | cidr_block = "10.0.12.0/24" 67 | availability_zone = "us-east-1c" 68 | 69 | tags = { 70 | Name = "prd-pri-subnet-3" 71 | } 72 | } 73 | 74 | resource "aws_internet_gateway" "prd-igw" { 75 | vpc_id = aws_vpc.prd-vpc.id 76 | 77 | tags = { 78 | Name = "prd-igw" 79 | } 80 | } 81 | 82 | resource "aws_route_table" "prd-pub-rt" { 83 | vpc_id = aws_vpc.prd-vpc.id 84 | 85 | route { 86 | cidr_block = "0.0.0.0/0" 87 | gateway_id = aws_internet_gateway.prd-igw.id 88 | } 89 | } 90 | 91 | resource "aws_route_table_association" "prd-pub-rt-assoc-1" { 92 | subnet_id = aws_subnet.prd-pub-subnet-1.id 93 | route_table_id = aws_route_table.prd-pub-rt.id 94 | } 95 | 96 | resource "aws_route_table_association" "prd-pub-rt-assoc-2" { 97 | subnet_id = aws_subnet.prd-pub-subnet-2.id 98 | route_table_id = aws_route_table.prd-pub-rt.id 99 | } 100 | 101 | resource "aws_route_table_association" "prd-pub-rt-assoc-3" { 102 | subnet_id = aws_subnet.prd-pub-subnet-3.id 103 | route_table_id = aws_route_table.prd-pub-rt.id 104 | } 105 | 106 | resource "aws_route_table" "prd-pri-rt" { 107 | vpc_id = aws_vpc.prd-vpc.id 108 | } 109 | 110 | resource "aws_route_table_association" "prd-pri-rt-assoc-1" { 111 | subnet_id = aws_subnet.prd-pri-subnet-1.id 112 | route_table_id = aws_route_table.prd-pri-rt.id 113 | } 114 | 115 | resource "aws_route_table_association" "prd-pri-rt-assoc-2" { 116 | subnet_id = aws_subnet.prd-pri-subnet-2.id 117 | route_table_id = aws_route_table.prd-pri-rt.id 118 | } 119 | 120 | resource "aws_route_table_association" "prd-pri-rt-assoc-3" { 121 | subnet_id = aws_subnet.prd-pri-subnet-3.id 122 | route_table_id = aws_route_table.prd-pri-rt.id 123 | } -------------------------------------------------------------------------------- /copilot-course/1-generate-terraform/outputs.tf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/1-generate-terraform/outputs.tf -------------------------------------------------------------------------------- /copilot-course/1-generate-terraform/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } 4 | 5 | -------------------------------------------------------------------------------- /copilot-course/1-generate-terraform/terraform.tfvars: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/1-generate-terraform/terraform.tfvars -------------------------------------------------------------------------------- /copilot-course/1-generate-terraform/variables.tf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/1-generate-terraform/variables.tf -------------------------------------------------------------------------------- /copilot-course/2-code-suggestions/README.md: -------------------------------------------------------------------------------- 1 | # Expanding on Code Suggestions 2 | 3 | This repository contains the code for the "Expanding on Code Suggestions" lecture. 4 | 5 | **Note:** This is NOT intended to be perfect Terraform code. The results are focused on the outputs of using GitHub Copilot suggested and alternative suggestions. -------------------------------------------------------------------------------- /copilot-course/2-code-suggestions/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | aws = { 4 | source = "hashicorp/aws" 5 | version = "5.64.0" 6 | } 7 | } 8 | } 9 | 10 | resource "aws_vpc" "prd-vpc" { 11 | cidr_block = "10.0.0.0/16" 12 | } 13 | ############################################################### 14 | # using comments to help invoke better suggestions from Copilot 15 | ############################################################### 16 | # creating a new vpc for development workloads 17 | resource "aws_vpc" "dev-vpc" { 18 | cidr_block = "10.10.0.0/16" 19 | } 20 | resource "aws_security_group" "dev-web-sg" { 21 | vpc_id = aws_vpc.dev-vpc.id 22 | 23 | ingress { 24 | description = "allow inbound traffic from the internet" 25 | from_port = 80 26 | to_port = 80 27 | protocol = "tcp" 28 | cidr_blocks = ["10.0.0.0/16"] 29 | } 30 | } 31 | 32 | # eks cluster for development web workloads 33 | resource "aws_eks_cluster" "dev-cluster" { 34 | name = "dev-cluster" 35 | role_arn = "arn:aws:iam::123456789012:role/eks-role" 36 | vpc_config { 37 | security_group_ids = [aws_security_group.dev-web-sg.id] 38 | subnet_ids = ["subnet-1234567890abcdef0", "subnet-1234567890abcdef1", "subnet-1234567890abcdef2"] 39 | } 40 | } 41 | 42 | # creating a new vpc for production workloads 43 | resource "aws_vpc" "prd-vpc" { 44 | cidr_block = " 45 | 46 | resource "aws_subnet" "prd-pub-subnet-1" { 47 | vpc_id = aws_vpc.prd-vpc.id 48 | cidr_block = "10.0.0.0/24" 49 | availability_zone = "us-east-1a" 50 | 51 | tags = { 52 | Name = "prd-pub-subnet-1" 53 | } 54 | } 55 | 56 | resource "aws_subnet" "prd-pub-subnet-2" { 57 | vpc_id = aws_vpc.prd-vpc.id 58 | cidr_block = "10.0.1.0/24" 59 | availability_zone = "us-east-1b" 60 | 61 | tags = { 62 | Name = "prd-pub-subnet-2" 63 | } 64 | } 65 | 66 | resource "aws_subnet" "prd-pub-subnet-3" { 67 | vpc_id = aws_vpc.prd-vpc.id 68 | cidr_block = "10.0.2.0/24" 69 | availability_zone = "us-east-1c" 70 | 71 | tags = { 72 | Name = "prd-pub-subnet-3" 73 | } 74 | } 75 | 76 | resource "aws_subnet" "prd-pri-subnet-1" { 77 | vpc_id = aws_vpc.prd-vpc.id 78 | cidr_block = "10.0.10.0/24" 79 | availability_zone = "us-east-1a" 80 | 81 | tags = { 82 | Name = "prd-pri-subnet-1" 83 | } 84 | } 85 | 86 | resource "aws_subnet" "prd-pri-subnet-2" { 87 | vpc_id = aws_vpc.prd-vpc.id 88 | cidr_block = "10.0.11.0/24" 89 | availability_zone = "us-east-1b" 90 | 91 | tags = { 92 | Name = "prd-pri-subnet-2" 93 | } 94 | } 95 | 96 | resource "aws_subnet" "prd-pri-subnet-3" { 97 | vpc_id = aws_vpc.prd-vpc.id 98 | cidr_block = "10.0.12.0/24" 99 | availability_zone = "us-east-1c" 100 | 101 | tags = { 102 | Name = "prd-pri-subnet-3" 103 | } 104 | } 105 | 106 | resource "aws_internet_gateway" "prd-igw" { 107 | vpc_id = aws_vpc.prd-vpc.id 108 | 109 | tags = { 110 | Name = "prd-igw" 111 | } 112 | } 113 | 114 | resource "aws_route_table" "prd-pub-rt" { 115 | vpc_id = aws_vpc.prd-vpc.id 116 | 117 | route { 118 | cidr_block = "0.0.0.0/0" 119 | gateway_id = aws_internet_gateway.prd-igw.id 120 | } 121 | } 122 | 123 | resource "aws_route_table_association" "prd-pub-rt-assoc-1" { 124 | subnet_id = aws_subnet.prd-pub-subnet-1.id 125 | route_table_id = aws_route_table.prd-pub-rt.id 126 | } 127 | 128 | resource "aws_route_table_association" "prd-pub-rt-assoc-2" { 129 | subnet_id = aws_subnet.prd-pub-subnet-2.id 130 | route_table_id = aws_route_table.prd-pub-rt.id 131 | } 132 | 133 | resource "aws_route_table_association" "prd-pub-rt-assoc-3" { 134 | subnet_id = aws_subnet.prd-pub-subnet-3.id 135 | route_table_id = aws_route_table.prd-pub-rt.id 136 | } 137 | 138 | resource "aws_route_table" "prd-pri-rt" { 139 | vpc_id = aws_vpc.prd-vpc.id 140 | } 141 | 142 | resource "aws_route_table_association" "prd-pri-rt-assoc-1" { 143 | subnet_id = aws_subnet.prd-pri-subnet-1.id 144 | route_table_id = aws_route_table.prd-pri-rt.id 145 | } 146 | 147 | resource "aws_route_table_association" "prd-pri-rt-assoc-2" { 148 | subnet_id = aws_subnet.prd-pri-subnet-2.id 149 | route_table_id = aws_route_table.prd-pri-rt.id 150 | } 151 | 152 | resource "aws_route_table_association" "prd-pri-rt-assoc-3" { 153 | subnet_id = aws_subnet.prd-pri-subnet-3.id 154 | route_table_id = aws_route_table.prd-pri-rt.id 155 | } -------------------------------------------------------------------------------- /copilot-course/2-code-suggestions/outputs.tf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/2-code-suggestions/outputs.tf -------------------------------------------------------------------------------- /copilot-course/2-code-suggestions/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } 4 | 5 | -------------------------------------------------------------------------------- /copilot-course/2-code-suggestions/terraform.tfvars: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/2-code-suggestions/terraform.tfvars -------------------------------------------------------------------------------- /copilot-course/2-code-suggestions/variables.tf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/2-code-suggestions/variables.tf -------------------------------------------------------------------------------- /copilot-course/3-expanding-on-code-suggestions/README.md: -------------------------------------------------------------------------------- 1 | # Terraform Project 2 | 3 | This is a Terraform project that contains infrastructure configuration using modules. 4 | 5 | ## Project Structure 6 | 7 | -------------------------------------------------------------------------------- /copilot-course/3-expanding-on-code-suggestions/main.tf: -------------------------------------------------------------------------------- 1 | 2 | # This Terraform configuration file creates a VPC and associated resources for different environments. 3 | 4 | # Configuring the required provider for AWS. 5 | terraform { 6 | required_providers { 7 | aws = { 8 | source = "hashicorp/aws" 9 | version = "5.64.0" 10 | } 11 | } 12 | } 13 | 14 | # Resource: aws_vpc.prd-vpc 15 | # Description: Creates a VPC for the production environment. 16 | resource "aws_vpc" "prd-vpc" { 17 | cidr_block = "10.0.0.0/16" 18 | } 19 | 20 | # Resource: aws_vpc.dev-vpc 21 | # Description: Creates a VPC for the development environment. 22 | resource "aws_vpc" "dev-vpc" { 23 | cidr_block = "10.10.0.0/16" 24 | } 25 | 26 | # Try creating the resource block for an aws_eks_cluster resource using Copilot here 27 | # Do NOT apply this configuration as it will incur costs 28 | # I've commented it out to prevent accidental execution 29 | 30 | # resource "aws_eks_cluster" "my-cluster" { 31 | # name = "my-cluster" 32 | # role_arn = aws_iam_role.my-cluster-role.arn 33 | # vpc_config { 34 | # subnet_ids = [aws_subnet.prd-pub-subnet-1.id, aws_subnet.prd-pub-subnet-2.id, aws_subnet.prd-pub-subnet-3.id] 35 | # } 36 | # } 37 | 38 | # Resource: aws_security_group.dev-web-sg 39 | # Description: Creates a security group for the development web server. 40 | resource "aws_security_group" "dev-web-sg" { 41 | vpc_id = aws_vpc.dev-vpc.id 42 | 43 | ingress { 44 | description = "allow inbound traffic from the internet" 45 | from_port = 80 46 | to_port = 80 47 | protocol = "tcp" 48 | cidr_blocks = ["10.0.0.0/16"] 49 | } 50 | } 51 | 52 | # Resource: aws_vpc.test-vpc 53 | # Description: Creates a VPC for testing Copilot features. 54 | resource "aws_vpc" "test-vpc" { 55 | cidr_block = "10.20.0.0/16" 56 | } 57 | 58 | # Resource: aws_subnet.prd-pub-subnet-1 59 | # Description: Creates a public subnet in the production VPC. 60 | resource "aws_subnet" "prd-pub-subnet-1" { 61 | vpc_id = aws_vpc.prd-vpc.id 62 | cidr_block = "10.0.0.0/24" 63 | availability_zone = "us-east-1a" 64 | 65 | tags = { 66 | Name = "prd-pub-subnet-1" 67 | } 68 | } 69 | 70 | # Resource: aws_subnet.prd-pub-subnet-2 71 | # Description: Creates a public subnet in the production VPC. 72 | resource "aws_subnet" "prd-pub-subnet-2" { 73 | vpc_id = aws_vpc.prd-vpc.id 74 | cidr_block = "10.0.1.0/24" 75 | availability_zone = "us-east-1b" 76 | 77 | tags = { 78 | Name = "prd-pub-subnet-2" 79 | } 80 | } 81 | 82 | # Resource: aws_subnet.prd-pub-subnet-3 83 | # Description: Creates a public subnet in the production VPC. 84 | resource "aws_subnet" "prd-pub-subnet-3" { 85 | vpc_id = aws_vpc.prd-vpc.id 86 | cidr_block = "10.0.2.0/24" 87 | availability_zone = "us-east-1c" 88 | 89 | tags = { 90 | Name = "prd-pub-subnet-3" 91 | } 92 | } 93 | 94 | # Resource: aws_subnet.prd-pri-subnet-1 95 | # Description: Creates a private subnet in the production VPC. 96 | resource "aws_subnet" "prd-pri-subnet-1" { 97 | vpc_id = aws_vpc.prd-vpc.id 98 | cidr_block = "10.0.10.0/24" 99 | availability_zone = "us-east-1a" 100 | 101 | tags = { 102 | Name = "prd-pri-subnet-1" 103 | } 104 | } 105 | 106 | # Resource: aws_subnet.prd-pri-subnet-2 107 | # Description: Creates a private subnet in the production VPC. 108 | resource "aws_subnet" "prd-pri-subnet-2" { 109 | vpc_id = aws_vpc.prd-vpc.id 110 | cidr_block = "10.0.11.0/24" 111 | availability_zone = "us-east-1b" 112 | 113 | tags = { 114 | Name = "prd-pri-subnet-2" 115 | } 116 | } 117 | 118 | # Resource: aws_subnet.prd-pri-subnet-3 119 | # Description: Creates a private subnet in the production VPC. 120 | resource "aws_subnet" "prd-pri-subnet-3" { 121 | vpc_id = aws_vpc.prd-vpc.id 122 | cidr_block = "10.0.12.0/24" 123 | availability_zone = "us-east-1c" 124 | 125 | tags = { 126 | Name = "prd-pri-subnet-3" 127 | } 128 | } 129 | 130 | # Resource: aws_internet_gateway.prd-igw 131 | # Description: Creates an internet gateway for the production VPC. 132 | resource "aws_internet_gateway" "prd-igw" { 133 | vpc_id = aws_vpc.prd-vpc.id 134 | 135 | tags = { 136 | Name = "prd-igw" 137 | } 138 | } 139 | 140 | # Resource: aws_route_table.prd-pub-rt 141 | # Description: Creates a route table for the public subnets in the production VPC. 142 | resource "aws_route_table" "prd-pub-rt" { 143 | vpc_id = aws_vpc.prd-vpc.id 144 | 145 | route { 146 | cidr_block = "0.0.0.0/0" 147 | gateway_id = aws_internet_gateway.prd-igw.id 148 | } 149 | } 150 | 151 | # Resource: aws_route_table_association.prd-pub-rt-assoc-1 152 | # Description: Associates the public subnet 1 with the public route table in the production VPC. 153 | resource "aws_route_table_association" "prd-pub-rt-assoc-1" { 154 | subnet_id = aws_subnet.prd-pub-subnet-1.id 155 | route_table_id = aws_route_table.prd-pub-rt.id 156 | } 157 | 158 | # Resource: aws_route_table_association.prd-pub-rt-assoc-2 159 | # Description: Associates the public subnet 2 with the public route table in the production VPC. 160 | resource "aws_route_table_association" "prd-pub-rt-assoc-2" { 161 | subnet_id = aws_subnet.prd-pub-subnet-2.id 162 | route_table_id = aws_route_table.prd-pub-rt.id 163 | } 164 | 165 | # Resource: aws_route_table_association.prd-pub-rt-assoc-3 166 | # Description: Associates the public subnet 3 with the public route table in the production VPC. 167 | resource "aws_route_table_association" "prd-pub-rt-assoc-3" { 168 | subnet_id = aws_subnet.prd-pub-subnet-3.id 169 | route_table_id = aws_route_table.prd-pub-rt.id 170 | } 171 | 172 | # Resource: aws_route_table.prd-pri-rt 173 | # Description: Creates a route table for the private subnets in the production VPC. 174 | resource "aws_route_table" "prd-pri-rt" { 175 | vpc_id = aws_vpc.prd-vpc.id 176 | } 177 | 178 | # Resource: aws_route_table_association.prd-pri-rt-assoc-1 179 | # Description: Associates the private subnet 1 with the private route table in the production VPC. 180 | resource "aws_route_table_association" "prd-pri-rt-assoc-1" { 181 | subnet_id = aws_subnet.prd-pri-subnet-1.id 182 | route_table_id = aws_route_table.prd-pri-rt.id 183 | } 184 | 185 | # Resource: aws_route_table_association.prd-pri-rt-assoc-2 186 | # Description: Associates the private subnet 2 with the private route table in the production VPC. 187 | resource "aws_route_table_association" "prd-pri-rt-assoc-2" { 188 | subnet_id = aws_subnet.prd-pri-subnet-2.id 189 | route_table_id = aws_route_table.prd-pri-rt.id 190 | } 191 | 192 | # Resource: aws_route_table_association.prd-pri-rt-assoc-3 193 | # Description: Associates the private subnet 3 with the private route table in the production VPC. 194 | resource "aws_route_table_association" "prd-pri-rt-assoc-3" { 195 | subnet_id = aws_subnet.prd-pri-subnet-3.id 196 | route_table_id = aws_route_table.prd-pri-rt.id 197 | } 198 | -------------------------------------------------------------------------------- /copilot-course/3-expanding-on-code-suggestions/outputs.tf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/3-expanding-on-code-suggestions/outputs.tf -------------------------------------------------------------------------------- /copilot-course/3-expanding-on-code-suggestions/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } 4 | 5 | -------------------------------------------------------------------------------- /copilot-course/3-expanding-on-code-suggestions/terraform.tfvars: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/3-expanding-on-code-suggestions/terraform.tfvars -------------------------------------------------------------------------------- /copilot-course/3-expanding-on-code-suggestions/variables.tf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/3-expanding-on-code-suggestions/variables.tf -------------------------------------------------------------------------------- /copilot-course/4-using-copilot-menu/README.md: -------------------------------------------------------------------------------- 1 | # Terraform Project 2 | 3 | This is a Terraform project that contains infrastructure configuration using modules. 4 | 5 | ## Project Structure 6 | 7 | -------------------------------------------------------------------------------- /copilot-course/4-using-copilot-menu/main.tf: -------------------------------------------------------------------------------- 1 | # Use Copilot to create documentation for the resources in this file 2 | 3 | terraform { 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "5.64.0" 8 | # Higlight this version paramenter 9 | # Right click, and select the Explain This option under the Copilot menu 10 | } 11 | } 12 | } 13 | 14 | # Higlight this resource block 15 | # Right click, and select the Explain This option under the Copilot menu 16 | resource "aws_vpc" "prd-vpc" { 17 | cidr_block = "10.0.0.0/16" 18 | } 19 | 20 | # cretaing a new vpc for development workloads 21 | resource "aws_vpc" "dev-vpc" { 22 | cidr_block = "10.10.0.0/16" 23 | } 24 | 25 | resource "aws_security_group" "dev-web-sg" { 26 | vpc_id = aws_vpc.dev-vpc.id 27 | 28 | ingress { 29 | description = "allow inbound traffic from the internet" 30 | from_port = 80 31 | to_port = 80 32 | protocol = "tcp" 33 | cidr_blocks = [10.0.0.0/16] 34 | # Something is wrong with this parameter 35 | # Highlight the cidr_blocks parameter and value, right click, and have Copilot Fix This! 36 | # Solution: the value should be a string, so it should be ["10.0.00/16"] 37 | } 38 | } 39 | # Something is wrong with this resource block 40 | # Highlight this block, right click, and have Copilot Fix This! 41 | # Solution: the vpc resource block is missing the cidr_block parameter 42 | resource "aws_vpc" "test-vpc" { 43 | } 44 | 45 | resource "aws_subnet" "prd-pub-subnet-1" { 46 | vpc_id = aws_vpc.prd-vpc.id 47 | cidr_block = "10.0.0.0/24" 48 | availability_zone = "us-east-1a" 49 | 50 | tags = { 51 | Name = "prd-pub-subnet-1" 52 | } 53 | } 54 | 55 | resource "aws_subnet" "prd-pub-subnet-2" { 56 | vpc_id = aws_vpc.prd-vpc.id 57 | cidr_block = "10.0.1.0/24" 58 | availability_zone = "us-east-1b" 59 | 60 | tags = { 61 | Name = "prd-pub-subnet-2" 62 | } 63 | } 64 | 65 | resource "aws_subnet" "prd-pub-subnet-3" { 66 | vpc_id = aws_vpc.prd-vpc.id 67 | cidr_block = "10.0.2.0/24" 68 | availability_zone = "us-east-1c" 69 | 70 | tags = { 71 | Name = "prd-pub-subnet-3" 72 | } 73 | } 74 | 75 | resource "aws_subnet" "prd-pri-subnet-1" { 76 | vpc_id = aws_vpc.prd-vpc.id 77 | cidr_block = "10.0.10.0/24" 78 | availability_zone = "us-east-1a" 79 | 80 | tags = { 81 | Name = "prd-pri-subnet-1" 82 | } 83 | } 84 | 85 | resource "aws_subnet" "prd-pri-subnet-2" { 86 | vpc_id = aws_vpc.prd-vpc.id 87 | cidr_block = "10.0.11.0/24" 88 | availability_zone = "us-east-1b" 89 | 90 | tags = { 91 | Name = "prd-pri-subnet-2" 92 | } 93 | } 94 | 95 | resource "aws_subnet" "prd-pri-subnet-3" { 96 | vpc_id = aws_vpc.prd-vpc.id 97 | cidr_block = "10.0.12.0/24" 98 | availability_zone = "us-east-1c" 99 | 100 | tags = { 101 | Name = "prd-pri-subnet-3" 102 | } 103 | } 104 | 105 | resource "aws_internet_gateway" "prd-igw" { 106 | vpc_id = aws_vpc.prd-vpc.id 107 | 108 | tags = { 109 | Name = "prd-igw" 110 | } 111 | } 112 | 113 | resource "aws_route_table" "prd-pub-rt" { 114 | vpc_id = aws_vpc.prd-vpc.id 115 | 116 | route { 117 | cidr_block = "0.0.0.0/0" 118 | gateway_id = aws_internet_gateway.prd-igw.id 119 | } 120 | } 121 | 122 | resource "aws_route_table_association" "prd-pub-rt-assoc-1" { 123 | subnet_id = aws_subnet.prd-pub-subnet-1.id 124 | route_table_id = aws_route_table.prd-pub-rt.id 125 | } 126 | 127 | resource "aws_route_table_association" "prd-pub-rt-assoc-2" { 128 | subnet_id = aws_subnet.prd-pub-subnet-2.id 129 | route_table_id = aws_route_table.prd-pub-rt.id 130 | } 131 | 132 | resource "aws_route_table_association" "prd-pub-rt-assoc-3" { 133 | subnet_id = aws_subnet.prd-pub-subnet-3.id 134 | route_table_id = aws_route_table.prd-pub-rt.id 135 | } 136 | 137 | resource "aws_route_table" "prd-pri-rt" { 138 | vpc_id = aws_vpc.prd-vpc.id 139 | } 140 | 141 | resource "aws_route_table_association" "prd-pri-rt-assoc-1" { 142 | subnet_id = aws_subnet.prd-pri-subnet-1.id 143 | route_table_id = aws_route_table.prd-pri-rt.id 144 | } 145 | 146 | resource "aws_route_table_association" "prd-pri-rt-assoc-2" { 147 | subnet_id = aws_subnet.prd-pri-subnet-2.id 148 | route_table_id = aws_route_table.prd-pri-rt.id 149 | } 150 | 151 | resource "aws_route_table_association" "prd-pri-rt-assoc-3" { 152 | subnet_id = aws_subnet.prd-pri-subnet-3.id 153 | route_table_id = aws_route_table.prd-pri-rt.id 154 | } 155 | -------------------------------------------------------------------------------- /copilot-course/4-using-copilot-menu/outputs.tf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/4-using-copilot-menu/outputs.tf -------------------------------------------------------------------------------- /copilot-course/4-using-copilot-menu/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } 4 | 5 | -------------------------------------------------------------------------------- /copilot-course/4-using-copilot-menu/terraform.tfvars: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/4-using-copilot-menu/terraform.tfvars -------------------------------------------------------------------------------- /copilot-course/4-using-copilot-menu/variables.tf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/4-using-copilot-menu/variables.tf -------------------------------------------------------------------------------- /copilot-course/5-create-a-module/README.md: -------------------------------------------------------------------------------- 1 | # Terraform Project 2 | 3 | This is a Terraform project that contains infrastructure configuration using modules. 4 | 5 | ## Project Structure 6 | 7 | -------------------------------------------------------------------------------- /copilot-course/5-create-a-module/main.tf: -------------------------------------------------------------------------------- 1 | 2 | # This Terraform configuration file creates a VPC and associated resources for different environments. 3 | 4 | # Configuring the required provider for AWS. 5 | terraform { 6 | required_providers { 7 | aws = { 8 | source = "hashicorp/aws" 9 | version = "5.64.0" 10 | } 11 | } 12 | } 13 | 14 | # Resource: aws_vpc.prd-vpc 15 | # Description: Creates a VPC for the production environment. 16 | resource "aws_vpc" "prd-vpc" { 17 | cidr_block = "10.0.0.0/16" 18 | } 19 | 20 | # Resource: aws_vpc.dev-vpc 21 | # Description: Creates a VPC for the development environment. 22 | 23 | # Use Copilot to create a new module for the development VPC 24 | # Solution: change the resource block below to: 25 | # module "vpc" { 26 | # source = "./modules/vpc" 27 | 28 | # vpc_cidr_block = var.dev_cidr_block 29 | # vpc_name = var.dev_vpc_name 30 | # } 31 | 32 | resource "aws_vpc" "dev-vpc" { 33 | cidr_block = "10.10.0.0/16" 34 | } 35 | 36 | # Resource: aws_security_group.dev-web-sg 37 | # Description: Creates a security group for the development web server. 38 | resource "aws_security_group" "dev-web-sg" { 39 | # Change the parameter below to use the new module 40 | # Solution: vpc_id = module.vpc.vpc_id 41 | vpc_id = aws_vpc.dev-vpc.id 42 | 43 | ingress { 44 | description = "allow inbound traffic from the internet" 45 | from_port = 80 46 | to_port = 80 47 | protocol = "tcp" 48 | cidr_blocks = ["10.0.0.0/16"] 49 | } 50 | } 51 | 52 | # Resource: aws_vpc.test-vpc 53 | # Description: Creates a VPC for testing Copilot features. 54 | resource "aws_vpc" "test-vpc" { 55 | cidr_block = "10.20.0.0/16" 56 | } 57 | 58 | # Resource: aws_subnet.prd-pub-subnet-1 59 | # Description: Creates a public subnet in the production VPC. 60 | resource "aws_subnet" "prd-pub-subnet-1" { 61 | vpc_id = aws_vpc.prd-vpc.id 62 | cidr_block = "10.0.0.0/24" 63 | availability_zone = "us-east-1a" 64 | 65 | tags = { 66 | Name = "prd-pub-subnet-1" 67 | } 68 | } 69 | 70 | # Resource: aws_subnet.prd-pub-subnet-2 71 | # Description: Creates a public subnet in the production VPC. 72 | resource "aws_subnet" "prd-pub-subnet-2" { 73 | vpc_id = aws_vpc.prd-vpc.id 74 | cidr_block = "10.0.1.0/24" 75 | availability_zone = "us-east-1b" 76 | 77 | tags = { 78 | Name = "prd-pub-subnet-2" 79 | } 80 | } 81 | 82 | # Resource: aws_subnet.prd-pub-subnet-3 83 | # Description: Creates a public subnet in the production VPC. 84 | resource "aws_subnet" "prd-pub-subnet-3" { 85 | vpc_id = aws_vpc.prd-vpc.id 86 | cidr_block = "10.0.2.0/24" 87 | availability_zone = "us-east-1c" 88 | 89 | tags = { 90 | Name = "prd-pub-subnet-3" 91 | } 92 | } 93 | 94 | # Resource: aws_subnet.prd-pri-subnet-1 95 | # Description: Creates a private subnet in the production VPC. 96 | resource "aws_subnet" "prd-pri-subnet-1" { 97 | vpc_id = aws_vpc.prd-vpc.id 98 | cidr_block = "10.0.10.0/24" 99 | availability_zone = "us-east-1a" 100 | 101 | tags = { 102 | Name = "prd-pri-subnet-1" 103 | } 104 | } 105 | 106 | # Resource: aws_subnet.prd-pri-subnet-2 107 | # Description: Creates a private subnet in the production VPC. 108 | resource "aws_subnet" "prd-pri-subnet-2" { 109 | vpc_id = aws_vpc.prd-vpc.id 110 | cidr_block = "10.0.11.0/24" 111 | availability_zone = "us-east-1b" 112 | 113 | tags = { 114 | Name = "prd-pri-subnet-2" 115 | } 116 | } 117 | 118 | # Resource: aws_subnet.prd-pri-subnet-3 119 | # Description: Creates a private subnet in the production VPC. 120 | resource "aws_subnet" "prd-pri-subnet-3" { 121 | vpc_id = aws_vpc.prd-vpc.id 122 | cidr_block = "10.0.12.0/24" 123 | availability_zone = "us-east-1c" 124 | 125 | tags = { 126 | Name = "prd-pri-subnet-3" 127 | } 128 | } 129 | 130 | # Resource: aws_internet_gateway.prd-igw 131 | # Description: Creates an internet gateway for the production VPC. 132 | resource "aws_internet_gateway" "prd-igw" { 133 | vpc_id = aws_vpc.prd-vpc.id 134 | 135 | tags = { 136 | Name = "prd-igw" 137 | } 138 | } 139 | 140 | # Resource: aws_route_table.prd-pub-rt 141 | # Description: Creates a route table for the public subnets in the production VPC. 142 | resource "aws_route_table" "prd-pub-rt" { 143 | vpc_id = aws_vpc.prd-vpc.id 144 | 145 | route { 146 | cidr_block = "0.0.0.0/0" 147 | gateway_id = aws_internet_gateway.prd-igw.id 148 | } 149 | } 150 | 151 | # Resource: aws_route_table_association.prd-pub-rt-assoc-1 152 | # Description: Associates the public subnet 1 with the public route table in the production VPC. 153 | resource "aws_route_table_association" "prd-pub-rt-assoc-1" { 154 | subnet_id = aws_subnet.prd-pub-subnet-1.id 155 | route_table_id = aws_route_table.prd-pub-rt.id 156 | } 157 | 158 | # Resource: aws_route_table_association.prd-pub-rt-assoc-2 159 | # Description: Associates the public subnet 2 with the public route table in the production VPC. 160 | resource "aws_route_table_association" "prd-pub-rt-assoc-2" { 161 | subnet_id = aws_subnet.prd-pub-subnet-2.id 162 | route_table_id = aws_route_table.prd-pub-rt.id 163 | } 164 | 165 | # Resource: aws_route_table_association.prd-pub-rt-assoc-3 166 | # Description: Associates the public subnet 3 with the public route table in the production VPC. 167 | resource "aws_route_table_association" "prd-pub-rt-assoc-3" { 168 | subnet_id = aws_subnet.prd-pub-subnet-3.id 169 | route_table_id = aws_route_table.prd-pub-rt.id 170 | } 171 | 172 | # Resource: aws_route_table.prd-pri-rt 173 | # Description: Creates a route table for the private subnets in the production VPC. 174 | resource "aws_route_table" "prd-pri-rt" { 175 | vpc_id = aws_vpc.prd-vpc.id 176 | } 177 | 178 | # Resource: aws_route_table_association.prd-pri-rt-assoc-1 179 | # Description: Associates the private subnet 1 with the private route table in the production VPC. 180 | resource "aws_route_table_association" "prd-pri-rt-assoc-1" { 181 | subnet_id = aws_subnet.prd-pri-subnet-1.id 182 | route_table_id = aws_route_table.prd-pri-rt.id 183 | } 184 | 185 | # Resource: aws_route_table_association.prd-pri-rt-assoc-2 186 | # Description: Associates the private subnet 2 with the private route table in the production VPC. 187 | resource "aws_route_table_association" "prd-pri-rt-assoc-2" { 188 | subnet_id = aws_subnet.prd-pri-subnet-2.id 189 | route_table_id = aws_route_table.prd-pri-rt.id 190 | } 191 | 192 | # Resource: aws_route_table_association.prd-pri-rt-assoc-3 193 | # Description: Associates the private subnet 3 with the private route table in the production VPC. 194 | resource "aws_route_table_association" "prd-pri-rt-assoc-3" { 195 | subnet_id = aws_subnet.prd-pri-subnet-3.id 196 | route_table_id = aws_route_table.prd-pri-rt.id 197 | } 198 | -------------------------------------------------------------------------------- /copilot-course/5-create-a-module/modules/vpc/main.tf: -------------------------------------------------------------------------------- 1 | # resource "aws_vpc" "vpc" { 2 | # cidr_block = var.vpc_cidr_block 3 | # enable_dns_support = true 4 | # enable_dns_hostnames = true 5 | 6 | # tags = { 7 | # Name = var.vpc_name 8 | # } 9 | # } 10 | 11 | -------------------------------------------------------------------------------- /copilot-course/5-create-a-module/modules/vpc/outputs.tf: -------------------------------------------------------------------------------- 1 | # output "vpc_id" { 2 | # description = "The ID of the VPC" 3 | # value = aws_vpc.vpc.id 4 | # } 5 | 6 | # output "vpc_cidr_block" { 7 | # description = "The CIDR block of the VPC" 8 | # value = aws_vpc.vpc.cidr_block 9 | # } -------------------------------------------------------------------------------- /copilot-course/5-create-a-module/modules/vpc/variables.tf: -------------------------------------------------------------------------------- 1 | # variable "vpc_cidr_block" { 2 | # description = "The CIDR block for the VPC" 3 | # type = string 4 | # } 5 | 6 | # variable "vpc_name" { 7 | # description = "The name of the VPC" 8 | # type = string 9 | # } 10 | -------------------------------------------------------------------------------- /copilot-course/5-create-a-module/outputs.tf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/btkrausen/terraform/4c9a1ae2ab6cd42a21717ae35c1f4db6ea82b03a/copilot-course/5-create-a-module/outputs.tf -------------------------------------------------------------------------------- /copilot-course/5-create-a-module/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } 4 | 5 | -------------------------------------------------------------------------------- /copilot-course/5-create-a-module/terraform.tfvars: -------------------------------------------------------------------------------- 1 | dev_cidr_block = "10.2.0.0/16" 2 | dev_vpc_name = "dev-vpc" -------------------------------------------------------------------------------- /copilot-course/5-create-a-module/variables.tf: -------------------------------------------------------------------------------- 1 | variable "dev_cidr_block" { 2 | description = "The CIDR block for the development VPC" 3 | type = string 4 | default = "10.0.0.0/16" 5 | } 6 | 7 | variable "dev_vpc_name" { 8 | description = "The name of the development VPC" 9 | type = string 10 | } 11 | -------------------------------------------------------------------------------- /copilot-course/6-intro-to-copilot-chat/README.md: -------------------------------------------------------------------------------- 1 | # Terraform Project 2 | 3 | This is a Terraform project that contains infrastructure configuration using modules. 4 | 5 | ## Project Structure 6 | 7 | -------------------------------------------------------------------------------- /copilot-course/6-intro-to-copilot-chat/main.tf: -------------------------------------------------------------------------------- 1 | 2 | # This Terraform configuration file creates a VPC and associated resources for different environments. 3 | 4 | # Configuring the required provider for AWS. 5 | terraform { 6 | required_providers { 7 | aws = { 8 | source = "hashicorp/aws" 9 | version = "5.64.0" 10 | } 11 | } 12 | } 13 | 14 | # Resource: aws_vpc.prd-vpc 15 | # Description: Creates a VPC for the production environment. 16 | resource "aws_vpc" "prd-vpc" { 17 | cidr_block = var.prd_vpc_cidr_block 18 | enable_dns_hostnames = var.prd_vpc_enable_dns_hostnames 19 | } 20 | 21 | # Resource: aws_vpc.dev-vpc 22 | # Description: Creates a VPC for the development environment. 23 | module "vpc" { 24 | source = "./modules/vpc" 25 | 26 | vpc_cidr_block = var.dev_cidr_block 27 | vpc_name = var.dev_vpc_name 28 | } 29 | 30 | 31 | # Resource: aws_security_group.dev-web-sg 32 | # Description: Creates a security group for the development web server. 33 | resource "aws_security_group" "dev-web-sg" { 34 | vpc_id = module 35 | 36 | ingress { 37 | description = "allow inbound traffic from the internet" 38 | from_port = 80 39 | to_port = 80 40 | protocol = "tcp" 41 | cidr_blocks = ["10.0.0.0/16"] 42 | } 43 | } 44 | 45 | # Resource: aws_vpc.test-vpc 46 | # Description: Creates a VPC for testing Copilot features. 47 | resource "aws_vpc" "test-vpc" { 48 | cidr_block = "10.20.0.0/16" 49 | } 50 | 51 | # Resource: aws_subnet.prd-pub-subnet-1 52 | # Description: Creates a public subnet in the production VPC. 53 | resource "aws_subnet" "prd-pub-subnet-1" { 54 | vpc_id = aws_vpc.prd-vpc.id 55 | cidr_block = "10.0.0.0/24" 56 | availability_zone = "us-east-1a" 57 | 58 | tags = { 59 | Name = "prd-pub-subnet-1" 60 | } 61 | } 62 | 63 | # Resource: aws_subnet.prd-pub-subnet-2 64 | # Description: Creates a public subnet in the production VPC. 65 | resource "aws_subnet" "prd-pub-subnet-2" { 66 | vpc_id = aws_vpc.prd-vpc.id 67 | cidr_block = "10.0.1.0/24" 68 | availability_zone = "us-east-1b" 69 | 70 | tags = { 71 | Name = "prd-pub-subnet-2" 72 | } 73 | } 74 | 75 | # Resource: aws_subnet.prd-pub-subnet-3 76 | # Description: Creates a public subnet in the production VPC. 77 | resource "aws_subnet" "prd-pub-subnet-3" { 78 | vpc_id = aws_vpc.prd-vpc.id 79 | cidr_block = "10.0.2.0/24" 80 | availability_zone = "us-east-1c" 81 | 82 | tags = { 83 | Name = "prd-pub-subnet-3" 84 | } 85 | } 86 | 87 | # Resource: aws_subnet.prd-pri-subnet-1 88 | # Description: Creates a private subnet in the production VPC. 89 | resource "aws_subnet" "prd-pri-subnet-1" { 90 | vpc_id = aws_vpc.prd-vpc.id 91 | cidr_block = "10.0.10.0/24" 92 | availability_zone = "us-east-1a" 93 | 94 | tags = { 95 | Name = "prd-pri-subnet-1" 96 | } 97 | } 98 | 99 | # Resource: aws_subnet.prd-pri-subnet-2 100 | # Description: Creates a private subnet in the production VPC. 101 | resource "aws_subnet" "prd-pri-subnet-2" { 102 | vpc_id = aws_vpc.prd-vpc.id 103 | cidr_block = "10.0.11.0/24" 104 | availability_zone = "us-east-1b" 105 | 106 | tags = { 107 | Name = "prd-pri-subnet-2" 108 | } 109 | } 110 | 111 | # Resource: aws_subnet.prd-pri-subnet-3 112 | # Description: Creates a private subnet in the production VPC. 113 | resource "aws_subnet" "prd-pri-subnet-3" { 114 | vpc_id = aws_vpc.prd-vpc.id 115 | cidr_block = "10.0.12.0/24" 116 | availability_zone = "us-east-1c" 117 | 118 | tags = { 119 | Name = "prd-pri-subnet-3" 120 | } 121 | } 122 | 123 | # Resource: aws_internet_gateway.prd-igw 124 | # Description: Creates an internet gateway for the production VPC. 125 | resource "aws_internet_gateway" "prd-igw" { 126 | vpc_id = aws_vpc.prd-vpc.id 127 | 128 | tags = { 129 | Name = "prd-igw" 130 | } 131 | } 132 | 133 | # Resource: aws_route_table.prd-pub-rt 134 | # Description: Creates a route table for the public subnets in the production VPC. 135 | resource "aws_route_table" "prd-pub-rt" { 136 | vpc_id = aws_vpc.prd-vpc.id 137 | 138 | route { 139 | cidr_block = "0.0.0.0/0" 140 | gateway_id = aws_internet_gateway.prd-igw.id 141 | } 142 | } 143 | 144 | # Resource: aws_route_table_association.prd-pub-rt-assoc-1 145 | # Description: Associates the public subnet 1 with the public route table in the production VPC. 146 | resource "aws_route_table_association" "prd-pub-rt-assoc-1" { 147 | subnet_id = aws_subnet.prd-pub-subnet-1.id 148 | route_table_id = aws_route_table.prd-pub-rt.id 149 | } 150 | 151 | # Resource: aws_route_table_association.prd-pub-rt-assoc-2 152 | # Description: Associates the public subnet 2 with the public route table in the production VPC. 153 | resource "aws_route_table_association" "prd-pub-rt-assoc-2" { 154 | subnet_id = aws_subnet.prd-pub-subnet-2.id 155 | route_table_id = aws_route_table.prd-pub-rt.id 156 | } 157 | 158 | # Resource: aws_route_table_association.prd-pub-rt-assoc-3 159 | # Description: Associates the public subnet 3 with the public route table in the production VPC. 160 | resource "aws_route_table_association" "prd-pub-rt-assoc-3" { 161 | subnet_id = aws_subnet.prd-pub-subnet-3.id 162 | route_table_id = aws_route_table.prd-pub-rt.id 163 | } 164 | 165 | # Resource: aws_route_table.prd-pri-rt 166 | # Description: Creates a route table for the private subnets in the production VPC. 167 | resource "aws_route_table" "prd-pri-rt" { 168 | vpc_id = aws_vpc.prd-vpc.id 169 | } 170 | 171 | # Resource: aws_route_table_association.prd-pri-rt-assoc-1 172 | # Description: Associates the private subnet 1 with the private route table in the production VPC. 173 | resource "aws_route_table_association" "prd-pri-rt-assoc-1" { 174 | subnet_id = aws_subnet.prd-pri-subnet-1.id 175 | route_table_id = aws_route_table.prd-pri-rt.id 176 | } 177 | 178 | # Resource: aws_route_table_association.prd-pri-rt-assoc-2 179 | # Description: Associates the private subnet 2 with the private route table in the production VPC. 180 | resource "aws_route_table_association" "prd-pri-rt-assoc-2" { 181 | subnet_id = aws_subnet.prd-pri-subnet-2.id 182 | route_table_id = aws_route_table.prd-pri-rt.id 183 | } 184 | 185 | # Resource: aws_route_table_association.prd-pri-rt-assoc-3 186 | # Description: Associates the private subnet 3 with the private route table in the production VPC. 187 | resource "aws_route_table_association" "prd-pri-rt-assoc-3" { 188 | subnet_id = aws_subnet.prd-pri-subnet-3.id 189 | route_table_id = aws_route_table.prd-pri-rt.id 190 | } 191 | -------------------------------------------------------------------------------- /copilot-course/6-intro-to-copilot-chat/modules/vpc/main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_vpc" "vpc" { 2 | cidr_block = var.vpc_cidr_block 3 | enable_dns_support = true 4 | enable_dns_hostnames = true 5 | 6 | tags = { 7 | Name = var.vpc_name 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /copilot-course/6-intro-to-copilot-chat/modules/vpc/outputs.tf: -------------------------------------------------------------------------------- 1 | output "vpc_id" { 2 | description = "The ID of the VPC" 3 | value = aws_vpc.vpc.id 4 | } 5 | 6 | output "vpc_cidr_block" { 7 | description = "The CIDR block of the VPC" 8 | value = aws_vpc.vpc.cidr_block 9 | } -------------------------------------------------------------------------------- /copilot-course/6-intro-to-copilot-chat/modules/vpc/variables.tf: -------------------------------------------------------------------------------- 1 | variable "vpc_cidr_block" { 2 | description = "The CIDR block for the VPC" 3 | type = string 4 | } 5 | 6 | variable "vpc_name" { 7 | description = "The name of the VPC" 8 | type = string 9 | } -------------------------------------------------------------------------------- /copilot-course/6-intro-to-copilot-chat/outputs.tf: -------------------------------------------------------------------------------- 1 | output "public_subnet_ids" { 2 | value = aws_subnet.public.*.id 3 | } 4 | 5 | output "vpc_id" { 6 | value = aws_vpc.main.id 7 | } 8 | 9 | -------------------------------------------------------------------------------- /copilot-course/6-intro-to-copilot-chat/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } 4 | 5 | -------------------------------------------------------------------------------- /copilot-course/6-intro-to-copilot-chat/terraform.tfvars: -------------------------------------------------------------------------------- 1 | dev_cidr_block = "10.2.0.0/16" 2 | dev_vpc_name = "dev-vpc" 3 | -------------------------------------------------------------------------------- /copilot-course/6-intro-to-copilot-chat/variables.tf: -------------------------------------------------------------------------------- 1 | variable "prd_vpc_cidr_block" { 2 | description = "The CIDR block for the production VPC" 3 | type = string 4 | default = "10.0.0.0/16" 5 | validation { 6 | condition = can(regex("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(\\/\\d{1,2})?$", var.prd_vpc_cidr_block)) 7 | error_message = "Invalid CIDR block format. Please provide a valid IP address or CIDR block." 8 | } 9 | } 10 | 11 | variable "prd_vpc_enable_dns_hostnames" { 12 | description = "Enable DNS hostnames for the production VPC" 13 | type = bool 14 | default = true 15 | } 16 | 17 | variable "dev_cidr_block" { 18 | description = "The CIDR block for the development VPC" 19 | type = string 20 | default = "10.0.0.0/16" 21 | } 22 | 23 | variable "dev_vpc_name" { 24 | description = "The name of the development VPC" 25 | type = string 26 | } 27 | --------------------------------------------------------------------------------