├── LICENSE ├── README.md ├── database ├── main.tf └── variable.tf ├── eks ├── main.tf ├── output.tf └── variable.tf ├── kubernetes ├── app.tf ├── main.tf └── variable.tf ├── main.tf ├── output.tf ├── production.tfvars ├── testing.tfvars ├── variable.tf └── vpc ├── main.tf ├── output.tf └── variable.tf /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Harshetjain666 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS EKS Fargate setup with terraform 2 | 3 | Source code of my AWS EKS with fargate cluster setup. 4 | 5 | To Know more go to 6 | 7 | https://harshetjain.medium.com/with-latest-updates-create-amazon-eks-fargate-cluster-and-managed-node-group-using-terraform-bc5cfefd5773 8 | -------------------------------------------------------------------------------- /database/main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_db_subnet_group" "Groups" { 2 | name = "db groups" 3 | subnet_ids = var.private_subnets 4 | 5 | tags = { 6 | Name = "DB subnet group" 7 | } 8 | } 9 | 10 | resource "aws_security_group" "data" { 11 | name = "data-SG" 12 | description = "Allow mysql inbound traffic" 13 | vpc_id = var.vpc_id 14 | 15 | ingress { 16 | description = "Traffic" 17 | from_port = 3306 18 | to_port = 3306 19 | protocol = "tcp" 20 | } 21 | 22 | tags = { 23 | Name = "data_server-SG" 24 | } 25 | 26 | } 27 | 28 | data "aws_secretsmanager_secret_version" "credentials" { 29 | secret_id = "${var.secret_id}" 30 | } 31 | 32 | locals { 33 | cred = jsondecode( 34 | data.aws_secretsmanager_secret_version.credentials.secret_string 35 | ) 36 | } 37 | 38 | resource "aws_db_instance" "db" { 39 | identifier = "${var.identifier}-${var.environment}" 40 | allocated_storage = "${var.allocated_storage}" 41 | storage_type = "${var.storage_type}" 42 | engine = "${var.engine}" 43 | engine_version = "${var.engine_version}" 44 | instance_class = "${var.instance_class}" 45 | name = "${var.database_name}" 46 | publicly_accessible = false 47 | db_subnet_group_name = aws_db_subnet_group.Groups.name 48 | vpc_security_group_ids = [aws_security_group.data.id] 49 | username = local.cred.username 50 | password = local.cred.password 51 | 52 | 53 | depends_on = [ aws_db_subnet_group.Groups, aws_security_group.data ] 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /database/variable.tf: -------------------------------------------------------------------------------- 1 | variable "secret_id" { 2 | description = "Put your secret name here" 3 | } 4 | 5 | variable "identifier" { 6 | description = "Enter the name of our database which is unique in that region" 7 | } 8 | 9 | variable "allocated_storage" { 10 | description = "Enter the storage of database" 11 | } 12 | 13 | variable "storage_type" { 14 | description = "Put the type of storage you want" 15 | } 16 | 17 | variable "engine" { 18 | description = "Put your database engine you want eg. mysql" 19 | } 20 | 21 | variable "engine_version" { 22 | description = "Which version you want of your db engine" 23 | } 24 | 25 | variable "instance_class" { 26 | description = "Which type of instance you need like ram and cpu eg. db.t2.micro" 27 | } 28 | 29 | variable "database_name" { 30 | description = "Enter your initial database name" 31 | } 32 | 33 | variable "environment" { 34 | description = "your environment name" 35 | } 36 | 37 | variable "private_subnets" { 38 | description = "List of private subnet IDs" 39 | } 40 | 41 | variable "vpc_id" { 42 | description = "put your vpc id" 43 | } -------------------------------------------------------------------------------- /eks/main.tf: -------------------------------------------------------------------------------- 1 | 2 | resource "aws_eks_cluster" "eks_cluster" { 3 | name = "${var.cluster_name}-${var.environment}" 4 | 5 | role_arn = aws_iam_role.eks_cluster_role.arn 6 | enabled_cluster_log_types = ["api", "audit", "authenticator", "controllerManager", "scheduler"] 7 | 8 | 9 | vpc_config { 10 | subnet_ids = concat(var.public_subnets, var.private_subnets) 11 | } 12 | 13 | timeouts { 14 | delete = "30m" 15 | } 16 | 17 | depends_on = [ 18 | aws_iam_role_policy_attachment.AmazonEKSClusterPolicy1, 19 | aws_iam_role_policy_attachment.AmazonEKSVPCResourceController1, 20 | aws_cloudwatch_log_group.cloudwatch_log_group 21 | ] 22 | } 23 | 24 | resource "aws_iam_policy" "AmazonEKSClusterCloudWatchMetricsPolicy" { 25 | name = "AmazonEKSClusterCloudWatchMetricsPolicy" 26 | policy = <