From 7e66f3a26f2f08ccb77d801b009546f32efd99de Mon Sep 17 00:00:00 2001 From: Sarah French <15078782+SarahFrench@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:18:40 +0100 Subject: [PATCH] Add TeamCity testing project for ephemeral resources feature branch, clean up imports (#11847) --- .../components/builds/build_steps.kt | 1 - .../FEATURE-BRANCH-ephemeral-resource.kt | 102 ++++++++++++++++++ .../components/projects/reused/mm_upstream.kt | 7 +- .../projects/reused/vcr_recording.kt | 3 +- .../components/projects/root_project.kt | 5 + .../terraform/.teamcity/settings.kts | 2 +- .../FEATURE-BRANCH-ephemeral-resource.kt | 79 ++++++++++++++ .../terraform/.teamcity/tests/sweepers.kt | 4 +- 8 files changed, 192 insertions(+), 11 deletions(-) create mode 100644 mmv1/third_party/terraform/.teamcity/components/projects/feature_branches/FEATURE-BRANCH-ephemeral-resource.kt create mode 100644 mmv1/third_party/terraform/.teamcity/tests/FEATURE-BRANCH-ephemeral-resource.kt diff --git a/mmv1/third_party/terraform/.teamcity/components/builds/build_steps.kt b/mmv1/third_party/terraform/.teamcity/components/builds/build_steps.kt index 68d9aa0a0206..2f1ce2a79ad5 100644 --- a/mmv1/third_party/terraform/.teamcity/components/builds/build_steps.kt +++ b/mmv1/third_party/terraform/.teamcity/components/builds/build_steps.kt @@ -7,7 +7,6 @@ package builds -import DefaultTerraformCoreVersion import jetbrains.buildServer.configs.kotlin.BuildSteps import jetbrains.buildServer.configs.kotlin.buildSteps.ScriptBuildStep diff --git a/mmv1/third_party/terraform/.teamcity/components/projects/feature_branches/FEATURE-BRANCH-ephemeral-resource.kt b/mmv1/third_party/terraform/.teamcity/components/projects/feature_branches/FEATURE-BRANCH-ephemeral-resource.kt new file mode 100644 index 000000000000..de3e5f426229 --- /dev/null +++ b/mmv1/third_party/terraform/.teamcity/components/projects/feature_branches/FEATURE-BRANCH-ephemeral-resource.kt @@ -0,0 +1,102 @@ +/* + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +// This file is maintained in the GoogleCloudPlatform/magic-modules repository and copied into the downstream provider repositories. Any changes to this file in the downstream will be overwritten. + +package projects.feature_branches + +import ProviderNameBeta +import ProviderNameGa +import SharedResourceNameBeta +import SharedResourceNameGa +import SharedResourceNameVcr +import builds.* +import generated.ServicesListBeta +import generated.ServicesListGa +import jetbrains.buildServer.configs.kotlin.Project +import replaceCharsId +import vcs_roots.HashiCorpVCSRootBeta +import vcs_roots.HashiCorpVCSRootGa +import vcs_roots.ModularMagicianVCSRootBeta +import vcs_roots.ModularMagicianVCSRootGa + +const val featureBranchEphemeralResources = "FEATURE-BRANCH-ephemeral-resource" +const val EphemeralResourcesTfCoreVersion = "1.10.0-alpha20240926" // TODO - update with correct release + +// featureBranchEphemeralResourcesSubProject creates a project just for testing ephemeral resources. +// We know that all ephemeral resources we're adding are part of the Resource Manager service, so we only include those builds. +// We create builds for testing the resourcemanager service: +// - Against the GA hashicorp repo +// - Against the GA modular-magician repo +// - Against the Beta hashicorp repo +// - Against the Beta modular-magician repo +// These resemble existing projects present in TeamCity, but these all use a more recent version of Terraform including +// the new ephemeral values feature. +fun featureBranchEphemeralResourcesSubProject(allConfig: AllContextParameters): Project { + + val projectId = replaceCharsId(featureBranchEphemeralResources) + + val packageName = "resourcemanager" // All ephemeral resources will be in the resourcemanager package + val vcrConfig = getVcrAcceptanceTestConfig(allConfig) // Reused below for both MM testing build configs + val trigger = NightlyTriggerConfiguration( + branch = "refs/heads/$featureBranchEphemeralResources" // triggered builds must test the feature branch + ) + + + // GA + val gaConfig = getGaAcceptanceTestConfig(allConfig) + // How to make only build configuration to the relevant package(s) + val resourceManagerPackageGa = ServicesListGa.getValue(packageName) + + // Enable testing using hashicorp/terraform-provider-google + var parentId = "${projectId}_HC_GA" + val buildConfigHashiCorpGa = BuildConfigurationForSinglePackage(packageName, resourceManagerPackageGa.getValue("path"), "Ephemeral resources in $packageName (GA provider, HashiCorp downstream)", ProviderNameGa, parentId, HashiCorpVCSRootGa, listOf(SharedResourceNameGa), gaConfig) + buildConfigHashiCorpGa.addTrigger(trigger) + + // Enable testing using modular-magician/terraform-provider-google + parentId = "${projectId}_MM_GA" + val buildConfigModularMagicianGa = BuildConfigurationForSinglePackage(packageName, resourceManagerPackageGa.getValue("path"), "Ephemeral resources in $packageName (GA provider, MM upstream)", ProviderNameGa, parentId, ModularMagicianVCSRootGa, listOf(SharedResourceNameVcr), vcrConfig) + // No trigger added here (MM upstream is manual only) + + // Beta + val betaConfig = getBetaAcceptanceTestConfig(allConfig) + val resourceManagerPackageBeta = ServicesListBeta.getValue(packageName) + + // Enable testing using hashicorp/terraform-provider-google-beta + parentId = "${projectId}_HC_BETA" + val buildConfigHashiCorpBeta = BuildConfigurationForSinglePackage(packageName, resourceManagerPackageBeta.getValue("path"), "Ephemeral resources in $packageName (Beta provider, HashiCorp downstream)", ProviderNameBeta, parentId, HashiCorpVCSRootBeta, listOf(SharedResourceNameBeta), betaConfig) + buildConfigHashiCorpBeta.addTrigger(trigger) + + // Enable testing using modular-magician/terraform-provider-google-beta + parentId = "${projectId}_MM_BETA" + val buildConfigModularMagicianBeta = BuildConfigurationForSinglePackage(packageName, resourceManagerPackageBeta.getValue("path"), "Ephemeral resources in $packageName (Beta provider, MM upstream)", ProviderNameBeta, parentId, ModularMagicianVCSRootBeta, listOf(SharedResourceNameVcr), vcrConfig) + // No trigger added here (MM upstream is manual only) + + + // ------ + + // Make all builds use a 1.10.0-ish version of TF core + val allBuildConfigs = listOf(buildConfigHashiCorpGa, buildConfigModularMagicianGa, buildConfigHashiCorpBeta, buildConfigModularMagicianBeta) + allBuildConfigs.forEach{ b -> + b.overrideTerraformCoreVersion(EphemeralResourcesTfCoreVersion) + } + + // ------ + + return Project{ + id(projectId) + name = featureBranchEphemeralResources + description = "Subproject for testing feature branch $featureBranchEphemeralResources" + + // Register all build configs in the project + allBuildConfigs.forEach{ b -> + buildType(b) + } + + params { + readOnlySettings() + } + } +} \ No newline at end of file diff --git a/mmv1/third_party/terraform/.teamcity/components/projects/reused/mm_upstream.kt b/mmv1/third_party/terraform/.teamcity/components/projects/reused/mm_upstream.kt index 288df583bf25..7d1d79b15b63 100644 --- a/mmv1/third_party/terraform/.teamcity/components/projects/reused/mm_upstream.kt +++ b/mmv1/third_party/terraform/.teamcity/components/projects/reused/mm_upstream.kt @@ -14,12 +14,7 @@ import ServiceSweeperCronName import ServiceSweeperManualName import SharedResourceNameVcr import builds.* -import generated.PackagesListBeta -import generated.PackagesListGa -import generated.ServicesListBeta -import generated.ServicesListGa -import generated.SweepersListBeta -import generated.SweepersListGa +import generated.* import jetbrains.buildServer.configs.kotlin.BuildType import jetbrains.buildServer.configs.kotlin.Project import jetbrains.buildServer.configs.kotlin.vcs.GitVcsRoot diff --git a/mmv1/third_party/terraform/.teamcity/components/projects/reused/vcr_recording.kt b/mmv1/third_party/terraform/.teamcity/components/projects/reused/vcr_recording.kt index 8df65299015f..89d6ffa04431 100644 --- a/mmv1/third_party/terraform/.teamcity/components/projects/reused/vcr_recording.kt +++ b/mmv1/third_party/terraform/.teamcity/components/projects/reused/vcr_recording.kt @@ -9,7 +9,8 @@ package projects.reused import SharedResourceNameVcr import VcrRecordingProjectId -import builds.* +import builds.AccTestConfiguration +import builds.VcrDetails import jetbrains.buildServer.configs.kotlin.Project import jetbrains.buildServer.configs.kotlin.vcs.GitVcsRoot import replaceCharsId diff --git a/mmv1/third_party/terraform/.teamcity/components/projects/root_project.kt b/mmv1/third_party/terraform/.teamcity/components/projects/root_project.kt index 7130a9c35ea8..d0a4308a2702 100644 --- a/mmv1/third_party/terraform/.teamcity/components/projects/root_project.kt +++ b/mmv1/third_party/terraform/.teamcity/components/projects/root_project.kt @@ -18,6 +18,7 @@ import generated.ServicesListBeta import generated.ServicesListGa import jetbrains.buildServer.configs.kotlin.Project import jetbrains.buildServer.configs.kotlin.sharedResource +import projects.feature_branches.featureBranchEphemeralResourcesSubProject // googleCloudRootProject returns a root project that contains a subprojects for the GA and Beta version of the // Google provider. There are also resources to help manage the test projects used for acceptance tests. @@ -62,6 +63,10 @@ fun googleCloudRootProject(allConfig: AllContextParameters): Project { subProject(googleSubProjectBeta(allConfig)) subProject(projectSweeperSubProject(allConfig)) + // Feature branch-testing projects - these will be added and removed as needed + subProject(featureBranchEphemeralResourcesSubProject(allConfig)) + + params { readOnlySettings() } diff --git a/mmv1/third_party/terraform/.teamcity/settings.kts b/mmv1/third_party/terraform/.teamcity/settings.kts index 518323d7bdef..ac329c4bd6b3 100644 --- a/mmv1/third_party/terraform/.teamcity/settings.kts +++ b/mmv1/third_party/terraform/.teamcity/settings.kts @@ -5,9 +5,9 @@ // This file is maintained in the GoogleCloudPlatform/magic-modules repository and copied into the downstream provider repositories. Any changes to this file in the downstream will be overwritten. -import projects.googleCloudRootProject import builds.AllContextParameters import jetbrains.buildServer.configs.kotlin.* +import projects.googleCloudRootProject version = "2024.03" diff --git a/mmv1/third_party/terraform/.teamcity/tests/FEATURE-BRANCH-ephemeral-resource.kt b/mmv1/third_party/terraform/.teamcity/tests/FEATURE-BRANCH-ephemeral-resource.kt new file mode 100644 index 000000000000..9b52c2c9d2fe --- /dev/null +++ b/mmv1/third_party/terraform/.teamcity/tests/FEATURE-BRANCH-ephemeral-resource.kt @@ -0,0 +1,79 @@ +/* + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +// This file is maintained in the GoogleCloudPlatform/magic-modules repository and copied into the downstream provider repositories. Any changes to this file in the downstream will be overwritten. + +package tests + +import jetbrains.buildServer.configs.kotlin.triggers.ScheduleTrigger +import org.junit.Assert +import org.junit.Test +import projects.feature_branches.featureBranchEphemeralResources +import projects.googleCloudRootProject + +class FeatureBranchEphemeralResourcesSubProject { + @Test + fun buildsUsingHashiCorpReposAreOnSchedule() { + val root = googleCloudRootProject(testContextParameters()) + + // Find feature branch project + val project = getSubProject(root, featureBranchEphemeralResources) + + // All builds using the HashiCorp owned GitHub repos + val hashiBuilds = project.buildTypes.filter { bt -> + bt.name.contains("HashiCorp downstream") + } + + hashiBuilds.forEach{bt -> + Assert.assertTrue( + "Build configuration `${bt.name}` should contain at least one trigger", + bt.triggers.items.isNotEmpty() + ) + // Look for at least one CRON trigger + var found = false + lateinit var schedulingTrigger: ScheduleTrigger + for (item in bt.triggers.items){ + if (item.type == "schedulingTrigger") { + schedulingTrigger = item as ScheduleTrigger + found = true + break + } + } + + Assert.assertTrue( + "Build configuration `${bt.name}` should contain a CRON/'schedulingTrigger' trigger", + found + ) + + // Check that triggered builds are being run on the feature branch + val isCorrectBranch: Boolean = schedulingTrigger.branchFilter == "+:refs/heads/$featureBranchEphemeralResources" + + Assert.assertTrue( + "Build configuration `${bt.name}` is using the $featureBranchEphemeralResources branch filter", + isCorrectBranch + ) + } + } + + @Test + fun buildsUsingModularMagicianReposAreNotTriggered() { + val root = googleCloudRootProject(testContextParameters()) + + // Find feature branch project + val project = getSubProject(root, featureBranchEphemeralResources) + + // All builds using the HashiCorp owned GitHub repos + val magicianBuilds = project.buildTypes.filter { bt -> + bt.name.contains("MM upstream") + } + + magicianBuilds.forEach{bt -> + Assert.assertTrue( + "Build configuration `${bt.name}` should not have any triggers", + bt.triggers.items.isEmpty() + ) + } + } +} diff --git a/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt b/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt index f6babaa4807a..6fd5c9e0efc0 100644 --- a/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt +++ b/mmv1/third_party/terraform/.teamcity/tests/sweepers.kt @@ -8,9 +8,9 @@ package tests import ProjectSweeperName -import ServiceSweeperName import ServiceSweeperCronName import ServiceSweeperManualName +import ServiceSweeperName import jetbrains.buildServer.configs.kotlin.BuildType import jetbrains.buildServer.configs.kotlin.Project import jetbrains.buildServer.configs.kotlin.triggers.ScheduleTrigger @@ -136,7 +136,7 @@ class SweeperTests { // Find Project sweeper project's build val projectSweeperProject = getSubProject(root, projectSweeperProjectName) - val projectSweeper: BuildType = getBuildFromProject(projectSweeperProject!!, ProjectSweeperName) + val projectSweeper: BuildType = getBuildFromProject(projectSweeperProject, ProjectSweeperName) // Check only one schedule trigger is on the builds in question assertTrue(sweeperGa.triggers.items.size == 1)