Skip to content

Commit

Permalink
Terraform code for Exoscale SKS (#508)
Browse files Browse the repository at this point in the history
* Add: makefiles for Exoscale

Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>

* Add: Terraform code for SKS

Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
  • Loading branch information
nlamirault authored May 5, 2021
1 parent a78a4c2 commit 6d6acaa
Show file tree
Hide file tree
Showing 13 changed files with 369 additions and 0 deletions.
21 changes: 21 additions & 0 deletions hack/exoscale.dev.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2020 Nicolas Lamirault <nicolas.lamirault@gmail.com>

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

EXO_PROJECT_dev = portefaix-dev

EXO_REGION_dev = ch-dk-2

EXO_CLUSTER_dev = portefaix-dev-cluster-sks

KUBE_CONTEXT_dev =
56 changes: 56 additions & 0 deletions hack/exoscale.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (C) 2021 Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MKFILE_DIR := $(dir $(MKFILE_PATH))

include $(MKFILE_DIR)/commons.mk
include $(MKFILE_DIR)/exoscale.*.mk

EXO_PROJECT = $(EXO_PROJECT_$(ENV))
EXO_REGION = $(EXO_REGION_$(ENV))

CLUSTER = $(EXO_CLUSTER_$(ENV))

BUNDLE_PATH=$(DIR)/vendor/bundle/ruby/2.7.0/bin


# ====================================
# E X O S C A L E
# ====================================

##@ Exoscale

.PHONY: exo-kube-credentials
exo-kube-credentials: guard-ENV ## Generate credentials
exo sks kubeconfig $(CLUSTER) admin -g system:masters > /tmp/exo-$(CLUSTER)

.PHONY: exo-bucket
exo-bucket: guard-ENV ## Setup the bucket for Terraform states
@echo -e "$(INFO_COLOR)Create the service account into $(GCP_PROJECT) $(NO_COLOR)"
exo storage mb sos://$(EXO_PROJECT)-tfstates --acl private


# ====================================
# I N S P E C
# ====================================

##@ Inspec

.PHONY: inspec-cis-kubernetes
inspec-cis-kubernetes: guard-ENV ## Test inspec
@echo -e "$(OK_COLOR)CIS Kubernetes benchmark$(NO_COLOR)"
@bundle exec inspec exec \
https://github.com/dev-sec/cis-kubernetes-benchmark.git \
--reporter cli json:$(AZ_RESOURCE_GROUP).json
1 change: 1 addition & 0 deletions iac/exoscale/sks/terraform/.terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.15.0
22 changes: 22 additions & 0 deletions iac/exoscale/sks/terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions iac/exoscale/sks/terraform/backend-vars/dev.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (C) 2021 Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

endpoint = "https://sos-ch-dk-2.exo.io"
region = "ch-dk-2"
bucket = "portefaix-dev-tfstates"
key = "portefaix-dev-tfstates"
25 changes: 25 additions & 0 deletions iac/exoscale/sks/terraform/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (C) 2021 Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

terraform {
backend "s3" {
# Deactivate the AWS specific behaviours
# https://www.terraform.io/docs/backends/types/s3.html#skip_credentials_validation
skip_credentials_validation = true
skip_get_ec2_platforms = true
skip_requesting_account_id = true
skip_metadata_api_check = true
skip_region_validation = true
}
}
39 changes: 39 additions & 0 deletions iac/exoscale/sks/terraform/errored.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (C) 2021 Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

{
"version": 4,
"terraform_version": "0.15.0",
"serial": 0,
"lineage": "2da3dd8d-f5a2-3332-7980-19f8183ed9c9",
"outputs": {},
"resources": [
{
"module": "module.sks",
"mode": "managed",
"type": "exoscale_security_group_rules",
"name": "sks",
"provider": "provider[\"registry.terraform.io/exoscale/exoscale\"]",
"instances": []
},
{
"module": "module.sks",
"mode": "managed",
"type": "exoscale_sks_nodepool",
"name": "core",
"provider": "provider[\"registry.terraform.io/exoscale/exoscale\"]",
"instances": []
}
]
}
24 changes: 24 additions & 0 deletions iac/exoscale/sks/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) 2021 Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

terraform {
required_version = ">= 0.15.0"

required_providers {
exoscale = {
source = "exoscale/exoscale"
version = "0.23.0"
}
}
}
13 changes: 13 additions & 0 deletions iac/exoscale/sks/terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (C) 2021 Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
17 changes: 17 additions & 0 deletions iac/exoscale/sks/terraform/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (C) 2021 Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

provider "exoscale" {
region = var.region
}
28 changes: 28 additions & 0 deletions iac/exoscale/sks/terraform/sks.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2021 Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module "sks" {
source = "nlamirault/sks/exoscale"
version = "0.1.0"

name = var.name
zone = var.zone

kubernetes_version = var.kubernetes_version
service_level = var.service_level
cni = var.cni
addons = var.addons

node_pools = var.node_pools
}
41 changes: 41 additions & 0 deletions iac/exoscale/sks/terraform/tfvars/dev.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (C) 2021 Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#####################################################################""
# Provider

region = "ch-dk-2"

###########################################################################
# Kubernetes cluster

name = "portefaix-dev-cluster-sks"

zone = "ch-dk-2"

kubernetes_version = "1.20.6"

service_level = "starter"

cni = "calico"

addons = ["exoscale-cloud-controller"]

node_pools = [
{
name = "core"
instance_type = "medium"
size = 2
}
]
64 changes: 64 additions & 0 deletions iac/exoscale/sks/terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright (C) 2021 Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#######################################################################
# Provider

variable "region" {
type = string
description = "The region in which the cluster should be created."
}

#######################################################################
# SKS

variable "name" {
description = "The name of the SKS cluster."
type = string
}

variable "zone" {
description = "The name of the zone to deploy the SKS cluster into."
type = string
}

variable "kubernetes_version" {
type = string
description = "The Kubernetes version of the SKS cluster control plane"
}

variable "service_level" {
type = string
description = "The service level of the SKS cluster control plane"
}

variable "cni" {
type = string
description = "The Kubernetes CNI plugin to be deployed in the SKS cluster control plane"
}

variable "addons" {
type = list(string)
description = "A list of optional add-ons to be deployed in the SKS cluster control plane"
}

variable "node_pools" {
description = "The SKS node pools to create."
type = list(object({
name = string
instance_type = string
size = number
}))
default = []
}

0 comments on commit 6d6acaa

Please sign in to comment.