-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: pubsub resource * chore: rename to delegator * chore: expand score examples * chore: improved readme
- Loading branch information
1 parent
2e79e96
commit e8a4ec0
Showing
97 changed files
with
1,352 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Example: gcp-pubsub resource based on Google Cloud Pub/Sub | ||
|
||
This example configures a [gcp-pubsub-topic](https://developer.humanitec.com/platform-orchestrator/reference/resource-types/#gcp-pubsub-topic) and a [gcp-pubsub-subscription](https://developer.humanitec.com/platform-orchestrator/reference/resource-types/#gcp-pubsub-subscription) Resource Definition using Google Cloud Pub/Sub. | ||
|
||
The Resource Graph is using [delegator resources](https://developer.humanitec.com/platform-orchestrator/examples/resource-graph-patterns/#delegator-resource) to expose shared resources with different access policies. | ||
|
||
Those Resource Definitions can be used in your Score file using: | ||
|
||
```yaml | ||
# publishing workload | ||
containers: | ||
app: | ||
... | ||
variables: | ||
TOPIC_NAME: ${resources.topic.name} | ||
resources: | ||
... | ||
topic: | ||
metadata: | ||
annotations: | ||
score.humanitec.io/resId: shared.main-topic | ||
type: gcp-pubsub-topic | ||
class: basic-publisher | ||
``` | ||
```yaml | ||
# subscribing workload | ||
containers: | ||
app: | ||
... | ||
variables: | ||
SUBSCRIPTION_NAME: ${resources.subscription.name} | ||
resources: | ||
... | ||
subscription: | ||
type: gcp-pubsub-subscription | ||
class: basic-subscriber | ||
params: | ||
topic_name: ${resources['gcp-pubsub-topic.basic#shared.main-topic'].outputs.name} | ||
``` | ||
The workload service account will automatically be assigned the necessary GCP Service Account with the selected role bindings. | ||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
| Name | Version | | ||
|------|---------| | ||
| terraform | >= 1.3.0 | | ||
| humanitec | ~> 0 | | ||
## Providers | ||
| Name | Version | | ||
|------|---------| | ||
| humanitec | ~> 0 | | ||
## Modules | ||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| gcp\_service\_account\_workload | ../../humanitec-resource-defs/gcp-service-account/workload | n/a | | ||
| gps\_basic\_subscriber | ../../humanitec-resource-defs/gcp-pubsub-subscription/delegator | n/a | | ||
| gpt\_basic\_publisher | ../../humanitec-resource-defs/gcp-pubsub-topic/delegator | n/a | | ||
| iam\_role\_binding\_gcp\_pubsub\_subscription\_subscriber | ../../humanitec-resource-defs/gcp-iam-policy-binding/basic | n/a | | ||
| iam\_role\_binding\_gcp\_pubsub\_topic\_publisher | ../../humanitec-resource-defs/gcp-iam-policy-binding/basic | n/a | | ||
| k8s\_service\_account | ../../humanitec-resource-defs/k8s/service-account | n/a | | ||
| pubsub\_subscription\_basic | ../../humanitec-resource-defs/gcp-pubsub-subscription/basic | n/a | | ||
| pubsub\_topic\_basic | ../../humanitec-resource-defs/gcp-pubsub-topic/basic | n/a | | ||
| workload | ../../humanitec-resource-defs/workload/service-account | n/a | | ||
## Resources | ||
| Name | Type | | ||
|------|------| | ||
| [humanitec_application.example](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/application) | resource | | ||
| [humanitec_resource_definition_criteria.gcp_service_account_workload](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource | | ||
| [humanitec_resource_definition_criteria.gps_basic_subscriber](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource | | ||
| [humanitec_resource_definition_criteria.gpt_basic_publisher](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource | | ||
| [humanitec_resource_definition_criteria.iam_role_binding_gcp_pubsub_subscription_subscriber](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource | | ||
| [humanitec_resource_definition_criteria.iam_role_binding_gcp_pubsub_topic_publisher](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource | | ||
| [humanitec_resource_definition_criteria.k8s_service_account](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource | | ||
| [humanitec_resource_definition_criteria.pubsub_subscription_basic](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource | | ||
| [humanitec_resource_definition_criteria.pubsub_topic_basic](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource | | ||
| [humanitec_resource_definition_criteria.workload](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource | | ||
## Inputs | ||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| credentials | GCP credentials | `string` | n/a | yes | | ||
| project | GCP project ID | `string` | n/a | yes | | ||
| name | Name of the example application | `string` | `"hum-rp-gcp-pubsub-example"` | no | | ||
| prefix | n/a | `string` | `"hum-rp-gcp-pubsub-ex-"` | no | | ||
| resource\_packs\_gcp\_rev | GCP Resource Pack git ref | `string` | `"refs/heads/main"` | no | | ||
| resource\_packs\_gcp\_url | GCP Resource Pack git url | `string` | `"https://github.com/humanitec-architecture/resource-packs-gcp.git"` | no | | ||
<!-- END_TF_DOCS --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
resource "humanitec_application" "example" { | ||
id = var.name | ||
name = var.name | ||
} | ||
|
||
# GCP pubsub | ||
|
||
locals { | ||
# Classes used to build the resource definition graph | ||
gpt_basic_class = "basic" | ||
gps_basic_class = "basic" | ||
gpt_publisher_policy_class = "gcp-pubsub-subscription-basic-publisher" | ||
gps_subscriber_policy_class = "gcp-pubsub-subscription-basic-subscriber" | ||
|
||
# Classes that developers can select from | ||
gpt_basic_publisher_class = "basic-publisher" | ||
gps_basic_subscriber_class = "basic-subscriber" | ||
} | ||
|
||
# Required resources for workload identity | ||
|
||
module "k8s_service_account" { | ||
source = "../../humanitec-resource-defs/k8s/service-account" | ||
|
||
prefix = var.prefix | ||
} | ||
|
||
resource "humanitec_resource_definition_criteria" "k8s_service_account" { | ||
resource_definition_id = module.k8s_service_account.id | ||
app_id = humanitec_application.example.id | ||
force_delete = true | ||
} | ||
|
||
module "gcp_service_account_workload" { | ||
source = "../../humanitec-resource-defs/gcp-service-account/workload" | ||
|
||
resource_packs_gcp_url = var.resource_packs_gcp_url | ||
resource_packs_gcp_rev = var.resource_packs_gcp_rev | ||
|
||
project = var.project | ||
credentials = var.credentials | ||
prefix = var.prefix | ||
|
||
name = "hrp-ps-$${context.res.id}" | ||
} | ||
|
||
resource "humanitec_resource_definition_criteria" "gcp_service_account_workload" { | ||
resource_definition_id = module.gcp_service_account_workload.id | ||
app_id = humanitec_application.example.id | ||
force_delete = true | ||
} | ||
|
||
module "workload" { | ||
source = "../../humanitec-resource-defs/workload/service-account" | ||
|
||
prefix = var.prefix | ||
} | ||
|
||
resource "humanitec_resource_definition_criteria" "workload" { | ||
resource_definition_id = module.workload.id | ||
app_id = humanitec_application.example.id | ||
force_delete = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
terraform { | ||
required_providers { | ||
humanitec = { | ||
source = "humanitec/humanitec" | ||
version = "~> 0" | ||
} | ||
} | ||
|
||
required_version = ">= 1.3.0" | ||
} | ||
|
||
provider "humanitec" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# gcp pubsub subscription related resources | ||
|
||
module "pubsub_subscription_basic" { | ||
source = "../../humanitec-resource-defs/gcp-pubsub-subscription/basic" | ||
|
||
resource_packs_gcp_url = var.resource_packs_gcp_url | ||
resource_packs_gcp_rev = var.resource_packs_gcp_rev | ||
|
||
project = var.project | ||
credentials = var.credentials | ||
prefix = var.prefix | ||
} | ||
|
||
resource "humanitec_resource_definition_criteria" "pubsub_subscription_basic" { | ||
resource_definition_id = module.pubsub_subscription_basic.id | ||
app_id = humanitec_application.example.id | ||
class = local.gps_basic_class | ||
force_delete = true | ||
} | ||
|
||
# policy | ||
|
||
module "iam_role_binding_gcp_pubsub_subscription_subscriber" { | ||
source = "../../humanitec-resource-defs/gcp-iam-policy-binding/basic" | ||
|
||
prefix = var.prefix | ||
name = "gcp-pubsub-subscription-basic-subscriber" | ||
|
||
type = "pubsub_subscription" | ||
scope_key = "subscription" | ||
scope_value = "$${resources['gcp-pubsub-subscription.${local.gps_basic_class}'].outputs.name}" | ||
role = "roles/pubsub.subscriber" | ||
} | ||
|
||
resource "humanitec_resource_definition_criteria" "iam_role_binding_gcp_pubsub_subscription_subscriber" { | ||
resource_definition_id = module.iam_role_binding_gcp_pubsub_subscription_subscriber.id | ||
app_id = humanitec_application.example.id | ||
class = local.gps_subscriber_policy_class | ||
force_delete = true | ||
} | ||
|
||
## Exposed delegator resource definition | ||
|
||
module "gps_basic_subscriber" { | ||
source = "../../humanitec-resource-defs/gcp-pubsub-subscription/delegator" | ||
|
||
prefix = var.prefix | ||
|
||
gps_resource_class = local.gps_basic_class | ||
policy_resource_class = local.gps_subscriber_policy_class | ||
} | ||
|
||
resource "humanitec_resource_definition_criteria" "gps_basic_subscriber" { | ||
resource_definition_id = module.gps_basic_subscriber.id | ||
app_id = humanitec_application.example.id | ||
class = local.gps_basic_subscriber_class | ||
force_delete = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# gcp pubsub topic related resources | ||
|
||
module "pubsub_topic_basic" { | ||
source = "../../humanitec-resource-defs/gcp-pubsub-topic/basic" | ||
|
||
resource_packs_gcp_url = var.resource_packs_gcp_url | ||
resource_packs_gcp_rev = var.resource_packs_gcp_rev | ||
|
||
project = var.project | ||
credentials = var.credentials | ||
prefix = var.prefix | ||
} | ||
|
||
resource "humanitec_resource_definition_criteria" "pubsub_topic_basic" { | ||
resource_definition_id = module.pubsub_topic_basic.id | ||
app_id = humanitec_application.example.id | ||
class = local.gpt_basic_class | ||
force_delete = true | ||
} | ||
|
||
# policy | ||
|
||
module "iam_role_binding_gcp_pubsub_topic_publisher" { | ||
source = "../../humanitec-resource-defs/gcp-iam-policy-binding/basic" | ||
|
||
prefix = var.prefix | ||
name = "gcp-pubsub-topic-basic-publisher" | ||
|
||
type = "pubsub_topic" | ||
scope_key = "topic" | ||
scope_value = "$${resources['gcp-pubsub-topic.${local.gpt_basic_class}'].outputs.name}" | ||
role = "roles/pubsub.publisher" | ||
} | ||
|
||
resource "humanitec_resource_definition_criteria" "iam_role_binding_gcp_pubsub_topic_publisher" { | ||
resource_definition_id = module.iam_role_binding_gcp_pubsub_topic_publisher.id | ||
app_id = humanitec_application.example.id | ||
class = local.gpt_publisher_policy_class | ||
force_delete = true | ||
} | ||
|
||
## Exposed delegator resource definition | ||
|
||
module "gpt_basic_publisher" { | ||
source = "../../humanitec-resource-defs/gcp-pubsub-topic/delegator" | ||
|
||
prefix = var.prefix | ||
|
||
gpt_resource_class = local.gpt_basic_class | ||
policy_resource_class = local.gpt_publisher_policy_class | ||
} | ||
|
||
resource "humanitec_resource_definition_criteria" "gpt_basic_publisher" { | ||
resource_definition_id = module.gpt_basic_publisher.id | ||
app_id = humanitec_application.example.id | ||
class = local.gpt_basic_publisher_class | ||
force_delete = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
# GCP credentials | ||
credentials = "" | ||
|
||
# Name of the example application | ||
name = "hum-rp-gcp-pubsub-example" | ||
|
||
prefix = "hum-rp-gcp-pubsub-ex-" | ||
|
||
# GCP project ID | ||
project = "" | ||
|
||
# GCP Resource Pack git ref | ||
resource_packs_gcp_rev = "refs/heads/main" | ||
|
||
# GCP Resource Pack git url | ||
resource_packs_gcp_url = "https://github.com/humanitec-architecture/resource-packs-gcp.git" |
Oops, something went wrong.