Skip to content

Commit

Permalink
Fixed gcp datacenter and added depends_on feature to datacenter modules
Browse files Browse the repository at this point in the history
  • Loading branch information
davidthor committed Jan 10, 2024
1 parent f9960ab commit bf75f44
Show file tree
Hide file tree
Showing 33 changed files with 440 additions and 82 deletions.
1 change: 1 addition & 0 deletions examples/datacenters/gcp/database/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
11 changes: 10 additions & 1 deletion examples/datacenters/gcp/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ if (!inputs) {
type Config = {
name: string;
cluster_id: string;
region: string;
project: string;
credentials: string;
};

const config: Config = JSON.parse(inputs);

const provider = new gcp.Provider('gcp-provider', {
credentials: config.credentials,
project: config.project,
region: config.region,
});

const database = new gcp.sql.Database(config.name, {
name: `db-${config.name}`.replace(/\//g, '-'),
instance: config.cluster_id,
});
}, { provider });

export const name = database.name;
1 change: 1 addition & 0 deletions examples/datacenters/gcp/databaseCluster/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
15 changes: 11 additions & 4 deletions examples/datacenters/gcp/databaseCluster/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as gcp from "@pulumi/gcp";
import * as pulumi from "@pulumi/pulumi";
import { randomUUID } from 'crypto';

const inputs = process.env.INPUTS;
Expand All @@ -9,6 +8,9 @@ if (!inputs) {

type Config = {
name: string;
region: string;
project: string;
credentials: string;
databasePort: number;
databaseVersion: string;
databaseSize?: string;
Expand All @@ -17,11 +19,16 @@ type Config = {

const config: Config = JSON.parse(inputs);

const gcpConfig = new pulumi.Config('gcp');
const provider = new gcp.Provider('gcp-provider', {
credentials: config.credentials,
project: config.project,
region: config.region,
});

const _port = config.databasePort;

const databaseInstance = new gcp.sql.DatabaseInstance(config.name, {
region: gcpConfig.require('region'),
region: config.region,
name: config.name,
databaseVersion: config.databaseVersion,
rootPassword: randomUUID(),
Expand All @@ -33,7 +40,7 @@ const databaseInstance = new gcp.sql.DatabaseInstance(config.name, {
},
},
deletionProtection: false
});
}, { provider });

export const id = databaseInstance.id;
export const private_host = databaseInstance.privateIpAddress;
Expand Down
10 changes: 8 additions & 2 deletions examples/datacenters/gcp/databaseUser/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@

config = json.loads(inputs)

provider = gcp.Provider("provider",
project=config["project"],
region=config["region"],
credentials=config["credentials"])

project_service = gcp.projects.Service("database-service",
disable_on_destroy=False,
service="sqladmin.googleapis.com")
service="sqladmin.googleapis.com",
opts=pulumi.ResourceOptions(provider=provider))

password = uuid.uuid4()

Expand All @@ -21,7 +27,7 @@
instance=config["cluster_id"],
password=password.hex,
deletion_policy="ABANDON",
opts=pulumi.ResourceOptions(depends_on=[project_service]))
opts=pulumi.ResourceOptions(provider=provider,depends_on=[project_service]))

pulumi.export("id", sql_user.name)
pulumi.export("username", sql_user.name)
Expand Down
91 changes: 63 additions & 28 deletions examples/datacenters/gcp/datacenter.arc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ variable "gcp_project" {
}

variable "gcp_region" {
description = "GCP region in which to create resources"
description = "GCP region in which to create resources"
type = "string"
}

Expand All @@ -20,26 +20,39 @@ variable "dns_zone" {

module "vpc" {
build = "./vpc"

volume {
mount_path = "/credentials.json"
host_path = var.gcp_credentials_file
}

inputs = {
name = datacenter.name

"gcp:region" = var.gcp_region
"gcp:project" = var.gcp_project
"gcp:credentials" = "file:${var.gcp_credentials_file}"
region = var.gcp_region
project = var.gcp_project
credentials = "/credentials.json"
}
}

module "kubernetesCluster" {
build = "./kubernetesCluster"
inputs = {
name = datacenter.name

"gcp:region" = var.gcp_region
"gcp:project" = var.gcp_project
"gcp:credentials" = "file:${var.gcp_credentials_file}"
volume {
mount_path = "/credentials.json"
host_path = var.gcp_credentials_file
}

"kubernetes:nodePools": "[{\"count\":1,\"name\":\"test-pool\",\"nodeSize\":\"e2-small\"}]"
"kubernetes:vpc" = module.vpc.name
inputs = {
name = datacenter.name
region = var.gcp_region
project = var.gcp_project
credentials = "/credentials.json"
nodePools = [{
"count": 1,
"name": "test-pool",
"nodeSize": "e2-small"
}]
vpc = module.vpc.name
}
}

Expand All @@ -55,17 +68,22 @@ environment {
module "databaseCluster" {
when = contains(environment.nodes.*.type, "database") && contains(environment.nodes.*.inputs.databaseType, "postgres")
build = "./databaseCluster"

volume {
mount_path = "/credentials.json"
host_path = var.gcp_credentials_file
}

inputs = {
name = "${datacenter.name}-database"
databaseType = "pg"
databaseVersion = "POSTGRES_14"
databasePort = 5432
region = variable.gcp_region
vpcId = module.vpc.id

"gcp:region" = var.gcp_region
"gcp:project" = var.gcp_project
"gcp:credentials" = "file:${var.gcp_credentials_file}"
region = var.gcp_region
project = var.gcp_project
credentials = "/credentials.json"
}
}

Expand All @@ -76,7 +94,7 @@ environment {
kubeconfig = module.kubernetesCluster.kubeconfig
chart = "ingress-nginx"
repo = "https://kubernetes.github.io/ingress-nginx"
namespace = "kube-system"
namespace = module.namespace.id
values = {
controller = {
ingressClass = "nginx"
Expand Down Expand Up @@ -108,12 +126,18 @@ environment {

module "database" {
build = "./database"

volume {
mount_path = "/credentials.json"
host_path = var.gcp_credentials_file
}

inputs = {
cluster_id = module.databaseCluster.id
name = node.inputs.name
"gcp:region" = var.gcp_region
"gcp:project" = var.gcp_project
"gcp:credentials" = "file:${var.gcp_credentials_file}"
region = var.gcp_region
project = var.gcp_project
credentials = "/credentials.json"
}
}

Expand All @@ -131,13 +155,18 @@ environment {
databaseUser {
module "databaseUser" {
build = "./databaseUser"

volume {
mount_path = "/credentials.json"
host_path = var.gcp_credentials_file
}

inputs = {
cluster_id = module.databaseCluster.id
name = node.inputs.name

"gcp:region" = var.gcp_region
"gcp:project" = var.gcp_project
"gcp:credentials" = "file:${var.gcp_credentials_file}"
region = var.gcp_region
project = var.gcp_project
credentials = "/credentials.json"
}

# TTL of 1 day
Expand All @@ -158,6 +187,7 @@ environment {
ingress {
module "ingressRule" {
build = "./kubernetesIngress"
depends_on = ["nginxController"]
inputs = merge(node.inputs, {
name = "${node.component}--${node.name}"
namespace = module.namespace.id
Expand All @@ -169,15 +199,20 @@ environment {

module "dnsRecord" {
build = "./dnsRecord"

volume {
mount_path = "/credentials.json"
host_path = var.gcp_credentials_file
}

inputs = {
domain = variable.dns_zone
type = "A"
value = module.ingressRule.load_balancer_ip
subdomain = node.inputs.subdomain

"gcp:region" = var.gcp_region
"gcp:project" = var.gcp_project
"gcp:credentials" = "file:${var.gcp_credentials_file}"
region = var.gcp_region
project = var.gcp_project
credentials = "/credentials.json"
}
}

Expand Down
1 change: 1 addition & 0 deletions examples/datacenters/gcp/dnsRecord/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
11 changes: 10 additions & 1 deletion examples/datacenters/gcp/dnsRecord/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ type Config = {
domain: string;
type: string;
value: string;
region: string;
project: string;
credentials: string;
};

const config: Config = JSON.parse(inputs);

const provider = new gcp.Provider('gcp-provider', {
credentials: config.credentials,
project: config.project,
region: config.region,
});

const subdomain = config.subdomain;
const zone = config.domain;

Expand All @@ -22,6 +31,6 @@ const dnsRecord = new gcp.dns.RecordSet('dns_record', {
managedZone: zone.replace('.', '-'),
type: config.type,
rrdatas: config.value.split(','),
});
}, { provider });

export const id = dnsRecord.id;
1 change: 1 addition & 0 deletions examples/datacenters/gcp/gateway/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions examples/datacenters/gcp/gceDeployment/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions examples/datacenters/gcp/gceService/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 2 additions & 1 deletion examples/datacenters/gcp/helm-chart/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ COPY . .

RUN npm install

ENV PULUMI_CONFIG_PASSPHRASE="passphrase"
ENV PULUMI_CONFIG_PASSPHRASE="passphrase"
ENV PULUMI_K8S_DELETE_UNREACHABLE="true"
5 changes: 4 additions & 1 deletion examples/datacenters/gcp/helm-chart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (!inputs) {
}

type Config = {
id?: string;
repo?: string;
kubeconfig: string;
chart: string;
Expand All @@ -31,4 +32,6 @@ new kubernetes.helm.v3.Chart('chart', {
version: config.version,
fetchOpts,
values: config.values,
}, { provider });
}, { provider });

export const id = config.id;
1 change: 1 addition & 0 deletions examples/datacenters/gcp/ingressRule/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions examples/datacenters/gcp/kubernetesCluster/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Loading

0 comments on commit bf75f44

Please sign in to comment.