Skip to content

Commit

Permalink
Add a core-infra stack to set up initial service contexts, and other …
Browse files Browse the repository at this point in the history
…stuff

This is generally nice to have, but also will ensure the management console has a service context, alongside the ones we put on the other clusters
  • Loading branch information
michaeljguarino committed Dec 17, 2024
1 parent c4cb662 commit 5bc60b2
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 8 deletions.
23 changes: 23 additions & 0 deletions setup/stacks/core-infra.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: deployments.plural.sh/v1alpha1
kind: InfrastructureStack
metadata:
name: core-infra
spec:
name: core-infra
detach: false
type: TERRAFORM
approval: true
manageState: true
actor: [email protected]
repositoryRef:
name: infra
namespace: infra
clusterRef:
name: mgmt
namespace: infra
variables:
region: [[ .Region ]]
cluster_name: [[ .Cluster ]]
git:
ref: main
folder: terraform/core-infra
13 changes: 5 additions & 8 deletions templates/clusters/stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ spec:
clusterRef:
name: mgmt
namespace: infra
variables:
cluster: {{ context.name }}
fleet: {{ context.fleet }}
tier: {{ context.tier }}
git:
ref: main
folder: terraform/modules/clusters/{{ context.cloud }}
environment:
- name: TF_VAR_cluster
value: {{ context.name }}
- name: TF_VAR_fleet
value: {{ context.fleet }}
- name: TF_VAR_tier
value: {{ context.tier }}
folder: terraform/modules/clusters/{{ context.cloud }}
4 changes: 4 additions & 0 deletions terraform/core-infra/aws/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# this can be used for provisioning any base infrastructure for your environment, a couple of common usecases:
# * setting up multi-cluster networks
# * setting up dns zones, subdomains, etc
# * configuring Cloud IAM throughout your environment
17 changes: 17 additions & 0 deletions terraform/core-infra/aws/context.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
data "aws_eks_cluster" "mgmt" {
name = var.cluster_name
}

data "aws_vpc" "mgmt" {
id = one(data.aws_eks_cluster.mgmt.vpc_config).vpc_id
}

resource "plural_service_context" "mgmt" {
name = "plrl/clusters/mgmt"
configuration = {
cluster_name = var.cluster_name
vpc_id = one(data.aws_eks_cluster.mgmt.vpc_config).vpc_id
subnet_ids = one(data.aws_eks_cluster.mgmt.vpc_config).subnet_ids
vpc_cidr = data.aws_vpc.mgmt.cidr_block
}
}
8 changes: 8 additions & 0 deletions terraform/core-infra/aws/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "region" {
type = string
default = "us-east-2"
}

variable "cluster_name" {
type = string
}
21 changes: 21 additions & 0 deletions terraform/core-infra/aws/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
terraform {
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
}

plural = {
source = "pluralsh/plural"
version = ">= 0.2.9"
}
}
}

provider "aws" {
region = var.region
}


provider "plural" { }
4 changes: 4 additions & 0 deletions terraform/core-infra/azure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# this can be used for provisioning any base infrastructure for your environment, a couple of common usecases:
# * setting up multi-cluster networks
# * setting up dns zones, subdomains, etc
# * configuring Cloud IAM throughout your environment
Empty file.
8 changes: 8 additions & 0 deletions terraform/core-infra/azure/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "region" {
type = string
default = "us-east-2"
}

variable "cluster_name" {
type = string
}
28 changes: 28 additions & 0 deletions terraform/core-infra/azure/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
terraform {
required_version = ">= 1.0"

required_providers {
google = {
source = "hashicorp/google"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.10"
}
plural = {
source = "pluralsh/plural"
version = ">= 0.2.9"
}
local = {
source = "hashicorp/local"
}
}
}

provider "google" {
region = var.region
}

data "google_client_config" "default" {}

provider "plural" { }
4 changes: 4 additions & 0 deletions terraform/core-infra/gcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# this can be used for provisioning any base infrastructure for your environment, a couple of common usecases:
# * setting up multi-cluster networks
# * setting up dns zones, subdomains, etc
# * configuring Cloud IAM throughout your environment
22 changes: 22 additions & 0 deletions terraform/core-infra/gcp/context.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
data "google_container_cluster" "mgmt" {
name = var.cluster_name
location = var.region
}

data "google_compute_network" "network" {
name = data.google_container_cluster.mgmt.network
}

data "google_compute_subnetwork" "subnetwork" {
name = data.google_container_cluster.mgmt.subnetwork
}

resource "plural_service_context" "mgmt" {
name = "plrl/clusters/mgmt"
configuration = {
cluster_name = var.cluster_name
network = data.google_container_cluster.mgmt.network
subnetwork = data.google_container_cluster.mgmt.subnetwork
cidr = data.google_compute_subnetwork.ip_cidr_range
}
}
8 changes: 8 additions & 0 deletions terraform/core-infra/gcp/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "region" {
type = string
default = "us-east-2"
}

variable "cluster_name" {
type = string
}
28 changes: 28 additions & 0 deletions terraform/core-infra/gcp/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
terraform {
required_version = ">= 1.0"

required_providers {
google = {
source = "hashicorp/google"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.10"
}
plural = {
source = "pluralsh/plural"
version = ">= 0.2.9"
}
local = {
source = "hashicorp/local"
}
}
}

provider "google" {
region = var.region
}

data "google_client_config" "default" {}

provider "plural" { }
11 changes: 11 additions & 0 deletions terraform/modules/clusters/aws/context.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "plural_service_context" "mgmt" {
name = "plrl/clusters/${var.cluster_name}"
configuration = {
cluster_name = var.cluster_name
vpc_id = module.vpc.vpc_id
subnet_ids = concat(module.vpc.public_subnets, module.vpc.private_subnets)
private_subnets = module.vpc.private_subnets
public_subnets = module.vpc.public_subnets
vpc_cidr = var.vpc_cidr
}
}
10 changes: 10 additions & 0 deletions terraform/modules/clusters/gcp/context.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "plural_service_context" "mgmt" {
name = "plrl/clusters/${var.cluster_name}"

configuration = {
cluster_name = var.cluster_name
network = module.gcp-network.network_name
subnetwork = module.gcp-network.subnets_names[0]
cidr = var.subnet_cidr
}
}

0 comments on commit 5bc60b2

Please sign in to comment.