├── .gitignore ├── LICENSE ├── README.md ├── k3s ├── aws │ ├── charts │ │ ├── 0 │ │ │ ├── .gitkeep │ │ │ ├── aws-cloud-provider-manifests.yaml │ │ │ └── namespaces.yaml │ │ ├── 1 │ │ │ └── .gitkeep │ │ ├── 2 │ │ │ ├── .gitkeep │ │ │ └── argocd.yaml │ │ ├── 3 │ │ │ └── .gitkeep │ │ ├── 4 │ │ │ └── .gitkeep │ │ └── 5 │ │ │ └── .gitkeep │ ├── db.tf │ ├── instances.tf │ ├── manifests.tf │ ├── networking.tf │ ├── outputs.tf │ ├── templates │ │ ├── agent_userdata.sh │ │ └── server_userdata.sh │ └── variables.tf ├── backends │ └── s3.tfvars ├── example.tfvars ├── main.tf └── variables.tf └── manifests ├── argocd-manifests.yaml └── aws-cloud-provider-manifests.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | .terraform/ 2 | terraform.tfstate 3 | terraform.tfstate.backup 4 | .idea/ 5 | *.iml -------------------------------------------------------------------------------- /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 2020 Adam Toy 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 K8S Terraform 2 | 3 | This is a project containing Terraform IaC to get a scalable Kubernetes cluster up and running in AWS with ArgoCD deployed to it. 4 | 5 | ### Prerequisites 6 | 7 | * Terraform CLI 8 | * An AWS account with Admin Permissions 9 | * Your AWS credentials configured via Environment Variables or `~/.aws/credentials` file. 10 | * Kubectl CLI 11 | 12 | ### How Do I Work It? 13 | 14 | Right now, we only support a K3S deployment model using RDS as a backend store. Eventually we'll expand to EKS. 15 | 16 | 1. Navigate to the `k3s` directory: 17 | ```bash 18 | cd k3s 19 | ``` 20 | 21 | 2. Create an S3 bucket in the AWS console to persist Terraform state. This gives you a highly reliable way to maintain your state file. 22 | 23 | 3. Update the `bucket` entry in both `backends/s3.tfvars` and `main.tf` files with the name of you bucket from the previous step. 24 | 25 | 4. (Optional) If you want to maintain multiple Terraform states, you can create/select separate workspaces. This will create separate files within your S3 bucket, so you can maintain multiple environments at once: 26 | ```bash 27 | # Create a new workspace 28 | terraform workspace new staging 29 | 30 | # Or select and switch to an existing workspace 31 | terraform workspace select staging 32 | ``` 33 | 34 | 5. Update the `example.tfvars`: 35 | * _db_username_: The master username for the RDS cluster. 36 | * _db_password_: The master password for the RDS cluster (you should actually not store this in a file and enter it when you apply your Terraform, but leaving it here for simplicity's sake.) 37 | * _public_ssh_key_: Set this to the public SSH key you're going to use to SSH to boxes. It is usually in `~/.ssh/id_rsa.pub` on your system. 38 | * _keypair_name_: The name of the keypair to store your public SSH key. 39 | * _key_s3_bucket_name_: The S3 bucket to store the K3S kubeconfig file. (**NOTE**: This needs to be GLOBALLY UNIQUE across AWS.) 40 | 41 | 6. Initialize Terraform with the S3 backend: 42 | ```bash 43 | terraform init -backend-config=backends/s3.tfvars 44 | ``` 45 | 46 | 7. Apply terraform (you'll need to type 'yes'): 47 | ```bash 48 | terraform apply -var-file=example.tfvars 49 | ``` 50 | 51 | 8. Wait until Terraform successfully deploys your cluster + a few minutes, then run the following to get your Kubeconfig file from S3: 52 | ```bash 53 | aws s3 cp s3://YOUR_BUCKET_NAME/k3s.yaml ~/.kube/config 54 | ``` 55 | 56 | 9. You should now be able to interact with your cluster via: 57 | ```bash 58 | kubectl get nodes 59 | ``` 60 | You should see 6 healthy nodes running (unless you've otherwised specified agent/server counts). 61 | 62 | 10. Lastly, let's check to make sure your ArgoCD pods are running: 63 | ```bash 64 | kubectl get deployments -n kube-system | grep argocd 65 | ``` 66 | You should see all ArgoCD deployments as `1/1`. 67 | 68 | ### Destroying your cluster 69 | 70 | To destroy a cluster, you need to first go to your AWS console, the EC2 service, and click on Load Balancers. There will be an ELB that the Kubernetes cloud provider created but isn't managed by Terraform that you need to clean up. You also need to delete the Security Group that that ELB is using. 71 | 72 | After you've cleaned the ELB up, run the following and type "yes" when prompted: 73 | ```bash 74 | terraform destroy -var-file=example.tfvars 75 | ``` 76 | 77 | ### What Next? 78 | 79 | If you're looking to really get into GitOps via ArgoCD, check out the [demo-app](https://github.com/atoy3731/k8s-tools-app) for adding a ton of cool tools to this cluster. 80 | -------------------------------------------------------------------------------- /k3s/aws/charts/0/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atoy3731/aws-k8s-terraform/7f8794eab48964c63508f46b031ace493fd93aa1/k3s/aws/charts/0/.gitkeep -------------------------------------------------------------------------------- /k3s/aws/charts/0/aws-cloud-provider-manifests.yaml: -------------------------------------------------------------------------------- 1 | https://raw.githubusercontent.com/atoy3731/aws-k8s-terraform/master/manifests/aws-cloud-provider-manifests.yaml -------------------------------------------------------------------------------- /k3s/aws/charts/0/namespaces.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: ingress-nginx 5 | labels: 6 | app: ingress-nginx 7 | --- 8 | apiVersion: v1 9 | kind: Namespace 10 | metadata: 11 | name: argocd 12 | labels: 13 | app: argocd -------------------------------------------------------------------------------- /k3s/aws/charts/1/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atoy3731/aws-k8s-terraform/7f8794eab48964c63508f46b031ace493fd93aa1/k3s/aws/charts/1/.gitkeep -------------------------------------------------------------------------------- /k3s/aws/charts/2/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atoy3731/aws-k8s-terraform/7f8794eab48964c63508f46b031ace493fd93aa1/k3s/aws/charts/2/.gitkeep -------------------------------------------------------------------------------- /k3s/aws/charts/2/argocd.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: helm.cattle.io/v1 2 | kind: HelmChart 3 | metadata: 4 | name: argocd 5 | namespace: kube-system 6 | spec: 7 | chart: argo-cd 8 | repo: https://argoproj.github.io/argo-helm 9 | targetNamespace: argocd 10 | valuesContent: |- 11 | server: 12 | extraArgs: 13 | - --insecure 14 | ingress: 15 | enabled: true 16 | hosts: 17 | - argocd.atoy.dev -------------------------------------------------------------------------------- /k3s/aws/charts/3/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atoy3731/aws-k8s-terraform/7f8794eab48964c63508f46b031ace493fd93aa1/k3s/aws/charts/3/.gitkeep -------------------------------------------------------------------------------- /k3s/aws/charts/4/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atoy3731/aws-k8s-terraform/7f8794eab48964c63508f46b031ace493fd93aa1/k3s/aws/charts/4/.gitkeep -------------------------------------------------------------------------------- /k3s/aws/charts/5/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atoy3731/aws-k8s-terraform/7f8794eab48964c63508f46b031ace493fd93aa1/k3s/aws/charts/5/.gitkeep -------------------------------------------------------------------------------- /k3s/aws/db.tf: -------------------------------------------------------------------------------- 1 | resource "aws_security_group" "k8s_db_sg" { 2 | name = "k8s-db-sg" 3 | description = "Allow traffic for K8S DB" 4 | vpc_id = aws_vpc.k8s_vpc.id 5 | 6 | ingress { 7 | description = "Ingress Control Plane" 8 | from_port = 5432 9 | to_port = 5432 10 | protocol = "tcp" 11 | cidr_blocks = [var.vpc_cidr] 12 | } 13 | 14 | egress { 15 | from_port = 0 16 | to_port = 0 17 | protocol = "-1" 18 | cidr_blocks = ["0.0.0.0/0"] 19 | } 20 | 21 | tags = { 22 | Name = "k8s-db-sg" 23 | } 24 | } 25 | 26 | resource "aws_db_subnet_group" "k8s_backend_db_subnets" { 27 | name = "k8s-backend-db-subnets" 28 | subnet_ids = [aws_subnet.k8s_private_subnet_1.id, aws_subnet.k8s_private_subnet_2.id] 29 | 30 | tags = { 31 | Name = "K8S Backend DB Subnets" 32 | } 33 | } 34 | 35 | resource "aws_rds_cluster" "k8s_backend_db_cluster" { 36 | cluster_identifier = "k8s-backend-db-cluster" 37 | engine = "aurora-postgresql" 38 | 39 | db_subnet_group_name = aws_db_subnet_group.k8s_backend_db_subnets.name 40 | 41 | database_name = "k3sdb" 42 | master_username = var.db_username 43 | master_password = var.db_password 44 | backup_retention_period = 5 45 | preferred_backup_window = "07:00-09:00" 46 | 47 | final_snapshot_identifier = "k8s-db-cluster-backup" 48 | skip_final_snapshot = true 49 | 50 | vpc_security_group_ids = [aws_security_group.k8s_db_sg.id] 51 | } 52 | 53 | resource "aws_rds_cluster_instance" "k8s_backend_db_instance" { 54 | count = 1 55 | identifier = "k8s-backend-db" 56 | cluster_identifier = aws_rds_cluster.k8s_backend_db_cluster.id 57 | instance_class = "db.r5.large" 58 | engine = aws_rds_cluster.k8s_backend_db_cluster.engine 59 | } -------------------------------------------------------------------------------- /k3s/aws/instances.tf: -------------------------------------------------------------------------------- 1 | data "template_file" "server_userdata" { 2 | template = "${file("${path.module}/templates/server_userdata.sh")}" 3 | 4 | vars = { 5 | cp_lb_host = aws_elb.k8s_cp_elb.dns_name 6 | datastore_endpoint = "postgres://${aws_rds_cluster.k8s_backend_db_cluster.master_username}:${aws_rds_cluster.k8s_backend_db_cluster.master_password}@${aws_rds_cluster.k8s_backend_db_cluster.endpoint}/${aws_rds_cluster.k8s_backend_db_cluster.database_name}" 7 | k3s_token = random_string.k3s_token.result 8 | s3_bucket = var.key_s3_bucket_name 9 | configure_aws_provider = var.configure_aws_provider 10 | } 11 | } 12 | 13 | data "template_file" "agent_userdata" { 14 | template = "${file("${path.module}/templates/agent_userdata.sh")}" 15 | 16 | vars = { 17 | cp_lb_host = aws_elb.k8s_cp_elb.dns_name 18 | k3s_token = random_string.k3s_token.result 19 | k3s_agent_count = var.k3s_agent_count 20 | configure_aws_provider = var.configure_aws_provider 21 | } 22 | } 23 | 24 | ########### 25 | # KEYPAIR # 26 | ########### 27 | 28 | module "key_pair" { 29 | source = "terraform-aws-modules/key-pair/aws" 30 | 31 | key_name = "${var.cluster_name}-keypair" 32 | public_key = var.public_ssh_key 33 | } 34 | 35 | ############# 36 | # K3S TOKEN # 37 | ############# 38 | 39 | resource "random_string" "k3s_token" { 40 | length = 20 41 | special = false 42 | } 43 | 44 | ################# 45 | # KEY S3 BUCKET # 46 | ################# 47 | 48 | resource "aws_s3_bucket" "k8s_data_bucket" { 49 | bucket = var.key_s3_bucket_name 50 | acl = "private" 51 | 52 | force_destroy = true 53 | 54 | tags = { 55 | Name = "k8s-data-bucket" 56 | "kubernetes.io/cluster/${var.cluster_name}" = "owned" 57 | "KubernetesCluster" = var.cluster_name 58 | } 59 | } 60 | 61 | ########### 62 | # BASTION # 63 | ########### 64 | 65 | resource "aws_security_group" "bastion_sg" { 66 | name = "bastion-ssh" 67 | description = "Allow traffic for K8S Control Plane" 68 | vpc_id = aws_vpc.k8s_vpc.id 69 | 70 | ingress { 71 | description = "Ingress Bastion" 72 | from_port = 22 73 | to_port = 22 74 | protocol = "tcp" 75 | cidr_blocks = ["0.0.0.0/0"] 76 | } 77 | 78 | egress { 79 | from_port = 0 80 | to_port = 0 81 | protocol = "-1" 82 | cidr_blocks = ["0.0.0.0/0"] 83 | } 84 | 85 | tags = { 86 | Name = "bastion-sg" 87 | "kubernetes.io/cluster/${var.cluster_name}" = "owned" 88 | "KubernetesCluster" = var.cluster_name 89 | } 90 | } 91 | 92 | resource "aws_instance" "bastion" { 93 | ami = var.ami_id 94 | instance_type = "t2.micro" 95 | 96 | subnet_id = aws_subnet.k8s_public_subnet_1.id 97 | vpc_security_group_ids = [aws_security_group.bastion_sg.id] 98 | associate_public_ip_address = true 99 | 100 | key_name = "${var.cluster_name}-keypair" 101 | 102 | tags = { 103 | Name = "k8s-bastion" 104 | "kubernetes.io/cluster/${var.cluster_name}" = "owned" 105 | "KubernetesCluster" = var.cluster_name 106 | } 107 | } 108 | 109 | ########### 110 | # MASTERS # 111 | ########### 112 | 113 | resource "aws_security_group" "k8s_cp_sg" { 114 | name = "k8s-cp-sg" 115 | description = "Allow traffic for K8S Control Plane" 116 | vpc_id = aws_vpc.k8s_vpc.id 117 | 118 | egress { 119 | from_port = 0 120 | to_port = 0 121 | protocol = "-1" 122 | cidr_blocks = ["0.0.0.0/0"] 123 | } 124 | 125 | tags = { 126 | Name = "k8s-cp-sg" 127 | "kubernetes.io/cluster/${var.cluster_name}" = "owned" 128 | "KubernetesCluster" = var.cluster_name 129 | } 130 | } 131 | 132 | resource "aws_security_group_rule" "k8s_cp_sg_self_ingress" { 133 | type = "ingress" 134 | from_port = 0 135 | to_port = 0 136 | protocol = "-1" 137 | cidr_blocks = [aws_vpc.k8s_vpc.cidr_block] 138 | security_group_id = aws_security_group.k8s_cp_sg.id 139 | } 140 | 141 | resource "aws_security_group_rule" "k8s_cp_ingress" { 142 | description = "Ingress Control Plane" 143 | type = "ingress" 144 | from_port = 6443 145 | to_port = 6443 146 | protocol = "tcp" 147 | cidr_blocks = ["0.0.0.0/0"] 148 | security_group_id = aws_security_group.k8s_cp_sg.id 149 | } 150 | 151 | resource "aws_iam_policy" "k8s_master_iam_policy" { 152 | name = "k8s-master-iam-policy" 153 | path = "/" 154 | description = "K8S Master IAM Policy" 155 | 156 | policy = <