├── locals.tf ├── architecture.jpg ├── .gitignore ├── CODE_OF_CONDUCT.md ├── test.yaml ├── providers.tf ├── sample-sg.tf ├── scripts ├── sg-policy.sh └── network.sh ├── README.md ├── LICENSE ├── iam.tf ├── CONTRIBUTING.md └── main.tf /locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | cluster_name = "CNICustomNetworkDemoEKS" 3 | region = "ap-southeast-2" 4 | } 5 | -------------------------------------------------------------------------------- /architecture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/terraform-cni-custom-network-sample/HEAD/architecture.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | .terraform.lock.hcl 8 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /test.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | labels: 6 | app: nginx 7 | spec: 8 | replicas: 1 9 | selector: 10 | matchLabels: 11 | app: nginx 12 | template: 13 | metadata: 14 | labels: 15 | app: nginx 16 | spec: 17 | containers: 18 | - name: nginx 19 | image: nginx:latest 20 | ports: 21 | - containerPort: 80 22 | -------------------------------------------------------------------------------- /providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "${local.region}" 3 | } 4 | 5 | data "aws_eks_cluster" "cluster" { 6 | name = module.eks.cluster_id 7 | } 8 | 9 | data "aws_eks_cluster_auth" "cluster" { 10 | name = module.eks.cluster_id 11 | } 12 | 13 | provider "kubernetes" { 14 | host = data.aws_eks_cluster.cluster.endpoint 15 | cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data) 16 | token = data.aws_eks_cluster_auth.cluster.token 17 | # load_config_file = false 18 | # version = "~> 1.9" 19 | } 20 | -------------------------------------------------------------------------------- /sample-sg.tf: -------------------------------------------------------------------------------- 1 | # Create example security group for pod 2 | resource "aws_security_group" "example_sg" { 3 | name = "example_sg" 4 | vpc_id = module.vpc.vpc_id 5 | 6 | ingress { 7 | description = "allow http" 8 | from_port = 80 9 | to_port = 80 10 | protocol = "tcp" 11 | # cidr_blocks = module.vpc.private_subnets_cidr_blocks 12 | cidr_blocks = ["10.0.0.0/16"] 13 | } 14 | 15 | egress { 16 | from_port = 0 17 | to_port = 0 18 | protocol = "-1" 19 | cidr_blocks = ["0.0.0.0/0"] 20 | ipv6_cidr_blocks = ["::/0"] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /scripts/sg-policy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # kubectl auth 4 | KUBE_CONFIG="$(mktemp)" 5 | aws eks update-kubeconfig --name "${CLUSTER_NAME}" --kubeconfig "${KUBE_CONFIG}" 6 | 7 | 8 | # Create security group policy 9 | cat <