├── .gitignore
├── .pre-commit-config.yaml
├── .tflint.hcl
├── IAM.md
├── LICENSE
├── README.md
├── compliance.md
├── examples
├── complete-vpc-with-vpn
│ ├── README.md
│ ├── main.tf
│ ├── outputs.tf
│ └── providers.tf
├── ipam-managed-vpc
│ ├── README.md
│ ├── main.tf
│ ├── output.tf
│ └── providers.tf
├── simple-vpc
│ ├── README.md
│ ├── main.tf
│ ├── output.tf
│ └── providers.tf
├── vpc-dualstack
│ ├── README.md
│ ├── main.tf
│ ├── outputs.tf
│ └── providers.tf
├── vpc-native-ipv6
│ ├── README.md
│ ├── main.tf
│ ├── outputs.tf
│ └── providers.tf
├── vpc-with-peering
│ ├── README.md
│ ├── main.tf
│ ├── output.tf
│ ├── provider.tf
│ └── vpc-requester-accepter
│ │ ├── main.tf
│ │ └── providers.tf
├── vpc-with-private-subnet
│ ├── README.md
│ ├── main.tf
│ ├── outputs.tf
│ └── providers.tf
└── vpc-with-secondary-cidr
│ ├── README.md
│ ├── main.tf
│ ├── outputs.tf
│ └── providers.tf
├── main.tf
├── modules
├── vpc_peering
│ ├── README.md
│ ├── main.tf
│ ├── outputs.tf
│ ├── variables.tf
│ └── versions.tf
└── vpn
│ ├── README.md
│ ├── main.tf
│ ├── outputs.tf
│ ├── scripts
│ └── pritunl-vpn.sh
│ ├── variables.tf
│ └── versions.tf
├── outputs.tf
├── tfsec.yaml
├── variables.tf
└── versions.tf
/.gitignore:
--------------------------------------------------------------------------------
1 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
2 | *.out
3 | *.lock
4 | *.tfvars
5 | *.pem
6 | *.txt
7 |
8 | # Local .terraform directories
9 | **/.terraform/*
10 | .terraform*
11 |
12 | # .tfstate files
13 | *.tfstate
14 | *.tfstate.*
15 |
16 | # Crash log files
17 | crash.log
18 | crash.*.log
19 |
20 | *.tfvars
21 | *.tfvars.json
22 |
23 | # Ignore override files as they are usually used to override resources locally and so
24 | # are not checked in
25 | override.tf
26 | override.tf.json
27 | *_override.tf
28 | *_override.tf.json
29 |
30 | # Ignore CLI configuration files
31 | .terraformrc
32 | terraform.rc
33 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | repos:
2 | - repo: https://github.com/pre-commit/pre-commit-hooks
3 | rev: v4.1.0
4 | hooks:
5 | - id: trailing-whitespace
6 | args: ['--markdown-linebreak-ext=md']
7 | - id: end-of-file-fixer
8 | - id: check-merge-conflict
9 | - id: detect-private-key
10 | - id: detect-aws-credentials
11 | args: ['--allow-missing-credentials']
12 | - repo: https://github.com/antonbabenko/pre-commit-terraform
13 | rev: v1.77.0
14 | hooks:
15 | - id: terraform_fmt
16 | - id: terraform_docs
17 | args:
18 | - '--args=--lockfile=false'
19 | - id: terraform_tflint
20 | args:
21 | - --args=--config=.tflint.hcl
22 | - id: terraform_tfsec
23 | files: ^examples/ # only scan `examples/*` which are the implementation
24 | args:
25 | - --args=--config-file=__GIT_WORKING_DIR__/tfsec.yaml
26 | - --args=--concise-output
27 |
--------------------------------------------------------------------------------
/.tflint.hcl:
--------------------------------------------------------------------------------
1 | plugin "aws" {
2 | enabled = true
3 | version = "0.21.1"
4 | source = "github.com/terraform-linters/tflint-ruleset-aws"
5 | }
6 | config {
7 | #Enables module inspection
8 | module = false
9 | force = false
10 | }
11 | # Required that all AWS resources have specified tags.
12 | rule "aws_resource_missing_tags" {
13 | enabled = true
14 | tags = [
15 | "Name",
16 | "Environment",
17 | ]
18 | }
19 | # Disallow deprecated (0.11-style) interpolation
20 | rule "terraform_deprecated_interpolation" {
21 | enabled = true
22 | }
23 | # Disallow legacy dot index syntax.
24 | rule "terraform_deprecated_index" {
25 | enabled = true
26 | }
27 | # Disallow variables, data sources, and locals that are declared but never used.
28 | rule "terraform_unused_declarations" {
29 | enabled = true
30 | }
31 | # Disallow // comments in favor of #.
32 | rule "terraform_comment_syntax" {
33 | enabled = false
34 | }
35 | # Disallow output declarations without description.
36 | rule "terraform_documented_outputs" {
37 | enabled = true
38 | }
39 | # Disallow variable declarations without description.
40 | rule "terraform_documented_variables" {
41 | enabled = true
42 | }
43 | # Disallow variable declarations without type.
44 | rule "terraform_typed_variables" {
45 | enabled = true
46 | }
47 | # Disallow specifying a git or mercurial repository as a module source without pinning to a version.
48 | rule "terraform_module_pinned_source" {
49 | enabled = true
50 | }
51 | # Enforces naming conventions
52 | rule "terraform_naming_convention" {
53 | enabled = true
54 | #Require specific naming structure
55 | variable {
56 | format = "snake_case"
57 | }
58 | locals {
59 | format = "snake_case"
60 | }
61 | output {
62 | format = "snake_case"
63 | }
64 | #Allow any format
65 | resource {
66 | format = "none"
67 | }
68 | module {
69 | format = "none"
70 | }
71 | data {
72 | format = "none"
73 | }
74 | }
75 | # Disallow terraform declarations without require_version.
76 | rule "terraform_required_version" {
77 | enabled = true
78 | }
79 | # Require that all providers have version constraints through required_providers.
80 | rule "terraform_required_providers" {
81 | enabled = true
82 | }
83 | # Ensure that a module complies with the Terraform Standard Module Structure
84 | rule "terraform_standard_module_structure" {
85 | enabled = true
86 | }
87 | # terraform.workspace should not be used with a "remote" backend with remote execution.
88 | rule "terraform_workspace_remote" {
89 | enabled = true
90 | }
91 |
--------------------------------------------------------------------------------
/IAM.md:
--------------------------------------------------------------------------------
1 |
2 | ## IAM Permission
3 |
4 | The Policy required to deploy this module is:
5 |
6 | ```json
7 | {
8 | "Version": "2012-10-17",
9 | "Statement": [
10 | {
11 | "Sid": "VisualEditor0",
12 | "Effect": "Allow",
13 | "Action": [
14 | "ec2:AllocateAddress",
15 | "ec2:AssociateAddress",
16 | "ec2:AssociateDhcpOptions",
17 | "ec2:AssociateRouteTable",
18 | "ec2:AssociateVpcCidrBlock",
19 | "ec2:AttachInternetGateway",
20 | "ec2:AttachVpnGateway",
21 | "ec2:AuthorizeSecurityGroupEgress",
22 | "ec2:AuthorizeSecurityGroupIngress",
23 | "ec2:CancelSpotInstanceRequests",
24 | "ec2:CreateCustomerGateway",
25 | "ec2:CreateDefaultVpc",
26 | "ec2:CreateDhcpOptions",
27 | "ec2:CreateEgressOnlyInternetGateway",
28 | "ec2:CreateFlowLogs",
29 | "ec2:CreateInternetGateway",
30 | "ec2:CreateKeyPair",
31 | "ec2:CreateNatGateway",
32 | "ec2:CreateNetworkAcl",
33 | "ec2:CreateNetworkAclEntry",
34 | "ec2:CreateRoute",
35 | "ec2:CreateRouteTable",
36 | "ec2:CreateSecurityGroup",
37 | "ec2:CreateSubnet",
38 | "ec2:CreateTags",
39 | "ec2:CreateVPC",
40 | "ec2:CreateVpnGateway",
41 | "ec2:DeleteCustomerGateway",
42 | "ec2:DeleteDhcpOptions",
43 | "ec2:DeleteEgressOnlyInternetGateway",
44 | "ec2:DeleteFlowLogs",
45 | "ec2:DeleteInternetGateway",
46 | "ec2:DeleteKeyPair",
47 | "ec2:DeleteNatGateway",
48 | "ec2:DeleteNetworkAcl",
49 | "ec2:DeleteNetworkAclEntry",
50 | "ec2:DeleteRoute",
51 | "ec2:DeleteRouteTable",
52 | "ec2:DeleteSecurityGroup",
53 | "ec2:DeleteSubnet",
54 | "ec2:DeleteTags",
55 | "ec2:DeleteVPC",
56 | "ec2:DeleteVpnGateway",
57 | "ec2:DescribeAccountAttributes",
58 | "ec2:DescribeAddresses",
59 | "ec2:DescribeCustomerGateways",
60 | "ec2:DescribeDhcpOptions",
61 | "ec2:DescribeEgressOnlyInternetGateways",
62 | "ec2:DescribeFlowLogs",
63 | "ec2:DescribeInstanceAttribute",
64 | "ec2:DescribeInstanceCreditSpecifications",
65 | "ec2:DescribeInstanceTypes",
66 | "ec2:DescribeInstances",
67 | "ec2:DescribeInternetGateways",
68 | "ec2:DescribeKeyPairs",
69 | "ec2:DescribeNatGateways",
70 | "ec2:DescribeNetworkAcls",
71 | "ec2:DescribeNetworkInterfaces",
72 | "ec2:DescribeRouteTables",
73 | "ec2:DescribeSecurityGroups",
74 | "ec2:DescribeSpotInstanceRequests",
75 | "ec2:DescribeSubnets",
76 | "ec2:DescribeTags",
77 | "ec2:DescribeVolumes",
78 | "ec2:DescribeVpcAttribute",
79 | "ec2:DescribeVpcs",
80 | "ec2:DescribeVpnGateways",
81 | "ec2:DetachInternetGateway",
82 | "ec2:DetachVpnGateway",
83 | "ec2:DisableVgwRoutePropagation",
84 | "ec2:DisassociateAddress",
85 | "ec2:DisassociateRouteTable",
86 | "ec2:DisassociateVpcCidrBlock",
87 | "ec2:EnableVgwRoutePropagation",
88 | "ec2:ImportKeyPair",
89 | "ec2:ModifyInstanceAttribute",
90 | "ec2:MonitorInstances",
91 | "ec2:ReleaseAddress",
92 | "ec2:RequestSpotInstances",
93 | "ec2:RevokeSecurityGroupEgress",
94 | "ec2:RevokeSecurityGroupIngress",
95 | "ec2:RunInstances",
96 | "ec2:StartInstances",
97 | "ec2:StopInstances",
98 | "ec2:TerminateInstances",
99 | "ec2:UnmonitorInstances"
100 | ],
101 | "Resource": [
102 | "*"
103 | ]
104 | },
105 | {
106 | "Sid": "VisualEditor1",
107 | "Effect": "Allow",
108 | "Action": [
109 | "elasticache:AddTagsToResource",
110 | "elasticache:CreateCacheSubnetGroup",
111 | "elasticache:DeleteCacheSubnetGroup",
112 | "elasticache:DescribeCacheSubnetGroups",
113 | "elasticache:ListTagsForResource",
114 | "elasticache:ModifyCacheSubnetGroup",
115 | "elasticache:RemoveTagsFromResource"
116 | ],
117 | "Resource": [
118 | "*"
119 | ]
120 | },
121 | {
122 | "Sid": "VisualEditor2",
123 | "Effect": "Allow",
124 | "Action": [
125 | "iam:AttachRolePolicy",
126 | "iam:CreatePolicy",
127 | "iam:CreateRole",
128 | "iam:DeletePolicy",
129 | "iam:DeleteRole",
130 | "iam:DeleteRolePermissionsBoundary",
131 | "iam:DetachRolePolicy",
132 | "iam:GetPolicy",
133 | "iam:GetPolicyVersion",
134 | "iam:GetRole",
135 | "iam:ListAttachedRolePolicies",
136 | "iam:ListInstanceProfilesForRole",
137 | "iam:ListPolicyVersions",
138 | "iam:ListRolePolicies",
139 | "iam:PassRole",
140 | "iam:PutRolePermissionsBoundary",
141 | "iam:TagPolicy",
142 | "iam:TagRole",
143 | "iam:UntagPolicy"
144 | ],
145 | "Resource": [
146 | "*"
147 | ]
148 | },
149 | {
150 | "Sid": "VisualEditor3",
151 | "Effect": "Allow",
152 | "Action": [
153 | "kms:Decrypt"
154 | ],
155 | "Resource": [
156 | "*"
157 | ]
158 | },
159 | {
160 | "Sid": "VisualEditor4",
161 | "Effect": "Allow",
162 | "Action": [
163 | "logs:AssociateKmsKey",
164 | "logs:CreateLogGroup",
165 | "logs:DeleteLogGroup",
166 | "logs:DeleteRetentionPolicy",
167 | "logs:DescribeLogGroups",
168 | "logs:DisassociateKmsKey",
169 | "logs:ListTagsLogGroup",
170 | "logs:PutRetentionPolicy",
171 | "logs:TagLogGroup",
172 | "logs:UntagLogGroup"
173 | ],
174 | "Resource": [
175 | "*"
176 | ]
177 | },
178 | {
179 | "Sid": "VisualEditor5",
180 | "Effect": "Allow",
181 | "Action": [
182 | "rds:AddTagsToResource",
183 | "rds:CreateDBSubnetGroup",
184 | "rds:DeleteDBSubnetGroup",
185 | "rds:DescribeDBSubnetGroups",
186 | "rds:ListTagsForResource",
187 | "rds:RemoveTagsFromResource"
188 | ],
189 | "Resource": [
190 | "*"
191 | ]
192 | },
193 | {
194 | "Sid": "VisualEditor6",
195 | "Effect": "Allow",
196 | "Action": [
197 | "redshift:CreateClusterSubnetGroup",
198 | "redshift:CreateTags",
199 | "redshift:DeleteClusterSubnetGroup",
200 | "redshift:DeleteTags",
201 | "redshift:DescribeClusterSubnetGroups",
202 | "redshift:ModifyClusterSubnetGroup"
203 | ],
204 | "Resource": [
205 | "*"
206 | ]
207 | },
208 | {
209 | "Sid": "VisualEditor7",
210 | "Effect": "Allow",
211 | "Action": [
212 | "ssm:AddTagsToResource",
213 | "ssm:DeleteParameter",
214 | "ssm:DescribeParameters",
215 | "ssm:GetParameter",
216 | "ssm:GetParameters",
217 | "ssm:ListTagsForResource",
218 | "ssm:PutParameter"
219 | ],
220 | "Resource": [
221 | "*"
222 | ]
223 | }
224 | ]
225 | }
226 |
227 | ```
228 |
229 |
--------------------------------------------------------------------------------
/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 2023 SaturnOps Technologies
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 | # AWS Virtual Private Cloud (VPC) Terraform Module
2 |
3 |
4 |
5 |
6 |
7 | Terraform module designed to create networking resources on the AWS Cloud, supporting both IPv4 and dual stack IP modes for workload deployment.
8 |
9 | ## Usage Example
10 |
11 | ```hcl
12 |
13 | module "key_pair_vpn" {
14 | source = "saturnops/keypair/aws"
15 | environment = "production"
16 | key_name = format("%s-%s-vpn", "production", "skaf")
17 | ssm_parameter_path = format("%s-%s-vpn", "production", "skaf")
18 | }
19 |
20 |
21 | module "vpc" {
22 | source = "saturnops/vpc/aws"
23 | name = "skaf"
24 | vpc_cidr = "10.0.0.0/16"
25 | environment = "production"
26 | ipv6_enabled = true
27 | create_ipam_pool = false
28 | ipam_enabled = false
29 | flow_log_enabled = true
30 | vpn_key_pair_name = module.key_pair_vpn.key_pair_name
31 | availability_zones = ["us-east-1a", "us-east-1b"]
32 | vpn_server_enabled = false
33 | intra_subnet_enabled = true
34 | auto_assign_public_ip = true
35 | public_subnet_enabled = true
36 | private_subnet_enabled = true
37 | one_nat_gateway_per_az = true
38 | database_subnet_enabled = true
39 | vpn_server_instance_type = "t3a.small"
40 | vpc_s3_endpoint_enabled = true
41 | vpc_ecr_endpoint_enabled = true
42 | flow_log_max_aggregation_interval = 60
43 | flow_log_cloudwatch_log_group_skip_destroy = true
44 | flow_log_cloudwatch_log_group_retention_in_days = 90
45 | flow_log_cloudwatch_log_group_kms_key_arn = "arn:aws:kms:us-east-2:222222222222:key/kms_key_arn" #Enter your kms key arn
46 | }
47 | ```
48 | Refer [this](https://github.com/saturnops/terraform-aws-vpc/tree/main/examples) for more examples.
49 |
50 |
51 | ## Note
52 | To avoid interruptions during the destruction process, ensure that any resources created outside of Terraform, which are connected to Terraform-managed resources, are deleted before destroying the module.
53 |
54 | The private key generated by Keypair module will be stored in AWS Systems Manager Parameter Store. For more details refer [this](https://registry.terraform.io/modules/saturnops/keypair/aws)
55 |
56 | To encrypt the VPC flow log CloudWatch log group, please use the following KMS key policy. Make sure to replace the account ID and region with your specific details.
57 |
58 | ```json
59 | {
60 | "Version": "2012-10-17",
61 | "Id": "allow-cloudwatch-logs-encryption",
62 | "Statement": [
63 | {
64 | "Sid": "AllowRootFullPermissions",
65 | "Effect": "Allow",
66 | "Principal": {
67 | "AWS": "arn:aws:iam::12345678:root"
68 | },
69 | "Action": "kms:*",
70 | "Resource": "*"
71 | },
72 | {
73 | "Sid": "AllowCloudWatchLogsEncryption",
74 | "Effect": "Allow",
75 | "Principal": {
76 | "Service": "logs.us-east-2.amazonaws.com"
77 | },
78 | "Action": [
79 | "kms:Encrypt*",
80 | "kms:Decrypt*",
81 | "kms:ReEncrypt*",
82 | "kms:GenerateDataKey*",
83 | "kms:Describe*"
84 | ],
85 | "Resource": "*"
86 | }
87 | ]
88 | }
89 | ```
90 |
91 |
92 | ## Network Scenarios
93 |
94 | Users need to declare `vpc_cidr` and subnets are calculated with the help of in-built functions.
95 |
96 | This module supports three scenarios to create Network resource on AWS. Each will be explained in brief in the corresponding sections.
97 |
98 | - **simple-vpc (default behavior):** To create a VPC with public subnets and IGW.
99 | - `vpc_cidr = ""`
100 | - `public_subnet_enabled = true`
101 | - `auto_assign_public_ip = true`
102 | - **vpc-with-private-sub:** To create a VPC with public subnets, private subnets, IGW gateway and NAT gateway.
103 | - `vpc_cidr = ""`
104 | - `public_subnet_enabled = true`
105 | - `private_subnet_enabled = true`
106 | - `auto_assign_public_ip = true`
107 |
108 | - **complete-vpc-with-vpn:** To create a VPC with public, private, database and intra subnets along with an IGW and NAT gateway. Jump server/Bastion Host is also configured.
109 | - `vpc_cidr = ""`
110 | - `public_subnet_enabled = true`
111 | - `private_subnet_enabled = true`
112 | - `database_subnet_enabled = true`
113 | - `intra_subnet_enabled = true`
114 | - `auto_assign_public_ip = true`
115 | - `one_nat_gateway_per_az = true`
116 | - `vpn_server_enabled = true`
117 | - `vpn_server_instance_type = "t3a.small"`
118 | - `vpn_key_pair_name = ""`
119 | - `availability_zones = 2`
120 | - `flow_log_enabled = true`
121 | - `flow_log_max_aggregation_interval = 60`
122 | - `flow_log_cloudwatch_log_group_retention_in_days = 90`
123 | - `flow_log_cloudwatch_log_group_kms_key_arn = "arn:aws:kms:us-east-2:222222222222:key/kms_key_arn"`
124 |
125 | - **vpc-peering:** VPC peering support is available using submodule `vpc_peering`. Refer [Peering Docs](https://github.com/saturnops/terraform-aws-vpc/tree/main/modules/vpc_peering) for more information
126 | - `accepter_name = ""`
127 | - `accepter_vpc_id = ""`
128 | - `accepter_vpc_region = ""`
129 | - `requester_name = ""`
130 | - `requester_vpc_id = ""`
131 | - `requester_vpc_region = ""`
132 | - `auto_assign_public_ip = true`
133 | - `one_nat_gateway_per_az = true`
134 |
135 | - **vpc-with-ipv6:** To create VPC with IPv6 support, you only need to enable the parameter `ipv6_enabled`. Rest all the configurations will be taken care by module. Refer for example [vpc-with-ipv6](https://github.com/saturnops/terraform-aws-vpc/tree/main/examples/vpc-with-ipv6) for more information.
136 | - `vpc_cidr = ""`
137 | - `public_subnet_enabled = true`
138 | - `private_subnet_enabled = true`
139 | - `database_subnet_enabled = true`
140 | - `intra_subnet_enabled = true`
141 | - `auto_assign_public_ip = true`
142 | - `ipv6_enabled = true`
143 | - `public_subnet_assign_ipv6_address_on_creation = true`
144 | - `private_subnet_assign_ipv6_address_on_creation = true`
145 | - `database_subnet_assign_ipv6_address_on_creation = true`
146 | - `intra_subnet_assign_ipv6_address_on_creation = true`
147 |
148 | # IAM Permissions
149 | The required IAM permissions to create resources from this module can be found [here](https://github.com/saturnops/terraform-aws-vpc/blob/main/IAM.md)
150 |
151 |
152 | # VPN setup
153 | We are using Pritunl as VPN. It is using Ubuntu 22.04 image as underlying OS.
154 | To configure Pritunl VPN:
155 |
156 | 1. Access the Pritunl UI over HTTPS using the public IP of EC2 instance in browser
157 | 2. Retrieve the initial key, user and password for setting up Pritunl from AWS Secrets Manager and log in to Pritunl.
158 | 3. Create a DNS record mapping to the EC2 instance's public IP
159 | 4. After login, in the Initial setup window, add the record created in the 'Lets Encrypt Domain' field.
160 | 5. Pritunl will automatically configure a signed SSL certificate from Lets Encrypt.
161 | 6. Add organization and user to pritunl.
162 | 7. Add server and set port as 10150 which is already allowed from security group while creating instance for VPN server.
163 | 8. Attach organization to the server and Start the server.
164 | 9. Copy or download user profile link or file.
165 | 10. Import the profile in Pritunl client.
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 | ## Requirements
176 |
177 | | Name | Version |
178 | |------|---------|
179 | | [terraform](#requirement\_terraform) | >= 1.0 |
180 | | [aws](#requirement\_aws) | >= 4.23 |
181 |
182 | ## Providers
183 |
184 | | Name | Version |
185 | |------|---------|
186 | | [aws](#provider\_aws) | >= 4.23 |
187 |
188 | ## Modules
189 |
190 | | Name | Source | Version |
191 | |------|--------|---------|
192 | | [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | 5.2.0 |
193 | | [vpn\_server](#module\_vpn\_server) | ./modules/vpn | n/a |
194 |
195 | ## Resources
196 |
197 | | Name | Type |
198 | |------|------|
199 | | [aws_security_group.vpc_endpoints](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
200 | | [aws_vpc_endpoint.private-ecr-api](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint) | resource |
201 | | [aws_vpc_endpoint.private-ecr-dkr](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint) | resource |
202 | | [aws_vpc_endpoint.private-s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint) | resource |
203 | | [aws_vpc_ipam.ipam](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam) | resource |
204 | | [aws_vpc_ipam_pool.ipam_pool](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool) | resource |
205 | | [aws_vpc_ipam_pool_cidr.ipam_pool_cidr](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool_cidr) | resource |
206 | | [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
207 | | [aws_ec2_instance_type.arch](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_instance_type) | data source |
208 | | [aws_route_tables.aws_private_routes](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route_tables) | data source |
209 |
210 | ## Inputs
211 |
212 | | Name | Description | Type | Default | Required |
213 | |------|-------------|------|---------|:--------:|
214 | | [auto\_assign\_public\_ip](#input\_auto\_assign\_public\_ip) | Specify true to indicate that instances launched into the subnet should be assigned a public IP address. | `bool` | `false` | no |
215 | | [availability\_zones](#input\_availability\_zones) | Number of Availability Zone to be used by VPC Subnets | `list(any)` | `[]` | no |
216 | | [create\_ipam\_pool](#input\_create\_ipam\_pool) | Whether create new IPAM pool | `bool` | `true` | no |
217 | | [database\_subnet\_assign\_ipv6\_address\_on\_creation](#input\_database\_subnet\_assign\_ipv6\_address\_on\_creation) | Assign IPv6 address on database subnet, must be disabled to change IPv6 CIDRs. This is the IPv6 equivalent of map\_public\_ip\_on\_launch | `bool` | `null` | no |
218 | | [database\_subnet\_cidrs](#input\_database\_subnet\_cidrs) | Database Tier subnet CIDRs to be created | `list(any)` | `[]` | no |
219 | | [database\_subnet\_enabled](#input\_database\_subnet\_enabled) | Set true to enable database subnets | `bool` | `false` | no |
220 | | [default\_network\_acl\_ingress](#input\_default\_network\_acl\_ingress) | List of maps of ingress rules to set on the Default Network ACL | `list(map(string))` |
[| no | 221 | | [enable\_database\_subnet\_group](#input\_enable\_database\_subnet\_group) | Whether create database subnet groups | `bool` | `false` | no | 222 | | [environment](#input\_environment) | Specify the environment indentifier for the VPC | `string` | `""` | no | 223 | | [existing\_ipam\_managed\_cidr](#input\_existing\_ipam\_managed\_cidr) | The existing IPAM pool CIDR | `string` | `""` | no | 224 | | [flow\_log\_cloudwatch\_log\_group\_kms\_key\_arn](#input\_flow\_log\_cloudwatch\_log\_group\_kms\_key\_arn) | The ARN of the KMS Key to use when encrypting log data for VPC flow logs | `string` | `null` | no | 225 | | [flow\_log\_cloudwatch\_log\_group\_retention\_in\_days](#input\_flow\_log\_cloudwatch\_log\_group\_retention\_in\_days) | Specifies the number of days you want to retain log events in the specified log group for VPC flow logs. | `number` | `null` | no | 226 | | [flow\_log\_cloudwatch\_log\_group\_skip\_destroy](#input\_flow\_log\_cloudwatch\_log\_group\_skip\_destroy) | Set to true if you do not wish the log group (and any logs it may contain) to be deleted at destroy time, and instead just remove the log group from the Terraform state | `bool` | `false` | no | 227 | | [flow\_log\_enabled](#input\_flow\_log\_enabled) | Whether or not to enable VPC Flow Logs | `bool` | `false` | no | 228 | | [flow\_log\_max\_aggregation\_interval](#input\_flow\_log\_max\_aggregation\_interval) | The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. Valid Values: `60` seconds or `600` seconds. | `number` | `60` | no | 229 | | [intra\_subnet\_assign\_ipv6\_address\_on\_creation](#input\_intra\_subnet\_assign\_ipv6\_address\_on\_creation) | Assign IPv6 address on intra subnet, must be disabled to change IPv6 CIDRs. This is the IPv6 equivalent of map\_public\_ip\_on\_launch | `bool` | `null` | no | 230 | | [intra\_subnet\_cidrs](#input\_intra\_subnet\_cidrs) | A list of intra subnets CIDR to be created | `list(any)` | `[]` | no | 231 | | [intra\_subnet\_enabled](#input\_intra\_subnet\_enabled) | Set true to enable intra subnets | `bool` | `false` | no | 232 | | [ipam\_enabled](#input\_ipam\_enabled) | Whether enable IPAM managed VPC or not | `bool` | `false` | no | 233 | | [ipam\_pool\_id](#input\_ipam\_pool\_id) | The existing IPAM pool id if any | `string` | `null` | no | 234 | | [ipv4\_netmask\_length](#input\_ipv4\_netmask\_length) | The netmask length for IPAM managed VPC | `number` | `16` | no | 235 | | [ipv6\_enabled](#input\_ipv6\_enabled) | Requests an Amazon-provided IPv6 CIDR block with a /56 prefix length for the VPC. You cannot specify the range of IP addresses, or the size of the CIDR block. | `bool` | `false` | no | 236 | | [ipv6\_only](#input\_ipv6\_only) | Enable it for deploying native IPv6 network | `bool` | `false` | no | 237 | | [name](#input\_name) | Specify the name of the VPC | `string` | `""` | no | 238 | | [one\_nat\_gateway\_per\_az](#input\_one\_nat\_gateway\_per\_az) | Set to true if a NAT Gateway is required per availability zone for Private Subnet Tier | `bool` | `false` | no | 239 | | [private\_subnet\_assign\_ipv6\_address\_on\_creation](#input\_private\_subnet\_assign\_ipv6\_address\_on\_creation) | Assign IPv6 address on private subnet, must be disabled to change IPv6 CIDRs. This is the IPv6 equivalent of map\_public\_ip\_on\_launch | `bool` | `null` | no | 240 | | [private\_subnet\_cidrs](#input\_private\_subnet\_cidrs) | A list of private subnets CIDR to be created inside the VPC | `list(any)` | `[]` | no | 241 | | [private\_subnet\_enabled](#input\_private\_subnet\_enabled) | Set true to enable private subnets | `bool` | `false` | no | 242 | | [public\_subnet\_assign\_ipv6\_address\_on\_creation](#input\_public\_subnet\_assign\_ipv6\_address\_on\_creation) | Assign IPv6 address on public subnet, must be disabled to change IPv6 CIDRs. This is the IPv6 equivalent of map\_public\_ip\_on\_launch | `bool` | `null` | no | 243 | | [public\_subnet\_cidrs](#input\_public\_subnet\_cidrs) | A list of public subnets CIDR to be created inside the VPC | `list(any)` | `[]` | no | 244 | | [public\_subnet\_enabled](#input\_public\_subnet\_enabled) | Set true to enable public subnets | `bool` | `false` | no | 245 | | [region](#input\_region) | The AWS region name | `string` | `null` | no | 246 | | [secondary\_cidr\_blocks](#input\_secondary\_cidr\_blocks) | List of the secondary CIDR blocks which can be at most 5 | `list(string)` | `[]` | no | 247 | | [secondry\_cidr\_enabled](#input\_secondry\_cidr\_enabled) | Whether enable secondary CIDR with VPC | `bool` | `false` | no | 248 | | [vpc\_cidr](#input\_vpc\_cidr) | The CIDR block of the VPC | `string` | `"10.0.0.0/16"` | no | 249 | | [vpc\_ecr\_endpoint\_enabled](#input\_vpc\_ecr\_endpoint\_enabled) | Set to true if you want to enable vpc ecr endpoints | `bool` | `false` | no | 250 | | [vpc\_s3\_endpoint\_enabled](#input\_vpc\_s3\_endpoint\_enabled) | Set to true if you want to enable vpc S3 endpoints | `bool` | `false` | no | 251 | | [vpn\_key\_pair\_name](#input\_vpn\_key\_pair\_name) | Specify the name of AWS Keypair to be used for VPN Server | `string` | `""` | no | 252 | | [vpn\_server\_enabled](#input\_vpn\_server\_enabled) | Set to true if you want to deploy VPN Gateway resource and attach it to the VPC | `bool` | `false` | no | 253 | | [vpn\_server\_instance\_type](#input\_vpn\_server\_instance\_type) | EC2 instance Type for VPN Server, Only amd64 based instance type are supported eg. t2.medium, t3.micro, c5a.large etc. | `string` | `"t3a.small"` | no | 254 | 255 | ## Outputs 256 | 257 | | Name | Description | 258 | |------|-------------| 259 | | [database\_subnets](#output\_database\_subnets) | List of IDs of database subnets | 260 | | [intra\_subnets](#output\_intra\_subnets) | List of IDs of Intra subnets | 261 | | [ipv6\_vpc\_cidr\_block](#output\_ipv6\_vpc\_cidr\_block) | The IPv6 CIDR block | 262 | | [private\_subnets](#output\_private\_subnets) | List of IDs of private subnets | 263 | | [public\_subnets](#output\_public\_subnets) | List of IDs of public subnets | 264 | | [vpc\_cidr\_block](#output\_vpc\_cidr\_block) | IPV4 CIDR Block for this VPC | 265 | | [vpc\_id](#output\_vpc\_id) | The ID of the VPC | 266 | | [vpc\_ipv6\_association\_id](#output\_vpc\_ipv6\_association\_id) | The association ID for the IPv6 CIDR block | 267 | | [vpc\_secondary\_cidr\_blocks](#output\_vpc\_secondary\_cidr\_blocks) | List of secondary CIDR blocks of the VPC | 268 | | [vpn\_host\_public\_ip](#output\_vpn\_host\_public\_ip) | IP Address of VPN Server | 269 | | [vpn\_security\_group](#output\_vpn\_security\_group) | Security Group ID of VPN Server | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | ## 278 | 279 | 280 | 281 | 282 | 283 | - Please give our [GitHub repository](https://github.com/saturnops/terraform-aws-vpc) a ⭐️ to show your support and increase its visibility. 284 | 285 | 286 | 287 | 288 | 289 | -------------------------------------------------------------------------------- /compliance.md: -------------------------------------------------------------------------------- 1 | | No. | Item | Status | Notes | 2 | | ----: | ------------------------------------------------------------------------------------------------------------------ | :-----: | ------------------------------------------------------------------------------------------------------------------------------------- | 3 | | 5.4 | Ensure routing tables for VPC peering are "least access" | N/A | | 4 | -------------------------------------------------------------------------------- /examples/complete-vpc-with-vpn/README.md: -------------------------------------------------------------------------------- 1 | # Complete VPC with VPN 2 | 3 | This configuration is suitable for production environments 4 | 5 | NAT Gateways, public, database,intra and Private subnets will be created in each availability zone. Additionally by default, an EC2 instance which will act as a VPN server will be created. 6 | 7 | 8 | ## Usage 9 | 10 | To run this example you need to execute: 11 | 12 | ```bash 13 | $ terraform init 14 | $ terraform plan 15 | $ terraform apply 16 | ``` 17 | 18 | Note that this example may create resources which can cost money (AWS Elastic IP, for example). Run `terraform destroy` when you don't need these resources. 19 | 20 | 21 | 22 | ## Requirements 23 | 24 | No requirements. 25 | 26 | ## Providers 27 | 28 | | Name | Version | 29 | |------|---------| 30 | | [aws](#provider\_aws) | n/a | 31 | 32 | ## Modules 33 | 34 | | Name | Source | Version | 35 | |------|--------|---------| 36 | | [key\_pair\_vpn](#module\_key\_pair\_vpn) | saturnops/keypair/aws | n/a | 37 | | [kms](#module\_kms) | terraform-aws-modules/kms/aws | n/a | 38 | | [vpc](#module\_vpc) | ../../ | n/a | 39 | 40 | ## Resources 41 | 42 | | Name | Type | 43 | |------|------| 44 | | [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | 45 | 46 | ## Inputs 47 | 48 | No inputs. 49 | 50 | ## Outputs 51 | 52 | | Name | Description | 53 | |------|-------------| 54 | | [database\_subnets](#output\_database\_subnets) | List of IDs of database subnets | 55 | | [intra\_subnets](#output\_intra\_subnets) | List of IDs of Intra subnets | 56 | | [private\_subnets](#output\_private\_subnets) | List of IDs of private subnets | 57 | | [public\_subnets](#output\_public\_subnets) | List of IDs of public subnets | 58 | | [region](#output\_region) | AWS Region | 59 | | [vpc\_cidr\_block](#output\_vpc\_cidr\_block) | AWS Region | 60 | | [vpc\_id](#output\_vpc\_id) | The ID of the VPC | 61 | | [vpn\_host\_public\_ip](#output\_vpn\_host\_public\_ip) | IP Adress of VPN Server | 62 | | [vpn\_security\_group](#output\_vpn\_security\_group) | Security Group ID of VPN Server | 63 | 64 | -------------------------------------------------------------------------------- /examples/complete-vpc-with-vpn/main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | name = "vpc" 3 | region = "ap-south-1" 4 | environment = "prod" 5 | additional_aws_tags = { 6 | Owner = "Organization_Name" 7 | Expires = "Never" 8 | Department = "Engineering" 9 | } 10 | kms_user = null 11 | vpc_cidr = "10.10.0.0/16" 12 | current_identity = data.aws_caller_identity.current.arn 13 | } 14 | 15 | data "aws_caller_identity" "current" {} 16 | 17 | module "key_pair_vpn" { 18 | source = "saturnops/keypair/aws" 19 | key_name = format("%s-%s-vpn", local.environment, local.name) 20 | environment = local.environment 21 | ssm_parameter_path = format("%s-%s-vpn", local.environment, local.name) 22 | } 23 | 24 | module "kms" { 25 | source = "terraform-aws-modules/kms/aws" 26 | 27 | deletion_window_in_days = 7 28 | description = "Symetric Key to Enable Encryption at rest using KMS services." 29 | enable_key_rotation = false 30 | is_enabled = true 31 | key_usage = "ENCRYPT_DECRYPT" 32 | multi_region = false 33 | 34 | # Policy 35 | enable_default_policy = true 36 | key_owners = [local.current_identity] 37 | key_administrators = local.kms_user == null ? ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling", "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/aws-service-role/eks.amazonaws.com/AWSServiceRoleForAmazonEKS", local.current_identity] : local.kms_user 38 | key_users = local.kms_user == null ? ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling", "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/aws-service-role/eks.amazonaws.com/AWSServiceRoleForAmazonEKS", local.current_identity] : local.kms_user 39 | key_service_users = local.kms_user == null ? ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling", "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/aws-service-role/eks.amazonaws.com/AWSServiceRoleForAmazonEKS", local.current_identity] : local.kms_user 40 | key_symmetric_encryption_users = [local.current_identity] 41 | key_hmac_users = [local.current_identity] 42 | key_asymmetric_public_encryption_users = [local.current_identity] 43 | key_asymmetric_sign_verify_users = [local.current_identity] 44 | key_statements = [ 45 | { 46 | sid = "AllowCloudWatchLogsEncryption", 47 | effect = "Allow" 48 | actions = [ 49 | "kms:Encrypt*", 50 | "kms:Decrypt*", 51 | "kms:ReEncrypt*", 52 | "kms:GenerateDataKey*", 53 | "kms:Describe*" 54 | ] 55 | resources = ["*"] 56 | 57 | principals = [ 58 | { 59 | type = "Service" 60 | identifiers = ["logs.${local.region}.amazonaws.com"] 61 | } 62 | ] 63 | } 64 | ] 65 | # Aliases 66 | aliases = ["${local.name}-KMS"] 67 | aliases_use_name_prefix = true 68 | } 69 | 70 | 71 | module "vpc" { 72 | source = "saturnops/vpc/aws" 73 | name = local.name 74 | region = local.region 75 | vpc_cidr = local.vpc_cidr 76 | environment = local.environment 77 | flow_log_enabled = true 78 | vpn_key_pair_name = module.key_pair_vpn.key_pair_name 79 | availability_zones = ["ap-south-1a", "ap-south-1b"] 80 | vpn_server_enabled = true 81 | intra_subnet_enabled = true 82 | public_subnet_enabled = true 83 | auto_assign_public_ip = true 84 | private_subnet_enabled = true 85 | one_nat_gateway_per_az = true 86 | database_subnet_enabled = true 87 | vpn_server_instance_type = "t3a.small" 88 | vpc_s3_endpoint_enabled = true 89 | vpc_ecr_endpoint_enabled = true 90 | flow_log_max_aggregation_interval = 60 # In seconds 91 | flow_log_cloudwatch_log_group_skip_destroy = true 92 | flow_log_cloudwatch_log_group_retention_in_days = 90 93 | flow_log_cloudwatch_log_group_kms_key_arn = module.kms.key_arn #Enter your kms key arn 94 | } -------------------------------------------------------------------------------- /examples/complete-vpc-with-vpn/outputs.tf: -------------------------------------------------------------------------------- 1 | output "region" { 2 | description = "AWS Region" 3 | value = local.region 4 | } 5 | 6 | output "vpc_id" { 7 | description = "The ID of the VPC" 8 | value = module.vpc.vpc_id 9 | } 10 | 11 | output "vpc_cidr_block" { 12 | description = "AWS Region" 13 | value = module.vpc.vpc_cidr_block 14 | } 15 | 16 | output "public_subnets" { 17 | description = "List of IDs of public subnets" 18 | value = module.vpc.public_subnets 19 | } 20 | 21 | output "private_subnets" { 22 | description = "List of IDs of private subnets" 23 | value = module.vpc.private_subnets 24 | } 25 | 26 | output "database_subnets" { 27 | description = "List of IDs of database subnets" 28 | value = module.vpc.database_subnets 29 | } 30 | 31 | output "intra_subnets" { 32 | description = "List of IDs of Intra subnets" 33 | value = module.vpc.intra_subnets 34 | } 35 | 36 | output "vpn_host_public_ip" { 37 | description = "IP Adress of VPN Server" 38 | value = module.vpc.vpn_host_public_ip 39 | } 40 | 41 | output "vpn_security_group" { 42 | description = "Security Group ID of VPN Server" 43 | value = module.vpc.vpn_security_group 44 | } 45 | -------------------------------------------------------------------------------- /examples/complete-vpc-with-vpn/providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = local.region 3 | default_tags { 4 | tags = local.additional_aws_tags 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/ipam-managed-vpc/README.md: -------------------------------------------------------------------------------- 1 | # IPAM VPC 2 | 3 | Configuration in this directory creates set of VPC resources with IPAM managed CIDRs 4 | 5 | IPAM pool with desired CIDR and its allocation which restricts the overlapping of CIDRs 6 | 7 | [Read more about AWS regions, availability zones and local zones](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-regions-availability-zones). 8 | 9 | ## Usage 10 | 11 | To run this example you need to execute: 12 | 13 | ```bash 14 | $ terraform init 15 | $ terraform plan 16 | $ terraform apply 17 | ``` 18 | 19 | Note that this example may create resources which can cost money (AWS Elastic IP, for example). Run `terraform destroy` when you don't need these resources. 20 | 21 | 22 | ## Requirements 23 | 24 | No requirements. 25 | 26 | ## Providers 27 | 28 | No providers. 29 | 30 | ## Modules 31 | 32 | | Name | Source | Version | 33 | |------|--------|---------| 34 | | [vpc\_ipam](#module\_vpc\_ipam) | saturnops/vpc/aws | n/a | 35 | 36 | ## Resources 37 | 38 | No resources. 39 | 40 | ## Inputs 41 | 42 | No inputs. 43 | 44 | ## Outputs 45 | 46 | | Name | Description | 47 | |------|-------------| 48 | | [public\_subnets](#output\_public\_subnets) | List of IDs of public subnets | 49 | | [region](#output\_region) | AWS Region | 50 | | [vpc\_cidr\_block](#output\_vpc\_cidr\_block) | AWS Region | 51 | | [vpc\_id](#output\_vpc\_id) | The ID of the VPC | 52 | 53 | -------------------------------------------------------------------------------- /examples/ipam-managed-vpc/main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | region = "us-east-1" 3 | environment = "stage" 4 | name = "skaf" 5 | additional_aws_tags = { 6 | Owner = "SaturnOps" 7 | Expires = "Never" 8 | Department = "Engineering" 9 | } 10 | vpc_cidr = "10.10.0.0/16" 11 | ipam_enabled = true 12 | } 13 | 14 | module "vpc_ipam" { 15 | source = "saturnops/vpc/aws" 16 | 17 | name = local.name 18 | 19 | ipam_enabled = local.ipam_enabled 20 | region = local.region 21 | create_ipam_pool = true 22 | vpc_cidr = local.vpc_cidr 23 | availability_zones = ["us-east-1a", "us-east-1b"] 24 | 25 | private_subnet_enabled = true 26 | public_subnet_enabled = true 27 | } 28 | -------------------------------------------------------------------------------- /examples/ipam-managed-vpc/output.tf: -------------------------------------------------------------------------------- 1 | output "region" { 2 | description = "AWS Region" 3 | value = local.region 4 | } 5 | 6 | output "vpc_id" { 7 | description = "The ID of the VPC" 8 | value = module.vpc_ipam.vpc_id 9 | } 10 | 11 | output "vpc_cidr_block" { 12 | description = "AWS Region" 13 | value = module.vpc_ipam.vpc_cidr_block 14 | } 15 | 16 | output "public_subnets" { 17 | description = "List of IDs of public subnets" 18 | value = module.vpc_ipam.public_subnets 19 | } 20 | -------------------------------------------------------------------------------- /examples/ipam-managed-vpc/providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = local.region 3 | default_tags { 4 | tags = local.additional_aws_tags 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/simple-vpc/README.md: -------------------------------------------------------------------------------- 1 | # Simple VPC 2 | 3 | Configuration in this directory creates set of VPC resources which may be sufficient for development environment. 4 | 5 | There is a public subnet created per availability zone with Internet Gateway and route tables. 6 | 7 | [Read more about AWS regions, availability zones and local zones](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-regions-availability-zones). 8 | 9 | ## Usage 10 | 11 | To run this example you need to execute: 12 | 13 | ```bash 14 | $ terraform init 15 | $ terraform plan 16 | $ terraform apply 17 | ``` 18 | 19 | Note that this example may create resources which can cost money (AWS Elastic IP, for example). Run `terraform destroy` when you don't need these resources. 20 | 21 | 22 | ## Requirements 23 | 24 | No requirements. 25 | 26 | ## Providers 27 | 28 | No providers. 29 | 30 | ## Modules 31 | 32 | | Name | Source | Version | 33 | |------|--------|---------| 34 | | [vpc](#module\_vpc) | saturnops/vpc/aws | n/a | 35 | 36 | ## Resources 37 | 38 | No resources. 39 | 40 | ## Inputs 41 | 42 | No inputs. 43 | 44 | ## Outputs 45 | 46 | | Name | Description | 47 | |------|-------------| 48 | | [public\_subnets](#output\_public\_subnets) | List of IDs of public subnets | 49 | | [region](#output\_region) | AWS Region | 50 | | [vpc\_cidr\_block](#output\_vpc\_cidr\_block) | AWS Region | 51 | | [vpc\_id](#output\_vpc\_id) | The ID of the VPC | 52 | 53 | -------------------------------------------------------------------------------- /examples/simple-vpc/main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | region = "us-east-1" 3 | environment = "dev" 4 | name = "skaf" 5 | additional_aws_tags = { 6 | Owner = "SaturnOps" 7 | Expires = "Never" 8 | Department = "Engineering" 9 | } 10 | vpc_cidr = "10.10.0.0/16" 11 | } 12 | 13 | module "vpc" { 14 | source = "saturnops/vpc/aws" 15 | name = local.name 16 | vpc_cidr = local.vpc_cidr 17 | environment = local.environment 18 | availability_zones = ["us-east-1a", "us-east-1b"] 19 | public_subnet_enabled = true 20 | auto_assign_public_ip = true 21 | } 22 | -------------------------------------------------------------------------------- /examples/simple-vpc/output.tf: -------------------------------------------------------------------------------- 1 | output "region" { 2 | description = "AWS Region" 3 | value = local.region 4 | } 5 | 6 | output "vpc_id" { 7 | description = "The ID of the VPC" 8 | value = module.vpc.vpc_id 9 | } 10 | 11 | output "vpc_cidr_block" { 12 | description = "AWS Region" 13 | value = module.vpc.vpc_cidr_block 14 | } 15 | 16 | output "public_subnets" { 17 | description = "List of IDs of public subnets" 18 | value = module.vpc.public_subnets 19 | } 20 | -------------------------------------------------------------------------------- /examples/simple-vpc/providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = local.region 3 | default_tags { 4 | tags = local.additional_aws_tags 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/vpc-dualstack/README.md: -------------------------------------------------------------------------------- 1 | # VPC with IPv6 support 2 | 3 | 4 | VPC with dual stack IP mode enabled IPv6 and IPv4 includes public and private subnet will be created per availability zone in addition to single NAT Gateway shared between all availability zones. 5 | 6 | ## Usage 7 | 8 | To run this example you need to execute: 9 | 10 | ```bash 11 | $ terraform init 12 | $ terraform plan 13 | $ terraform apply 14 | ``` 15 | 16 | Note that this example may create resources which can cost money (AWS Elastic IP, for example). Run `terraform destroy` when you don't need these resources. 17 | 18 | 19 | 20 | ## Requirements 21 | 22 | No requirements. 23 | 24 | ## Providers 25 | 26 | No providers. 27 | 28 | ## Modules 29 | 30 | | Name | Source | Version | 31 | |------|--------|---------| 32 | | [vpc](#module\_vpc) | saturnops/vpc/aws | n/a | 33 | 34 | ## Resources 35 | 36 | No resources. 37 | 38 | ## Inputs 39 | 40 | No inputs. 41 | 42 | ## Outputs 43 | 44 | | Name | Description | 45 | |------|-------------| 46 | | [ipv6\_vpc\_cidr\_block](#output\_ipv6\_vpc\_cidr\_block) | The IPv6 CIDR block | 47 | | [private\_subnets](#output\_private\_subnets) | List of IDs of private subnets | 48 | | [public\_subnets](#output\_public\_subnets) | List of IDs of public subnets | 49 | | [region](#output\_region) | AWS Region | 50 | | [vpc\_cidr\_block](#output\_vpc\_cidr\_block) | The CIDR of the VPC | 51 | | [vpc\_id](#output\_vpc\_id) | The ID of the VPC | 52 | | [vpc\_ipv6\_association\_id](#output\_vpc\_ipv6\_association\_id) | The association ID for the IPv6 CIDR block | 53 | 54 | -------------------------------------------------------------------------------- /examples/vpc-dualstack/main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | name = "skaf" 3 | region = "us-east-1" 4 | environment = "stage" 5 | additional_aws_tags = { 6 | Owner = "SaturnOps" 7 | Expires = "Never" 8 | Department = "Engineering" 9 | } 10 | vpc_cidr = "10.10.0.0/16" 11 | ipv6_enabled = true 12 | } 13 | 14 | module "vpc" { 15 | source = "saturnops/vpc/aws" 16 | name = local.name 17 | vpc_cidr = local.vpc_cidr 18 | environment = local.environment 19 | availability_zones = ["us-east-1a", "us-east-1b"] 20 | public_subnet_enabled = true 21 | private_subnet_enabled = true 22 | intra_subnet_enabled = false 23 | database_subnet_enabled = false 24 | auto_assign_public_ip = true 25 | ipv6_enabled = local.ipv6_enabled 26 | public_subnet_assign_ipv6_address_on_creation = true 27 | private_subnet_assign_ipv6_address_on_creation = true 28 | database_subnet_assign_ipv6_address_on_creation = true 29 | intra_subnet_assign_ipv6_address_on_creation = true 30 | 31 | } 32 | -------------------------------------------------------------------------------- /examples/vpc-dualstack/outputs.tf: -------------------------------------------------------------------------------- 1 | output "region" { 2 | description = "AWS Region" 3 | value = local.region 4 | } 5 | 6 | output "vpc_id" { 7 | description = "The ID of the VPC" 8 | value = module.vpc.vpc_id 9 | } 10 | 11 | output "vpc_cidr_block" { 12 | description = "The CIDR of the VPC" 13 | value = module.vpc.vpc_cidr_block 14 | } 15 | 16 | output "public_subnets" { 17 | description = "List of IDs of public subnets" 18 | value = module.vpc.public_subnets 19 | } 20 | 21 | output "private_subnets" { 22 | description = "List of IDs of private subnets" 23 | value = module.vpc.private_subnets 24 | } 25 | 26 | 27 | output "vpc_ipv6_association_id" { 28 | description = "The association ID for the IPv6 CIDR block" 29 | value = module.vpc.vpc_ipv6_association_id 30 | } 31 | 32 | output "ipv6_vpc_cidr_block" { 33 | description = "The IPv6 CIDR block" 34 | value = module.vpc.ipv6_vpc_cidr_block 35 | } 36 | -------------------------------------------------------------------------------- /examples/vpc-dualstack/providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = local.region 3 | default_tags { 4 | tags = local.additional_aws_tags 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/vpc-native-ipv6/README.md: -------------------------------------------------------------------------------- 1 | # VPC with Native IPv6 support 2 | 3 | 4 | VPC with native IPv6 which includes public and private subnet will be created per availability zone in addition to single NAT Gateway shared between all availability zones. 5 | 6 | ## Usage 7 | 8 | To run this example you need to execute: 9 | 10 | ```bash 11 | $ terraform init 12 | $ terraform plan 13 | $ terraform apply 14 | ``` 15 | 16 | Note that this example may create resources which can cost money (AWS Elastic IP, for example). Run `terraform destroy` when you don't need these resources. 17 | 18 | 19 | 20 | ## Requirements 21 | 22 | No requirements. 23 | 24 | ## Providers 25 | 26 | No providers. 27 | 28 | ## Modules 29 | 30 | | Name | Source | Version | 31 | |------|--------|---------| 32 | | [vpc](#module\_vpc) | saturnops/vpc/aws | n/a | 33 | 34 | ## Resources 35 | 36 | No resources. 37 | 38 | ## Inputs 39 | 40 | No inputs. 41 | 42 | ## Outputs 43 | 44 | | Name | Description | 45 | |------|-------------| 46 | | [database\_subnets](#output\_database\_subnets) | List of IDs of database subnets | 47 | | [intra\_subnets](#output\_intra\_subnets) | List of IDs of Intra subnets | 48 | | [ipv6\_vpc\_cidr\_block](#output\_ipv6\_vpc\_cidr\_block) | The IPv6 CIDR block | 49 | | [private\_subnets](#output\_private\_subnets) | List of IDs of private subnets | 50 | | [public\_subnets](#output\_public\_subnets) | List of IDs of public subnets | 51 | | [region](#output\_region) | AWS Region | 52 | | [vpc\_cidr\_block](#output\_vpc\_cidr\_block) | The CIDR of the VPC | 53 | | [vpc\_id](#output\_vpc\_id) | The ID of the VPC | 54 | | [vpc\_ipv6\_association\_id](#output\_vpc\_ipv6\_association\_id) | The association ID for the IPv6 CIDR block | 55 | 56 | -------------------------------------------------------------------------------- /examples/vpc-native-ipv6/main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | name = "skaf" 3 | region = "us-east-1" 4 | environment = "stage" 5 | additional_aws_tags = { 6 | Owner = "SaturnOps" 7 | Expires = "Never" 8 | Department = "Engineering" 9 | } 10 | vpc_cidr = "10.10.0.0/16" 11 | ipv6_enabled = true 12 | ipv6_only = true 13 | } 14 | 15 | module "vpc" { 16 | source = "saturnops/vpc/aws" 17 | name = local.name 18 | vpc_cidr = local.vpc_cidr 19 | ipv6_only = local.ipv6_only 20 | environment = local.environment 21 | ipv6_enabled = local.ipv6_enabled 22 | availability_zones = ["us-east-1a", "us-east-1b"] 23 | public_subnet_enabled = true 24 | private_subnet_enabled = true 25 | intra_subnet_enabled = true 26 | database_subnet_enabled = true 27 | public_subnet_assign_ipv6_address_on_creation = true 28 | private_subnet_assign_ipv6_address_on_creation = true 29 | database_subnet_assign_ipv6_address_on_creation = true 30 | intra_subnet_assign_ipv6_address_on_creation = true 31 | } 32 | -------------------------------------------------------------------------------- /examples/vpc-native-ipv6/outputs.tf: -------------------------------------------------------------------------------- 1 | output "region" { 2 | description = "AWS Region" 3 | value = local.region 4 | } 5 | 6 | output "vpc_id" { 7 | description = "The ID of the VPC" 8 | value = module.vpc.vpc_id 9 | } 10 | 11 | output "vpc_cidr_block" { 12 | description = "The CIDR of the VPC" 13 | value = module.vpc.vpc_cidr_block 14 | } 15 | 16 | output "public_subnets" { 17 | description = "List of IDs of public subnets" 18 | value = module.vpc.public_subnets 19 | } 20 | 21 | output "private_subnets" { 22 | description = "List of IDs of private subnets" 23 | value = module.vpc.private_subnets 24 | } 25 | 26 | output "database_subnets" { 27 | description = "List of IDs of database subnets" 28 | value = module.vpc.database_subnets 29 | } 30 | 31 | output "intra_subnets" { 32 | description = "List of IDs of Intra subnets" 33 | value = module.vpc.intra_subnets 34 | } 35 | 36 | output "vpc_ipv6_association_id" { 37 | description = "The association ID for the IPv6 CIDR block" 38 | value = module.vpc.vpc_ipv6_association_id 39 | } 40 | 41 | output "ipv6_vpc_cidr_block" { 42 | description = "The IPv6 CIDR block" 43 | value = module.vpc.ipv6_vpc_cidr_block 44 | } 45 | -------------------------------------------------------------------------------- /examples/vpc-native-ipv6/providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = local.region 3 | default_tags { 4 | tags = local.additional_aws_tags 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/vpc-with-peering/README.md: -------------------------------------------------------------------------------- 1 | # VPC Peering 2 | 3 | Configuration in this directory creates a VPC peering connection between two VPCs. 4 | 5 | ## Usage 6 | 7 | To run this example you need to execute this module in two parts : 8 | 9 | 1. Execute the below command to deploy accepter and requester VPC: 10 | 11 | ```bash 12 | $ cd vpc-requester-accepter 13 | $ terraform init 14 | $ terraform plan 15 | $ terraform apply 16 | ``` 17 | 2. Copy the VPC id from the output and update in root (peering) main.tf locals block. 18 | 19 | 3. Execute the below command for peering of created VPC: 20 | 21 | ```bash 22 | $ terraform init 23 | $ terraform plan 24 | $ terraform apply 25 | ``` 26 | 27 | Note that this example may create resources which can cost money (AWS Elastic IP, for example). Run `terraform destroy` when you don't need these resources. 28 | 29 | 30 | 31 | ## Requirements 32 | 33 | No requirements. 34 | 35 | ## Providers 36 | 37 | No providers. 38 | 39 | ## Modules 40 | 41 | | Name | Source | Version | 42 | |------|--------|---------| 43 | | [vpc\_peering](#module\_vpc\_peering) | saturnops/vpc/aws//modules/vpc_peering | n/a | 44 | 45 | ## Resources 46 | 47 | No resources. 48 | 49 | ## Inputs 50 | 51 | No inputs. 52 | 53 | ## Outputs 54 | 55 | | Name | Description | 56 | |------|-------------| 57 | | [vpc\_peering\_accept\_status](#output\_vpc\_peering\_accept\_status) | Accept status for the connection | 58 | | [vpc\_peering\_connection\_id](#output\_vpc\_peering\_connection\_id) | Peering connection ID | 59 | 60 | -------------------------------------------------------------------------------- /examples/vpc-with-peering/main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | accepter_name = "tenent-peering" 3 | accepter_region = "us-east-2" 4 | accepter_vpc_id = "vpc-049f2peerb195d692" 5 | requester_name = "management-peering" 6 | requester_region = "us-east-2" 7 | requester_vpc_id = "vpc-0125epeere8cfb616" 8 | additional_tags = { 9 | Owner = "tenent" 10 | Tenancy = "dedicated" 11 | } 12 | } 13 | 14 | module "vpc_peering" { 15 | source = "saturnops/vpc/aws//modules/vpc_peering" 16 | accepter_name = local.accepter_name 17 | accepter_vpc_id = local.accepter_vpc_id 18 | accepter_vpc_region = local.accepter_region 19 | requester_name = local.requester_name 20 | requester_vpc_id = local.requester_vpc_id 21 | requester_vpc_region = local.requester_region 22 | } 23 | -------------------------------------------------------------------------------- /examples/vpc-with-peering/output.tf: -------------------------------------------------------------------------------- 1 | output "vpc_peering_connection_id" { 2 | description = "Peering connection ID" 3 | value = module.vpc_peering.vpc_peering_connection_id 4 | } 5 | 6 | output "vpc_peering_accept_status" { 7 | description = "Accept status for the connection" 8 | value = module.vpc_peering.vpc_peering_accept_status 9 | } 10 | -------------------------------------------------------------------------------- /examples/vpc-with-peering/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = local.region 3 | default_tags { 4 | tags = local.additional_tags 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/vpc-with-peering/vpc-requester-accepter/main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | region = "us-east-2" 3 | additional_aws_tags = { 4 | Owner = "SaturnOps" 5 | Expires = "Never" 6 | Department = "Engineering" 7 | } 8 | } 9 | 10 | module "vpc_accepter" { 11 | source = "saturnops/vpc/aws" 12 | name = "accepter" 13 | vpc_cidr = "10.10.0.0/16" 14 | environment = "dev" 15 | availability_zones = 2 16 | public_subnet_enabled = true 17 | } 18 | 19 | module "vpc_requester" { 20 | source = "saturnops/vpc/aws" 21 | name = "requester" 22 | vpc_cidr = "172.10.0.0/16" 23 | environment = "uat" 24 | availability_zones = 2 25 | public_subnet_enabled = true 26 | } 27 | 28 | output "vpc_id_accepter" { 29 | description = "The ID of the accepter VPC" 30 | value = module.vpc_accepter.vpc_id 31 | } 32 | 33 | output "vpc_id_requester" { 34 | description = "The ID of the requester VPC" 35 | value = module.vpc_requester.vpc_id 36 | } 37 | -------------------------------------------------------------------------------- /examples/vpc-with-peering/vpc-requester-accepter/providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = local.region 3 | default_tags { 4 | tags = local.additional_aws_tags 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/vpc-with-private-subnet/README.md: -------------------------------------------------------------------------------- 1 | # VPC with Private Subnets 2 | 3 | 4 | A public and private subnet will be created per availability zone in addition to single NAT Gateway shared between all availability zones. 5 | 6 | ## Usage 7 | 8 | To run this example you need to execute: 9 | 10 | ```bash 11 | $ terraform init 12 | $ terraform plan 13 | $ terraform apply 14 | ``` 15 | 16 | Note that this example may create resources which can cost money (AWS Elastic IP, for example). Run `terraform destroy` when you don't need these resources. 17 | 18 | 19 | 20 | ## Requirements 21 | 22 | No requirements. 23 | 24 | ## Providers 25 | 26 | No providers. 27 | 28 | ## Modules 29 | 30 | | Name | Source | Version | 31 | |------|--------|---------| 32 | | [vpc](#module\_vpc) | saturnops/vpc/aws | n/a | 33 | 34 | ## Resources 35 | 36 | No resources. 37 | 38 | ## Inputs 39 | 40 | No inputs. 41 | 42 | ## Outputs 43 | 44 | | Name | Description | 45 | |------|-------------| 46 | | [private\_subnets](#output\_private\_subnets) | List of IDs of private subnets | 47 | | [public\_subnets](#output\_public\_subnets) | List of IDs of public subnets | 48 | | [region](#output\_region) | AWS Region | 49 | | [vpc\_cidr\_block](#output\_vpc\_cidr\_block) | AWS Region | 50 | | [vpc\_id](#output\_vpc\_id) | The ID of the VPC | 51 | 52 | -------------------------------------------------------------------------------- /examples/vpc-with-private-subnet/main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | name = "skaf" 3 | region = "us-east-1" 4 | environment = "stage" 5 | additional_aws_tags = { 6 | Owner = "SaturnOps" 7 | Expires = "Never" 8 | Department = "Engineering" 9 | } 10 | vpc_cidr = "10.10.0.0/16" 11 | } 12 | 13 | module "vpc" { 14 | source = "saturnops/vpc/aws" 15 | name = local.name 16 | vpc_cidr = local.vpc_cidr 17 | environment = local.environment 18 | availability_zones = ["us-east-1a", "us-east-1b"] 19 | public_subnet_enabled = true 20 | private_subnet_enabled = true 21 | auto_assign_public_ip = true 22 | 23 | } 24 | -------------------------------------------------------------------------------- /examples/vpc-with-private-subnet/outputs.tf: -------------------------------------------------------------------------------- 1 | output "region" { 2 | description = "AWS Region" 3 | value = local.region 4 | } 5 | 6 | output "vpc_id" { 7 | description = "The ID of the VPC" 8 | value = module.vpc.vpc_id 9 | } 10 | 11 | output "vpc_cidr_block" { 12 | description = "AWS Region" 13 | value = module.vpc.vpc_cidr_block 14 | } 15 | 16 | output "public_subnets" { 17 | description = "List of IDs of public subnets" 18 | value = module.vpc.public_subnets 19 | } 20 | 21 | output "private_subnets" { 22 | description = "List of IDs of private subnets" 23 | value = module.vpc.private_subnets 24 | } 25 | -------------------------------------------------------------------------------- /examples/vpc-with-private-subnet/providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = local.region 3 | default_tags { 4 | tags = local.additional_aws_tags 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/vpc-with-secondary-cidr/README.md: -------------------------------------------------------------------------------- 1 | # VPC with Multiple CIDR Supports 2 | 3 | 4 | MUltiple CIDRs can be attached with a VPC in addition of increasing numbers of IPs. A public and private subnet will be created per availability zone in addition to single NAT Gateway shared between all availability zones. 5 | 6 | ## Usage 7 | 8 | To run this example you need to execute: 9 | 10 | ```bash 11 | $ terraform init 12 | $ terraform plan 13 | $ terraform apply 14 | ``` 15 | 16 | Note that this example may create resources which can cost money (AWS Elastic IP, for example). Run `terraform destroy` when you don't need these resources. 17 | 18 | 19 | 20 | ## Requirements 21 | 22 | No requirements. 23 | 24 | ## Providers 25 | 26 | No providers. 27 | 28 | ## Modules 29 | 30 | | Name | Source | Version | 31 | |------|--------|---------| 32 | | [vpc](#module\_vpc) | saturnops/vpc/aws | n/a | 33 | 34 | ## Resources 35 | 36 | No resources. 37 | 38 | ## Inputs 39 | 40 | No inputs. 41 | 42 | ## Outputs 43 | 44 | | Name | Description | 45 | |------|-------------| 46 | | [private\_subnets](#output\_private\_subnets) | List of IDs of private subnets | 47 | | [public\_subnets](#output\_public\_subnets) | List of IDs of public subnets | 48 | | [region](#output\_region) | AWS Region | 49 | | [vpc\_cidr\_block](#output\_vpc\_cidr\_block) | AWS Region | 50 | | [vpc\_id](#output\_vpc\_id) | The ID of the VPC | 51 | | [vpc\_secondary\_cidr\_blocks](#output\_vpc\_secondary\_cidr\_blocks) | List of secondary CIDR blocks of the VPC | 52 | 53 | -------------------------------------------------------------------------------- /examples/vpc-with-secondary-cidr/main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | name = "skaf" 3 | region = "us-east-1" 4 | environment = "stage" 5 | additional_aws_tags = { 6 | Owner = "SaturnOps" 7 | Expires = "Never" 8 | Department = "Engineering" 9 | } 10 | vpc_cidr = "10.10.0.0/16" 11 | secondry_cidr_enabled = true 12 | secondary_cidr_blocks = ["10.20.0.0/16"] 13 | } 14 | 15 | module "vpc" { 16 | source = "saturnops/vpc/aws" 17 | name = local.name 18 | vpc_cidr = local.vpc_cidr 19 | environment = local.environment 20 | availability_zones = ["us-east-1a", "us-east-1b"] 21 | public_subnet_enabled = true 22 | private_subnet_enabled = true 23 | auto_assign_public_ip = true 24 | intra_subnet_enabled = true 25 | database_subnet_enabled = true 26 | secondry_cidr_enabled = local.secondry_cidr_enabled 27 | secondary_cidr_blocks = local.secondary_cidr_blocks 28 | } 29 | -------------------------------------------------------------------------------- /examples/vpc-with-secondary-cidr/outputs.tf: -------------------------------------------------------------------------------- 1 | output "region" { 2 | description = "AWS Region" 3 | value = local.region 4 | } 5 | 6 | output "vpc_id" { 7 | description = "The ID of the VPC" 8 | value = module.vpc.vpc_id 9 | } 10 | 11 | output "vpc_cidr_block" { 12 | description = "AWS Region" 13 | value = module.vpc.vpc_cidr_block 14 | } 15 | 16 | output "public_subnets" { 17 | description = "List of IDs of public subnets" 18 | value = module.vpc.public_subnets 19 | } 20 | 21 | output "private_subnets" { 22 | description = "List of IDs of private subnets" 23 | value = module.vpc.private_subnets 24 | } 25 | 26 | output "vpc_secondary_cidr_blocks" { 27 | description = "List of secondary CIDR blocks of the VPC" 28 | value = module.vpc.vpc_secondary_cidr_blocks 29 | } 30 | -------------------------------------------------------------------------------- /examples/vpc-with-secondary-cidr/providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = local.region 3 | default_tags { 4 | tags = local.additional_aws_tags 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | azs = length(var.availability_zones) 3 | public_subnets_native = var.public_subnet_enabled ? length(var.public_subnet_cidrs) > 0 ? var.public_subnet_cidrs : [for netnum in range(0, local.azs) : cidrsubnet(var.vpc_cidr, 8, netnum)] : [] 4 | secondary_public_subnets = var.public_subnet_enabled && var.secondry_cidr_enabled ? [ 5 | for cidr_block in var.secondary_cidr_blocks : [ 6 | for netnum in range(0, local.azs) : cidrsubnet(cidr_block, 8, netnum) 7 | ] 8 | ] : [] 9 | public_subnets = concat(local.public_subnets_native, flatten(local.secondary_public_subnets)) 10 | intra_subnets_native = var.intra_subnet_enabled ? length(var.intra_subnet_cidrs) > 0 ? var.intra_subnet_cidrs : [for netnum in range(local.azs * 3, local.azs * 4) : cidrsubnet(var.vpc_cidr, 8, netnum)] : [] 11 | secondary_intra_subnets = var.intra_subnet_enabled && var.secondry_cidr_enabled ? [ 12 | for cidr_block in var.secondary_cidr_blocks : [ 13 | for netnum in range(local.azs * 3, local.azs * 4) : cidrsubnet(cidr_block, 8, netnum) 14 | ] 15 | ] : [] 16 | intra_subnets = concat(local.intra_subnets_native, flatten(local.secondary_intra_subnets)) 17 | private_subnets_native = var.private_subnet_enabled ? length(var.private_subnet_cidrs) > 0 ? var.private_subnet_cidrs : [for netnum in range(local.azs, local.azs * 2) : cidrsubnet(var.vpc_cidr, 4, netnum)] : [] 18 | secondary_private_subnets = var.private_subnet_enabled && var.secondry_cidr_enabled ? [ 19 | for cidr_block in var.secondary_cidr_blocks : [ 20 | for netnum in range(local.azs, local.azs * 2) : cidrsubnet(cidr_block, 4, netnum) 21 | ] 22 | ] : [] 23 | private_subnets = concat(local.private_subnets_native, flatten(local.secondary_private_subnets)) 24 | database_subnets_native = var.database_subnet_enabled ? length(var.database_subnet_cidrs) > 0 ? var.database_subnet_cidrs : [for netnum in range(local.azs * 2, local.azs * 3) : cidrsubnet(var.vpc_cidr, 8, netnum)] : [] 25 | secondary_database_subnets = var.database_subnet_enabled && var.secondry_cidr_enabled ? [ 26 | for cidr_block in var.secondary_cidr_blocks : [ 27 | for netnum in range(local.azs * 2, local.azs * 3) : cidrsubnet(cidr_block, 8, netnum) 28 | ] 29 | ] : [] 30 | database_subnets = concat(local.database_subnets_native, flatten(local.secondary_database_subnets)) 31 | single_nat_gateway = var.one_nat_gateway_per_az == true ? false : true 32 | create_database_subnet_route_table = var.database_subnet_enabled 33 | create_flow_log_cloudwatch_log_group = var.flow_log_enabled == true || var.flow_log_cloudwatch_log_group_skip_destroy == true ? true : false 34 | is_supported_arch = data.aws_ec2_instance_type.arch.supported_architectures[0] == "arm64" ? false : true # for VPN Instance 35 | nacl_allow_vpc_access_rule = [{ 36 | rule_no = 97 37 | action = "allow" 38 | from_port = 0 39 | to_port = 0 40 | protocol = "-1" 41 | cidr_block = var.vpc_cidr 42 | } 43 | 44 | ] 45 | enable_ipv6 = var.ipv6_enabled 46 | ipv6_only = var.ipv6_enabled && var.ipv6_only ? true : false 47 | public_subnet_assign_ipv6_address_on_creation = var.public_subnet_assign_ipv6_address_on_creation == true && var.ipv6_enabled == true ? true : false 48 | private_subnet_assign_ipv6_address_on_creation = var.private_subnet_assign_ipv6_address_on_creation == true && var.ipv6_enabled == true ? true : false 49 | database_subnet_assign_ipv6_address_on_creation = var.database_subnet_assign_ipv6_address_on_creation == true && var.ipv6_enabled == true ? true : false 50 | intra_subnet_assign_ipv6_address_on_creation = var.intra_subnet_assign_ipv6_address_on_creation == true && var.ipv6_enabled == true ? true : false 51 | 52 | public_subnet_ipv6_prefixes = var.public_subnet_enabled ? [for i in range(local.azs) : i] : [] 53 | private_subnet_ipv6_prefixes = var.private_subnet_enabled ? [for i in range(local.azs) : i + length(data.aws_availability_zones.available.names)] : [] 54 | database_subnet_ipv6_prefixes = var.database_subnet_enabled ? [for i in range(local.azs) : i + 2 * length(data.aws_availability_zones.available.names)] : [] 55 | intra_subnet_ipv6_prefixes = var.intra_subnet_enabled ? [for i in range(local.azs) : i + 3 * length(data.aws_availability_zones.available.names)] : [] 56 | } 57 | data "aws_availability_zones" "available" {} 58 | data "aws_ec2_instance_type" "arch" { 59 | instance_type = var.vpn_server_instance_type 60 | } 61 | 62 | module "vpc" { 63 | source = "terraform-aws-modules/vpc/aws" 64 | version = "5.2.0" 65 | name = format("%s-%s-vpc", var.environment, var.name) 66 | cidr = var.vpc_cidr # CIDR FOR VPC 67 | azs = var.availability_zones 68 | use_ipam_pool = var.ipam_enabled ? true : false 69 | ipv4_ipam_pool_id = var.ipam_enabled && var.create_ipam_pool ? aws_vpc_ipam_pool.ipam_pool[0].id : null 70 | ipv4_netmask_length = var.ipam_enabled ? var.ipv4_netmask_length : null 71 | create_database_subnet_group = length(local.database_subnets) > 1 && var.enable_database_subnet_group ? true : false 72 | intra_subnets = local.intra_subnets 73 | public_subnets = local.public_subnets 74 | private_subnets = local.private_subnets 75 | database_subnets = local.database_subnets 76 | enable_flow_log = var.flow_log_enabled 77 | enable_nat_gateway = length(local.private_subnets) > 0 && !var.ipv6_only ? true : false 78 | single_nat_gateway = local.single_nat_gateway 79 | enable_vpn_gateway = false 80 | enable_dns_hostnames = true 81 | flow_log_traffic_type = "ALL" 82 | secondary_cidr_blocks = var.secondry_cidr_enabled ? var.secondary_cidr_blocks : [] 83 | one_nat_gateway_per_az = var.one_nat_gateway_per_az 84 | map_public_ip_on_launch = var.auto_assign_public_ip 85 | flow_log_destination_type = "cloud-watch-logs" 86 | manage_default_network_acl = true 87 | default_network_acl_ingress = concat(local.nacl_allow_vpc_access_rule, var.default_network_acl_ingress) 88 | manage_default_security_group = true 89 | default_security_group_ingress = [] # Enforcing no rules being present in the default security group. 90 | default_security_group_egress = [] 91 | create_database_nat_gateway_route = false 92 | create_database_subnet_route_table = local.create_database_subnet_route_table 93 | create_flow_log_cloudwatch_iam_role = var.flow_log_enabled 94 | create_flow_log_cloudwatch_log_group = local.create_flow_log_cloudwatch_log_group 95 | flow_log_max_aggregation_interval = var.flow_log_max_aggregation_interval 96 | flow_log_cloudwatch_log_group_skip_destroy = var.flow_log_cloudwatch_log_group_skip_destroy 97 | flow_log_cloudwatch_log_group_retention_in_days = var.flow_log_cloudwatch_log_group_retention_in_days 98 | flow_log_cloudwatch_log_group_kms_key_id = var.flow_log_cloudwatch_log_group_kms_key_arn 99 | enable_ipv6 = local.enable_ipv6 100 | public_subnet_ipv6_native = local.ipv6_only 101 | private_subnet_ipv6_native = local.ipv6_only 102 | database_subnet_ipv6_native = local.ipv6_only 103 | intra_subnet_ipv6_native = local.ipv6_only 104 | #assign_ipv6_address_on_creation = local.assign_ipv6_address_on_creation 105 | public_subnet_assign_ipv6_address_on_creation = local.public_subnet_assign_ipv6_address_on_creation 106 | private_subnet_assign_ipv6_address_on_creation = local.private_subnet_assign_ipv6_address_on_creation 107 | database_subnet_assign_ipv6_address_on_creation = local.database_subnet_assign_ipv6_address_on_creation 108 | intra_subnet_assign_ipv6_address_on_creation = local.intra_subnet_assign_ipv6_address_on_creation 109 | public_subnet_ipv6_prefixes = local.public_subnet_ipv6_prefixes 110 | private_subnet_ipv6_prefixes = local.private_subnet_ipv6_prefixes 111 | database_subnet_ipv6_prefixes = local.database_subnet_ipv6_prefixes 112 | intra_subnet_ipv6_prefixes = local.intra_subnet_ipv6_prefixes 113 | 114 | 115 | # TAGS TO BE ASSOCIATED WITH EACH RESOURCE 116 | 117 | tags = tomap( 118 | { 119 | "Name" = format("%s-%s-vpc", var.environment, var.name) 120 | "Environment" = var.environment 121 | }, 122 | ) 123 | 124 | public_subnet_tags = tomap({ 125 | "Name" = "${var.environment}-${var.name}-public-subnet" 126 | "Subnet-group" = "public" 127 | "kubernetes.io/role/elb" = 1 128 | }) 129 | 130 | public_route_table_tags = tomap({ 131 | "Name" = "${var.environment}-${var.name}-public-route-table" 132 | }) 133 | 134 | private_subnet_tags = tomap({ 135 | "Name" = "${var.environment}-${var.name}-private-subnet" 136 | "Subnet-group" = "private" 137 | "kubernetes.io/role/internal-elb" = 1 138 | }) 139 | 140 | private_subnet_tags_per_az = { for az in var.availability_zones : az => { 141 | "Karpenter" = "${az}" 142 | } } 143 | 144 | private_route_table_tags = tomap({ 145 | "Name" = "${var.environment}-${var.name}-private-route-table" 146 | }) 147 | 148 | database_subnet_tags = tomap({ 149 | "Name" = "${var.environment}-${var.name}-database-subnet" 150 | "Subnet-group" = "database" 151 | }) 152 | 153 | database_route_table_tags = tomap({ 154 | "Name" = "${var.environment}-${var.name}-database-route-table" 155 | }) 156 | 157 | intra_subnet_tags = tomap({ 158 | "Name" = "${var.environment}-${var.name}-intra-subnet" 159 | "Subnet-group" = "intra" 160 | }) 161 | 162 | intra_route_table_tags = tomap({ 163 | "Name" = "${var.environment}-${var.name}-intra-route-table" 164 | }) 165 | 166 | igw_tags = tomap({ 167 | "Name" = "${var.environment}-${var.name}-igw" 168 | }) 169 | 170 | nat_gateway_tags = tomap({ 171 | "Name" = "${var.environment}-${var.name}-nat" 172 | }) 173 | 174 | default_network_acl_name = format("%s-%s-nacl", var.environment, var.name) 175 | default_network_acl_tags = { 176 | "Name" = format("%s-%s-nacl", var.environment, var.name) 177 | "Environment" = var.environment 178 | } 179 | } 180 | 181 | module "vpn_server" { 182 | count = var.vpn_server_enabled && local.is_supported_arch ? 1 : 0 183 | depends_on = [module.vpc] 184 | source = "./modules/vpn" 185 | name = var.name 186 | vpc_id = module.vpc.vpc_id 187 | vpc_cidr = var.vpc_cidr 188 | environment = var.environment 189 | vpn_key_pair = var.vpn_key_pair_name 190 | public_subnet = module.vpc.public_subnets[0] 191 | vpn_server_instance_type = var.vpn_server_instance_type 192 | } 193 | 194 | resource "aws_vpc_ipam" "ipam" { 195 | count = var.ipam_enabled && var.create_ipam_pool ? 1 : 0 196 | operating_regions { 197 | region_name = var.region 198 | } 199 | 200 | 201 | } 202 | 203 | # IPv4 204 | resource "aws_vpc_ipam_pool" "ipam_pool" { 205 | count = var.ipam_enabled && var.create_ipam_pool ? 1 : 0 206 | description = "IPv4 pool" 207 | address_family = "ipv4" 208 | ipam_scope_id = aws_vpc_ipam.ipam[0].private_default_scope_id 209 | locale = var.region 210 | allocation_default_netmask_length = 16 211 | 212 | 213 | } 214 | 215 | resource "aws_vpc_ipam_pool_cidr" "ipam_pool_cidr" { 216 | count = var.ipam_enabled ? 1 : 0 217 | ipam_pool_id = var.create_ipam_pool ? aws_vpc_ipam_pool.ipam_pool[0].id : var.ipam_pool_id 218 | cidr = var.create_ipam_pool ? var.vpc_cidr : var.existing_ipam_managed_cidr 219 | } 220 | 221 | # private links for S3 222 | 223 | data "aws_route_tables" "aws_private_routes" { 224 | count = var.vpc_s3_endpoint_enabled ? 1 : 0 225 | depends_on = [module.vpc] 226 | vpc_id = module.vpc.vpc_id 227 | tags = { 228 | Name = "${var.environment}-${var.name}-private-route-table" 229 | } 230 | } 231 | 232 | resource "aws_vpc_endpoint" "private-s3" { 233 | count = var.vpc_s3_endpoint_enabled ? 1 : 0 234 | depends_on = [data.aws_route_tables.aws_private_routes] 235 | vpc_id = module.vpc.vpc_id 236 | service_name = "com.amazonaws.${var.region}.s3" 237 | route_table_ids = data.aws_route_tables.aws_private_routes[0].ids 238 | vpc_endpoint_type = "Gateway" 239 | policy = <
{
"action": "deny",
"cidr_block": "0.0.0.0/0",
"from_port": 22,
"protocol": "tcp",
"rule_no": 98,
"to_port": 22
},
{
"action": "deny",
"cidr_block": "0.0.0.0/0",
"from_port": 3389,
"protocol": "tcp",
"rule_no": 99,
"to_port": 3389
},
{
"action": "allow",
"cidr_block": "0.0.0.0/0",
"from_port": 0,
"protocol": "-1",
"rule_no": 100,
"to_port": 0
},
{
"action": "allow",
"from_port": 0,
"ipv6_cidr_block": "::/0",
"protocol": "-1",
"rule_no": 101,
"to_port": 0
}
]