Skip to content

Commit

Permalink
Add TeamCity testing project for ephemeral resources feature branch, …
Browse files Browse the repository at this point in the history
…clean up imports (GoogleCloudPlatform#11847)
  • Loading branch information
SarahFrench authored Oct 7, 2024
1 parent 43a7536 commit 5fe624f
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package builds

import DefaultTerraformCoreVersion
import jetbrains.buildServer.configs.kotlin.BuildSteps
import jetbrains.buildServer.configs.kotlin.buildSteps.ScriptBuildStep

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion mmv1/third_party/terraform/.teamcity/settings.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
)
}
}
}
4 changes: 2 additions & 2 deletions mmv1/third_party/terraform/.teamcity/tests/sweepers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5fe624f

Please sign in to comment.