Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions modules/aws-infra/k8s.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module "k8s-common" {
source = "../kubernetes-common"
for_each = toset(var.runtime == "kubernetes" ? ["this"] : [])
score_workload_resource_type = var.score_workload_resource_type
}

resource "platform-orchestrator_module" "k8s-cluster-credentials" {
for_each = toset(var.runtime == "kubernetes" ? ["development", "production"] : [])
id = "aks-${each.key}-cluster-credentials"
resource_type = module.k8s-common["this"].cluster_credentials_resource_type
module_source = "inline"
module_inputs = jsonencode({
env_type_id = "$${context.env_type_id}"
})
module_source_code = <<EOT
variable "env_type_id" {
type = string
}
output "host" {
value = "https://E0AB44F606B56BF1DAF47472A94746CB.yl4.eu-central-1.eks.amazonaws.com"
}
output "cluster_ca_certificate" {
value = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWM..."
}
locals {
cluster_region = "eu-central-1"
cluster_name = "${each.key}-cluster"
}

output "humanitec_metadata" {
value = {
"Aws-Ecs-Cluster-Name" = local.cluster_name
"Aws-Region" = local.cluster_region
"Console-Url" = "https://$${local.cluster_region}.console.aws.amazon.com/eks/clusters/$${local.cluster_name}?region=$${local.cluster_region}"
}
}
EOT
}

resource "platform-orchestrator_module_rule" "cluster-creds" {
for_each = toset(var.runtime == "kubernetes" ? ["development", "production"] : [])
module_id = platform-orchestrator_module.k8s-cluster-credentials[each.key].id
resource_id = module.k8s-common["this"].cluster_credentials_resource_id
env_type_id = each.key
}
20 changes: 20 additions & 0 deletions modules/aws-infra/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
terraform {
required_providers {
platform-orchestrator = {
source = "humanitec/platform-orchestrator"
version = "~> 2.0"
}
}
}

variable "runtime" {
type = string
}

variable "primary_resource" {
type = string
}

variable "score_workload_resource_type" {
type = string
}
47 changes: 47 additions & 0 deletions modules/azure-infra/k8s.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module "k8s-common" {
source = "../kubernetes-common"
for_each = toset(var.runtime == "kubernetes" ? ["this"] : [])
score_workload_resource_type = var.score_workload_resource_type
}

resource "platform-orchestrator_module" "k8s-cluster-credentials" {
for_each = toset(var.runtime == "kubernetes" ? ["development", "production"] : [])
id = "aks-${each.key}-cluster-credentials"
resource_type = module.k8s-common["this"].cluster_credentials_resource_type
module_source = "inline"
module_inputs = jsonencode({
env_type_id = "$${context.env_type_id}"
})
module_source_code = <<EOT
variable "env_type_id" {
type = string
}
output "host" {
value = "https://azure-cluster-1a2b3c4d.hcp.eastus.azmk8s.io:443"
}
output "cluster_ca_certificate" {
value = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWM..."
}
locals {
cluster_project = "example-project"
cluster_region = "eastus"
cluster_name = "${each.key}-cluster"
}

output "humanitec_metadata" {
value = {
"Azure-Resource-Group" = local.cluster_project
"Azure-Aks-Cluster-Name" = local.cluster_name
"Azure-Region" = local.cluster_region
"Console-Url" = "https://portal.azure.com/#@some-tenant/resource/subscriptions/some-subscription/resourceGroups/$${local.cluster_project}/providers/Microsoft.ContainerService/managedClusters/$${local.cluster_name}/overview"
}
}
EOT
}

resource "platform-orchestrator_module_rule" "cluster-creds" {
for_each = toset(var.runtime == "kubernetes" ? ["development", "production"] : [])
module_id = platform-orchestrator_module.k8s-cluster-credentials[each.key].id
resource_id = module.k8s-common["this"].cluster_credentials_resource_id
env_type_id = each.key
}
20 changes: 20 additions & 0 deletions modules/azure-infra/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
terraform {
required_providers {
platform-orchestrator = {
source = "humanitec/platform-orchestrator"
version = "~> 2.0"
}
}
}

variable "runtime" {
type = string
}

variable "primary_resource" {
type = string
}

variable "score_workload_resource_type" {
type = string
}
47 changes: 47 additions & 0 deletions modules/gcp-infra/k8s.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module "k8s-common" {
source = "../kubernetes-common"
for_each = toset(var.runtime == "kubernetes" ? ["this"] : [])
score_workload_resource_type = var.score_workload_resource_type
}

resource "platform-orchestrator_module" "k8s-cluster-credentials" {
for_each = toset(var.runtime == "kubernetes" ? ["development", "production"] : [])
id = "gke-${each.key}-cluster-credentials"
resource_type = module.k8s-common["this"].cluster_credentials_resource_type
module_source = "inline"
module_inputs = jsonencode({
env_type_id = "$${context.env_type_id}"
})
module_source_code = <<EOT
variable "env_type_id" {
type = string
}
output "host" {
value = "https://34.75.145.245"
}
output "cluster_ca_certificate" {
value = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWM..."
}
locals {
cluster_project = "example-project"
cluster_region = "europe-west3"
cluster_name = "${each.key}-cluster"
}

output "humanitec_metadata" {
value = {
"Gcp-Project" = local.cluster_project
"Gcp-Gke-Cluster-Name" = local.cluster_name
"Gcp-Region" = local.cluster_region
"Console-Url" = "https://console.cloud.google.com/kubernetes/clusters/details/$${local.cluster_region}/$${local.cluster_name}/overview?hl=en&project=$${local.cluster_project}"
}
}
EOT
}

resource "platform-orchestrator_module_rule" "cluster-creds" {
for_each = toset(var.runtime == "kubernetes" ? ["development", "production"] : [])
module_id = platform-orchestrator_module.k8s-cluster-credentials[each.key].id
resource_id = module.k8s-common["this"].cluster_credentials_resource_id
env_type_id = each.key
}
20 changes: 20 additions & 0 deletions modules/gcp-infra/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
terraform {
required_providers {
platform-orchestrator = {
source = "humanitec/platform-orchestrator"
version = "~> 2.0"
}
}
}

variable "runtime" {
type = string
}

variable "primary_resource" {
type = string
}

variable "score_workload_resource_type" {
type = string
}
10 changes: 10 additions & 0 deletions modules/infra/envs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "platform-orchestrator_project" "project" {
id = "example"
}

resource "platform-orchestrator_environment" "development" {
id = "development"
project_id = platform-orchestrator_project.project.id
env_type_id = platform-orchestrator_environment_type.development.id
depends_on = [platform-orchestrator_runner_rule.default]
}
65 changes: 59 additions & 6 deletions modules/infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,65 @@ terraform {
}

variable "inputs" {
type = map(any)
type = object({
cloud = string
runtime = string
primary_resource = string
})

validation {
condition = contains(["aws", "gcp", "azure"], var.inputs.cloud)
error_message = "Invalid cloud: Must be one of [\"aws\", \"gcp\", \"azure\"]."
}

validation {
condition = contains(["kubernetes", "vms", "serverless"], var.inputs.runtime)
error_message = "Invalid runtime: Must be one of [\"kubernetes\", \"vms\", \"serverless\"]."
}

validation {
condition = contains(["postgres", "redis"], var.inputs.primary_resource)
error_message = "Invalid primary_resource: Must be one of [\"postgres\", \"redis\"]."
}
}

resource "platform-orchestrator_resource_type" "test" {
id = "test"
output_schema = jsonencode({
type = "object"
})
resource "platform-orchestrator_environment_type" "development" {
id = "development"
display_name = "Development"
}

resource "platform-orchestrator_environment_type" "production" {
id = "production"
display_name = "Production"
}

module "score-common" {
source = "../score-common"
}

module "aws-infra" {
source = "../aws-infra"
for_each = toset(var.inputs.cloud == "aws" ? ["this"] : [])
runtime = var.inputs.runtime
primary_resource = var.inputs.primary_resource
score_workload_resource_type = module.score-common.score_workload_resource_type
depends_on = [platform-orchestrator_environment_type.development, platform-orchestrator_environment_type.production]
}

module "gcp-infra" {
source = "../gcp-infra"
for_each = toset(var.inputs.cloud == "gcp" ? ["this"] : [])
runtime = var.inputs.runtime
primary_resource = var.inputs.primary_resource
score_workload_resource_type = module.score-common.score_workload_resource_type
depends_on = [platform-orchestrator_environment_type.development, platform-orchestrator_environment_type.production]
}

module "azure-infra" {
source = "../azure-infra"
for_each = toset(var.inputs.cloud == "azure" ? ["this"] : [])
runtime = var.inputs.runtime
primary_resource = var.inputs.primary_resource
score_workload_resource_type = module.score-common.score_workload_resource_type
depends_on = [platform-orchestrator_environment_type.development, platform-orchestrator_environment_type.production]
}
61 changes: 61 additions & 0 deletions modules/infra/tests/test.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
mock_provider "platform-orchestrator" {}

run "test_aws_kubernetes" {
command = plan
variables {
inputs = {
cloud = "aws"
runtime = "kubernetes"
primary_resource = "postgres"
}
runner_config = {
region = "eu-central-1"
subnet_ids = ["subnet1", "subnet2"]
security_group_ids = []
humanitec_org_id = "example"
existing_ecs_cluster_name = "ecs-cluster"
oidc_hostname = "oidc.humanitec.dev"
existing_oidc_provider_arn = "arn"
}
}
}

run "test_gcp_kubernetes" {
command = plan
variables {
inputs = {
cloud = "gcp"
runtime = "kubernetes"
primary_resource = "postgres"
}
runner_config = {
region = "eu-central-1"
subnet_ids = ["subnet1", "subnet2"]
security_group_ids = []
humanitec_org_id = "example"
existing_ecs_cluster_name = "ecs-cluster"
oidc_hostname = "oidc.humanitec.dev"
existing_oidc_provider_arn = "arn"
}
}
}

run "test_azure_kubernetes" {
command = plan
variables {
inputs = {
cloud = "azure"
runtime = "kubernetes"
primary_resource = "postgres"
}
runner_config = {
region = "eu-central-1"
subnet_ids = ["subnet1", "subnet2"]
security_group_ids = []
humanitec_org_id = "example"
existing_ecs_cluster_name = "ecs-cluster"
oidc_hostname = "oidc.humanitec.dev"
existing_oidc_provider_arn = "arn"
}
}
}
Loading
Loading