Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added v2 service as submodule #200

Merged
merged 8 commits into from
Jun 5, 2024
Merged
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ docker_test_lint:
.PHONY: docker_generate_docs
docker_generate_docs:
docker run --rm -it \
-e ENABLE_BPMETADATA \
-v $(CURDIR):/workspace \
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
/bin/bash -c 'source /usr/local/bin/task_helper_functions.sh && generate_docs'
Expand Down
63 changes: 63 additions & 0 deletions examples/v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Cloud Run Service using v2 API Example

This example showcases the basic deployment of containerized applications on Cloud Run and IAM policy for the service.

The resources/services/activations/deletions that this example will create/trigger are:

* Creates a Cloud Run service with provided name and container
* Creates a Service Account to be used by Cloud Run Service.

## Assumptions and Prerequisites

This example assumes that below mentioned prerequisites are in place before consuming the example.

* All required APIs are enabled in the GCP Project

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| project\_id | The project ID to deploy to | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| observed\_generation | The generation of this Service currently serving traffic. |
| project\_id | Project ID of the service |
| service\_id | Unique Identifier for the created service with format projects/{{project}}/locations/{{location}}/services/{{name}} |
| service\_location | Location in which the Cloud Run service was created |
| service\_name | Name of the created service |
| service\_uri | The URL on which the deployed service is available |
| traffic\_statuses | Detailed status information for corresponding traffic targets. |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

## Requirements

These sections describe requirements for using this example.

### Software

* [Terraform](https://www.terraform.io/downloads.html) ~> v0.13+
* [Terraform Provider for GCP](https://github.com/terraform-providers/terraform-provider-google) ~> v5.0+
* [Terraform Provider for GCP Beta](https://github.com/terraform-providers/terraform-provider-google-beta) ~>
v5.0+

### Service Account

A service account can be used with required roles to execute this example:

* Cloud Run Admin: `roles/run.admin`

Know more about [Cloud Run Deployment Permissions](https://cloud.google.com/run/docs/reference/iam/roles#additional-configuration).

The [Project Factory module](https://registry.terraform.io/modules/terraform-google-modules/project-factory/google/latest) and the
[IAM module](https://registry.terraform.io/modules/terraform-google-modules/iam/google/latest) may be used in combination to provision a service account with the necessary roles applied.

### APIs

A project with the following APIs enabled must be used to host the main resource of this example:

* Google Cloud Run: `run.googleapis.com`
39 changes: 39 additions & 0 deletions examples/v2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module "service_account" {
source = "terraform-google-modules/service-accounts/google"
version = "~> 4.2"
project_id = var.project_id
prefix = "sa-cloud-run"
names = ["simple"]
}

module "cloud_run_v2" {
source = "GoogleCloudPlatform/cloud-run/google//modules/v2"
version = "~> 0.10"

service_name = "ci-cloud-run-v2"
project_id = var.project_id
location = "us-central1"
containers = [
{
container_image = "us-docker.pkg.dev/cloudrun/container/hello"
container_name = "hello-world"
}
]
service_account = module.service_account.email
}
50 changes: 50 additions & 0 deletions examples/v2/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

output "project_id" {
value = module.cloud_run_v2.project_id
description = "Project ID of the service"
}

output "service_name" {
value = module.cloud_run_v2.service_name
description = "Name of the created service"
}

output "service_uri" {
value = module.cloud_run_v2.service_uri
description = "The URL on which the deployed service is available"
}

output "service_id" {
value = module.cloud_run_v2.service_id
description = "Unique Identifier for the created service with format projects/{{project}}/locations/{{location}}/services/{{name}}"
}

output "service_location" {
value = module.cloud_run_v2.location
description = "Location in which the Cloud Run service was created"
}

output "traffic_statuses" {
value = module.cloud_run_v2.traffic_statuses
description = "Detailed status information for corresponding traffic targets."
}

output "observed_generation" {
value = module.cloud_run_v2.observed_generation
description = "The generation of this Service currently serving traffic."
}
20 changes: 20 additions & 0 deletions examples/v2/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

variable "project_id" {
description = "The project ID to deploy to"
type = string
}
Loading