Skip to content

Commit a0aceba

Browse files
committed
feat: Add EKS terraform example
feat: Add Terraform for GCP GKE feat: Update terraform
1 parent 00fcb7a commit a0aceba

16 files changed

+534
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
override.yaml
33
.cq
44
cloudquery.log
5+
**/.terraform
6+
terraform.tfstate

.helmignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424

2525
# CloudQuery
2626
.cq/
27-
cloudquery.log
27+
cloudquery.log
28+
terraform

terraform/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Terraform Examples
2+
3+
This directory contains few examples on how to spawn k8s clusters on AWS and GCP so you can install the helm charts.

terraform/aws/.terraform.lock.hcl

+97
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/aws/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```bash
2+
terraform apply
3+
aws sts get-caller-identity
4+
aws eks update-kubeconfig --region eu-west-1 --name cloudquery-eks
5+
helm install cloudquery .
6+
```

terraform/aws/eks.tf

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
3+
locals {
4+
# VPC - existing or new?
5+
vpc_id = var.vpc_id == "" ? module.vpc.vpc_id : var.vpc_id
6+
public_subnet_ids = coalescelist(module.vpc.public_subnets, var.public_subnet_ids, [""])
7+
private_subnet_ids = coalescelist(module.vpc.private_subnets, var.private_subnet_ids, [""])
8+
private_subnets_cidr_blocks = coalescelist(module.vpc.private_subnets_cidr_blocks, var.private_subnets_cidr_blocks, [""])
9+
}
10+
11+
data "aws_region" "current" {}
12+
13+
###################
14+
# VPC
15+
###################
16+
17+
module "vpc" {
18+
source = "terraform-aws-modules/vpc/aws"
19+
version = "~> 3.0"
20+
21+
create_vpc = var.vpc_id == ""
22+
23+
name = var.name
24+
25+
cidr = var.cidr
26+
azs = var.azs
27+
public_subnets = var.public_subnets
28+
private_subnets = var.private_subnets
29+
30+
enable_nat_gateway = true
31+
single_nat_gateway = true
32+
33+
}
34+
35+
###################
36+
# Security groups
37+
###################
38+
39+
module "eks_sg" {
40+
source = "terraform-aws-modules/security-group/aws"
41+
version = "~> 4.0"
42+
43+
name = "eks-sg"
44+
vpc_id = local.vpc_id
45+
description = "Allow outbound connections to the world"
46+
47+
ingress_cidr_blocks = ["0.0.0.0/0"]
48+
49+
egress_rules = ["all-all"]
50+
51+
}
52+
53+
###################
54+
# EKS
55+
###################
56+
57+
module "eks" {
58+
source = "terraform-aws-modules/eks/aws"
59+
60+
cluster_name = "cloudquery-eks"
61+
cluster_version = "1.21"
62+
cluster_endpoint_private_access = true
63+
cluster_endpoint_public_access = true
64+
65+
cluster_addons = {
66+
coredns = {
67+
resolve_conflicts = "OVERWRITE"
68+
}
69+
kube-proxy = {}
70+
vpc-cni = {
71+
resolve_conflicts = "OVERWRITE"
72+
}
73+
}
74+
75+
76+
vpc_id = local.vpc_id
77+
subnet_ids = local.private_subnet_ids
78+
79+
// # EKS Managed Node Group(s)
80+
eks_managed_node_group_defaults = {
81+
ami_type = "AL2_x86_64"
82+
disk_size = 100
83+
instance_types = ["m5.large"]
84+
vpc_security_group_ids = [module.eks_sg.security_group_id]
85+
}
86+
87+
eks_managed_node_groups = {
88+
# Default node group - as provided by AWS EKS
89+
default_node_group = {
90+
# By default, the module creates a launch template to ensure tags are propagated to instances, etc.,
91+
# so we need to disable it to use the default template provided by the AWS EKS managed node group service
92+
create_launch_template = false
93+
launch_template_name = ""
94+
max_size = 2
95+
desired_size = 1
96+
}
97+
}
98+
99+
}

terraform/aws/terraform.tfvars

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Name to use on all resources created (VPC, RDS, etc)
2+
name = "cloudquery"
3+
4+
#####################
5+
# CloudQuery Service
6+
#####################
7+
8+
###################################
9+
# Infrastructure (to be created)
10+
###################################
11+
12+
# The CIDR block for the VPC.
13+
# type: string
14+
cidr = "10.10.0.0/16"
15+
16+
# A list of availability zones names or ids in the region
17+
# type: list(string)
18+
azs = ["eu-west-1a", "eu-west-1b"]
19+
20+
# A list of public subnets
21+
# type: list(string)
22+
public_subnets = ["10.10.1.0/24", "10.10.2.0/24"]
23+
24+
# A list of database subnets
25+
# type: list(string)
26+
private_subnets = ["10.10.11.0/24", "10.10.12.0/24"]
27+
28+
##############################################
29+
# Infrastructure (use existing VPC resources)
30+
##############################################
31+
32+
# vpc_id = "vpc-9651acf1"
33+
# public_subnet_ids = ["subnet-6fe3d837", "subnet-9211eef5", "subnet-e29d66ab"]
34+
# private_subnet_ids = ["subnet-6fe3d837", "subnet-9211eef5", "subnet-e29d66ab"]
35+
# private_subnets_cidr_blocks = ["10.0.0.0/24", "10.0.1.0/24", "10.0.2.0/24"]

terraform/aws/terraform.tfvars.sample

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Name to use on all resources created (VPC, RDS, etc)
2+
name = "cloudquery"
3+
4+
#####################
5+
# CloudQuery Service
6+
#####################
7+
8+
###################################
9+
# Infrastructure (to be created)
10+
###################################
11+
12+
# The CIDR block for the VPC.
13+
# type: string
14+
cidr = "10.10.0.0/16"
15+
16+
# A list of availability zones names or ids in the region
17+
# type: list(string)
18+
azs = ["eu-west-1a", "eu-west-1b"]
19+
20+
# A list of public subnets
21+
# type: list(string)
22+
public_subnets = ["10.10.1.0/24", "10.10.2.0/24"]
23+
24+
# A list of database subnets
25+
# type: list(string)
26+
private_subnets = ["10.10.11.0/24", "10.10.12.0/24"]
27+
28+
##############################################
29+
# Infrastructure (use existing VPC resources)
30+
##############################################
31+
32+
# vpc_id = "vpc-9651acf1"
33+
# public_subnet_ids = ["subnet-6fe3d837", "subnet-9211eef5", "subnet-e29d66ab"]
34+
# private_subnet_ids = ["subnet-6fe3d837", "subnet-9211eef5", "subnet-e29d66ab"]
35+
# private_subnets_cidr_blocks = ["10.0.0.0/24", "10.0.1.0/24", "10.0.2.0/24"]

terraform/aws/variables.tf

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
variable "name" {
2+
description = "Name to use on all resources created (VPC, RDS, etc)"
3+
type = string
4+
default = "cloudquery"
5+
}
6+
7+
variable "tags" {
8+
description = "A map of tags to use on all resources"
9+
type = map(string)
10+
default = {}
11+
}
12+
13+
# VPC
14+
variable "vpc_id" {
15+
description = "ID of an existing VPC where resources will be created"
16+
type = string
17+
default = ""
18+
}
19+
20+
variable "public_subnet_ids" {
21+
description = "A list of IDs of existing public subnets inside the VPC"
22+
type = list(string)
23+
default = []
24+
}
25+
26+
variable "private_subnet_ids" {
27+
description = "A list of IDs of existing private subnets inside the VPC"
28+
type = list(string)
29+
default = []
30+
}
31+
32+
variable "private_subnets_cidr_blocks" {
33+
description = "A list of CIDR blocks of private subnets inside the VPC to allow access to RDS database"
34+
type = list(string)
35+
default = []
36+
}
37+
38+
variable "cidr" {
39+
description = "The CIDR block for the VPC which will be created if `vpc_id` is not specified"
40+
type = string
41+
default = ""
42+
}
43+
44+
variable "azs" {
45+
description = "A list of availability zones in the region"
46+
type = list(string)
47+
default = []
48+
}
49+
50+
variable "public_subnets" {
51+
description = "A list of public subnets inside the VPC"
52+
type = list(string)
53+
default = []
54+
}
55+
56+
variable "private_subnets" {
57+
description = "A list of private subnets inside the VPC"
58+
type = list(string)
59+
default = []
60+
}

terraform/aws/versions.tf

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
terraform {
2+
required_version = ">= 0.15"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 2.68"
8+
}
9+
10+
random = {
11+
source = "hashicorp/random"
12+
version = ">= 2.0"
13+
}
14+
15+
local = {
16+
source = "hashicorp/local"
17+
version = ">= 2.0"
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)