Skip to content

Commit

Permalink
Merge pull request #11 from johanneswuerbach/cloudsql
Browse files Browse the repository at this point in the history
feat: cloudsql
  • Loading branch information
johanneswuerbach authored Feb 22, 2024
2 parents 1dd1e70 + 4d4c063 commit 2e79e96
Show file tree
Hide file tree
Showing 37 changed files with 947 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The following resources are included:

* [dns/basic](./humanitec-resource-defs/dns/basic): GCP Cloud DNS `dns` resource.
* [gcs/basic](./humanitec-resource-defs/gcs/basic): A basic cloud storage bucket.
* [mysql/basic](./humanitec-resource-defs/mysql/basic): A `mysql` resource using GCP CloudSQL.
* [postgres/basic](./humanitec-resource-defs/postgres/basic): A `postgres` resource using GCP CloudSQL.
* [redis/basic](./humanitec-resource-defs/redis/basic): GCP Memorystore `redis` resource.

The `humanitec-resource-defs` directory includes the respective resource definitions.
Expand Down
59 changes: 59 additions & 0 deletions examples/mysql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Example: mysql resource based on GCP CloudSQL

This example configures a [mysql](https://developer.humanitec.com/platform-orchestrator/reference/resource-types/#mysql) Resource Definition using GCP CloudSQL.

The created Resource Definition can be used in your Score file using:

```yaml
resources:
...
db:
type: mysql
```
<!-- BEGIN_TF_DOCS -->
## Requirements
| Name | Version |
|------|---------|
| terraform | >= 1.3.0 |
| google | ~> 5.17 |
| humanitec | ~> 0 |
## Providers
| Name | Version |
|------|---------|
| google | ~> 5.17 |
| humanitec | ~> 0 |
## Modules
| Name | Source | Version |
|------|--------|---------|
| mysql | ../../humanitec-resource-defs/mysql/basic | n/a |
## Resources
| Name | Type |
|------|------|
| [google_compute_global_address.private_ip_address](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_global_address) | resource |
| [google_project_service.servicenetworking](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_service) | resource |
| [google_service_networking_connection.private_vpc_connection](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_networking_connection) | resource |
| [humanitec_application.example](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/application) | resource |
| [humanitec_resource_definition_criteria.mysql](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [google_compute_network.network](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_network) | data source |
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| credentials | n/a | `string` | n/a | yes |
| private\_network | The VPC network from which the Cloud SQL instance is accessible for private IP. | `string` | n/a | yes |
| project | n/a | `string` | n/a | yes |
| region | n/a | `string` | n/a | yes |
| name | Name of the example application | `string` | `"hum-rp-mysql-example"` | no |
| prefix | Prefix of the created resources | `string` | `"hum-rp-mysql-ex-"` | no |
| resource\_packs\_gcp\_rev | n/a | `string` | `"ref/heads/main"` | no |
| resource\_packs\_gcp\_url | n/a | `string` | `"https://github.com/humanitec-architecture/resource-packs-gcp.git"` | no |
<!-- END_TF_DOCS -->
52 changes: 52 additions & 0 deletions examples/mysql/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
resource "humanitec_application" "example" {
id = var.name
name = var.name
}

data "google_compute_network" "network" {
name = var.private_network
}

resource "google_project_service" "servicenetworking" {
service = "servicenetworking.googleapis.com"
disable_on_destroy = false
}

resource "google_compute_global_address" "private_ip_address" {
name = "${var.prefix}private-ip-address"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = data.google_compute_network.network.id
}

resource "google_service_networking_connection" "private_vpc_connection" {
network = data.google_compute_network.network.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_address.name]

depends_on = [google_project_service.servicenetworking]
}

module "mysql" {
source = "../../humanitec-resource-defs/mysql/basic"

prefix = var.prefix
resource_packs_gcp_rev = var.resource_packs_gcp_rev
resource_packs_gcp_url = var.resource_packs_gcp_url
project = var.project
region = var.region
credentials = var.credentials

database_version = "MYSQL_8_0"
tier = "db-f1-micro"
private_network = data.google_compute_network.network.id

depends_on = [google_service_networking_connection.private_vpc_connection]
}

resource "humanitec_resource_definition_criteria" "mysql" {
resource_definition_id = module.mysql.id
app_id = humanitec_application.example.id
force_delete = true
}
27 changes: 27 additions & 0 deletions examples/mysql/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.17"
}
humanitec = {
source = "humanitec/humanitec"
version = "~> 0"
}
}

required_version = ">= 1.3.0"
}

provider "humanitec" {}

provider "google" {
project = var.project
region = var.region
credentials = var.credentials

default_labels = {
"managed_by" = "terraform"
"source" = "github.com/humanitec-architecture/resource-pack-gcp"
}
}
15 changes: 15 additions & 0 deletions examples/mysql/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
credentials = ""

# Name of the example application
name = "hum-rp-mysql-example"

# Prefix of the created resources
prefix = "hum-rp-mysql-ex-"

# The VPC network from which the Cloud SQL instance is accessible for private IP.
private_network = ""

project = ""
region = ""
resource_packs_gcp_rev = "ref/heads/main"
resource_packs_gcp_url = "https://github.com/humanitec-architecture/resource-packs-gcp.git"
38 changes: 38 additions & 0 deletions examples/mysql/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
variable "name" {
description = "Name of the example application"
type = string
default = "hum-rp-mysql-example"
}

variable "resource_packs_gcp_rev" {
type = string
default = "ref/heads/main"
}

variable "resource_packs_gcp_url" {
type = string
default = "https://github.com/humanitec-architecture/resource-packs-gcp.git"
}

variable "prefix" {
description = "Prefix of the created resources"
type = string
default = "hum-rp-mysql-ex-"
}

variable "project" {
type = string
}

variable "region" {
type = string
}

variable "credentials" {
type = string
}

variable "private_network" {
type = string
description = "The VPC network from which the Cloud SQL instance is accessible for private IP."
}
59 changes: 59 additions & 0 deletions examples/postgres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Example: postgres resource based on GCP CloudSQL

This example configures a [postgres](https://developer.humanitec.com/platform-orchestrator/reference/resource-types/#postgres) Resource Definition using GCP CloudSQL.

The created Resource Definition can be used in your Score file using:

```yaml
resources:
...
db:
type: postgres
```
<!-- BEGIN_TF_DOCS -->
## Requirements
| Name | Version |
|------|---------|
| terraform | >= 1.3.0 |
| google | ~> 5.17 |
| humanitec | ~> 0 |
## Providers
| Name | Version |
|------|---------|
| google | ~> 5.17 |
| humanitec | ~> 0 |
## Modules
| Name | Source | Version |
|------|--------|---------|
| postgres | ../../humanitec-resource-defs/postgres/basic | n/a |
## Resources
| Name | Type |
|------|------|
| [google_compute_global_address.private_ip_address](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_global_address) | resource |
| [google_project_service.servicenetworking](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_service) | resource |
| [google_service_networking_connection.private_vpc_connection](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_networking_connection) | resource |
| [humanitec_application.example](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/application) | resource |
| [humanitec_resource_definition_criteria.postgres](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [google_compute_network.network](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_network) | data source |
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| credentials | n/a | `string` | n/a | yes |
| private\_network | The VPC network from which the Cloud SQL instance is accessible for private IP. | `string` | n/a | yes |
| project | n/a | `string` | n/a | yes |
| region | n/a | `string` | n/a | yes |
| name | Name of the example application | `string` | `"hum-rp-postgres-example"` | no |
| prefix | Prefix of the created resources | `string` | `"hum-rp-postgres-ex-"` | no |
| resource\_packs\_gcp\_rev | n/a | `string` | `"ref/heads/main"` | no |
| resource\_packs\_gcp\_url | n/a | `string` | `"https://github.com/humanitec-architecture/resource-packs-gcp.git"` | no |
<!-- END_TF_DOCS -->
52 changes: 52 additions & 0 deletions examples/postgres/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
resource "humanitec_application" "example" {
id = var.name
name = var.name
}

data "google_compute_network" "network" {
name = var.private_network
}

resource "google_project_service" "servicenetworking" {
service = "servicenetworking.googleapis.com"
disable_on_destroy = false
}

resource "google_compute_global_address" "private_ip_address" {
name = "${var.prefix}private-ip-address"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = data.google_compute_network.network.id
}

resource "google_service_networking_connection" "private_vpc_connection" {
network = data.google_compute_network.network.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_address.name]

depends_on = [google_project_service.servicenetworking]
}

module "postgres" {
source = "../../humanitec-resource-defs/postgres/basic"

prefix = var.prefix
resource_packs_gcp_rev = var.resource_packs_gcp_rev
resource_packs_gcp_url = var.resource_packs_gcp_url
project = var.project
region = var.region
credentials = var.credentials

database_version = "POSTGRES_15"
tier = "db-f1-micro"
private_network = data.google_compute_network.network.id

depends_on = [google_service_networking_connection.private_vpc_connection]
}

resource "humanitec_resource_definition_criteria" "postgres" {
resource_definition_id = module.postgres.id
app_id = humanitec_application.example.id
force_delete = true
}
27 changes: 27 additions & 0 deletions examples/postgres/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.17"
}
humanitec = {
source = "humanitec/humanitec"
version = "~> 0"
}
}

required_version = ">= 1.3.0"
}

provider "humanitec" {}

provider "google" {
project = var.project
region = var.region
credentials = var.credentials

default_labels = {
"managed_by" = "terraform"
"source" = "github.com/humanitec-architecture/resource-pack-gcp"
}
}
15 changes: 15 additions & 0 deletions examples/postgres/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
credentials = ""

# Name of the example application
name = "hum-rp-postgres-example"

# Prefix of the created resources
prefix = "hum-rp-postgres-ex-"

# The VPC network from which the Cloud SQL instance is accessible for private IP.
private_network = ""

project = ""
region = ""
resource_packs_gcp_rev = "ref/heads/main"
resource_packs_gcp_url = "https://github.com/humanitec-architecture/resource-packs-gcp.git"
Loading

0 comments on commit 2e79e96

Please sign in to comment.