-
Notifications
You must be signed in to change notification settings - Fork 132
chore: Migrate simple_cloud_run kitchen -> cft #404
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
base: main
Are you sure you want to change the base?
Changes from all commits
170a988
538f179
0d7eb7d
80c7021
e9c701f
5f7dac8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2025 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 | ||
// | ||
// 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() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
} |
There was a problem hiding this comment.
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.