Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ docker_test_integration:
-e TF_VAR_project_id \
-v "$(CURDIR)":/workspace \
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
/usr/local/bin/test_integration.sh
cft test run all
27 changes: 6 additions & 21 deletions build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,19 @@ steps:
# - 'TF_VAR_create_access_context_manager_access_policy=false'
# waitFor:
# - prepare
- id: create
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create']
waitFor:
- prepare
- id: converge
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge']
- id: simple-cloud-run
waitFor:
- create
- id: verify
- prepare
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify']
waitFor:
- converge
- id: destroy
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy']
waitFor:
- verify
- id: create all
args: ['/bin/bash', '-c', 'cft test run TestSimpleCloudRun --verbose']
- id: create cloud-run-with-cmek
waitFor:
- destroy
- simple-cloud-run
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && source_test_env && init_credentials && cft test run TestCloudRunWithCMEK --test-dir test/integration --stage init --verbose']
- id: converge cloud-run-with-cmek
waitFor:
- create all
- create cloud-run-with-cmek
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && source_test_env && init_credentials && cft test run TestCloudRunWithCMEK --test-dir test/integration --stage apply --verbose']
- id: verify cloud-run-with-cmek
Expand Down
40 changes: 0 additions & 40 deletions kitchen.yml

This file was deleted.

30 changes: 0 additions & 30 deletions test/integration/simple_cloud_run/controls/gcloud.rb

This file was deleted.

28 changes: 0 additions & 28 deletions test/integration/simple_cloud_run/inspec.yml

This file was deleted.

48 changes: 48 additions & 0 deletions test/integration/simple_cloud_run/simple_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2025 Google LLC
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was just copied from the simple_cloud_run_with_cmek test and lightly edited.

//
// 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
//
// https://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.

package simple_cloud_run

import (
"fmt"
"testing"

"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
"github.com/stretchr/testify/assert"
)

func TestSimpleCloudRun(t *testing.T) {
cloudRun := tft.NewTFBlueprintTest(t)

cloudRun.DefineVerify(
func(assert *assert.Assertions) {
projectID := cloudRun.GetStringOutput("project_id")
location := cloudRun.GetStringOutput("service_location")
serviceName := cloudRun.GetStringOutput("service_name")
serviceStatus := cloudRun.GetStringOutput("service_status")

gcProjectOps := gcloud.WithCommonArgs([]string{"--project", projectID, "--format", "json"})
projectOp := gcloud.Run(t, "services list --enabled --filter='config.name=run.googleapis.com'", gcProjectOps).Array()[0]

assert.Equal("run.googleapis.com", projectOp.Get("config").Get("name").String(), "should have the right API enabled")

gcOps := gcloud.WithCommonArgs([]string{"--project", projectID, "--region", location, "--format", "json"})

op := gcloud.Run(t, fmt.Sprintf("run services list --filter=metadata.name=%q", serviceName), gcOps).Array()[0]

assert.Equal(serviceStatus, op.Get("status").Get("conditions").Array()[0].Get("type").String(), "should have the right service status")
})
cloudRun.Test()
}
15 changes: 8 additions & 7 deletions test/setup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,14 @@ module "project" {
source = "terraform-google-modules/project-factory/google"
version = "~> 17.0"

name = "ci-cloud-run"
random_project_id = "true"
org_id = var.org_id
folder_id = var.folder_id
billing_account = var.billing_account
default_service_account = "keep"
deletion_policy = "DELETE"
name = "ci-cloud-run"
random_project_id = "true"
random_project_id_length = 8
Copy link
Author

@martijnvans martijnvans Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is here to help with an "already exists" error I ran into while testing. Without this setting, we were using 16 bits for a "unique" name. After this setting, it will be 41 bits.

I did some calculations and if 50 projects are currently in use, there is a (roughly) 4% chance that there will be a naming clash among them. This gets reduced to a 1 in 10^10 chance with 41 bits.

I don't know whether the "already exists" error I saw was due to a collision, but using a longer project ID length will at least rule out this as a possible issue.

org_id = var.org_id
folder_id = var.folder_id
billing_account = var.billing_account
default_service_account = "keep"
deletion_policy = "DELETE"

activate_apis = flatten(values(local.per_module_services))
}
Loading