Skip to content

Commit e75074d

Browse files
authored
TeamCity: Add project for testing the provider functions feature branch (#10088)
* Add ability to use non-default versions of Terraform in TeamCity builds * Add function to enable making build configs for single packages at a time * Add new sub project that contains 2 builds for testing provider functions the 2 builds: 1) only pulls code from the feature branch on the downstream hashicorp/terraform-provider-google repo 2) only pulls code from the feature branch on the downstream hashicorp/terraform-provider-google-beta repo These builds both use an alpha release of TF 1.8.0 * Add builds for testing auto generated branches in the MM upstream repos These re-use existing VCR Roots. * Make the builds that test the `FEATURE-BRANCH-provider-functions branches in the downstream repos run every night at the default time * Fix defect in 'Download Terraform' build step definition * Update build step to solve bug * Update build_configuration_per_package.kt
1 parent 12b3ce1 commit e75074d

File tree

6 files changed

+142
-7
lines changed

6 files changed

+142
-7
lines changed

mmv1/third_party/terraform/.teamcity/components/builds/build_configuration_per_package.kt

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import jetbrains.buildServer.configs.kotlin.sharedResources
1515
import jetbrains.buildServer.configs.kotlin.vcs.GitVcsRoot
1616
import replaceCharsId
1717

18+
// BuildConfigurationsForPackages accepts a map containing details of multiple packages in a provider and returns a list of build configurations for them all.
19+
// Intended to be used in projects where we're testing all packages, e.g. the nightly test projects
1820
fun BuildConfigurationsForPackages(packages: Map<String, Map<String, String>>, providerName: String, parentProjectName: String, vcsRoot: GitVcsRoot, sharedResources: List<String>, environmentVariables: AccTestConfiguration): List<BuildType> {
1921
val list = ArrayList<BuildType>()
2022

@@ -31,6 +33,13 @@ fun BuildConfigurationsForPackages(packages: Map<String, Map<String, String>>, p
3133
return list
3234
}
3335

36+
// BuildConfigurationForSinglePackage accepts details of a single package in a provider and returns a build configuration for it
37+
// Intended to be used in short-lived projects where we're testing specific packages, e.g. feature branch testing
38+
fun BuildConfigurationForSinglePackage(packageName: String, packagePath: String, packageDisplayName: String, providerName: String, parentProjectName: String, vcsRoot: GitVcsRoot, sharedResources: List<String>, environmentVariables: AccTestConfiguration): BuildType{
39+
val pkg = PackageDetails(packageName, packageDisplayName, providerName, parentProjectName)
40+
return pkg.buildConfiguration(packagePath, vcsRoot, sharedResources, environmentVariables)
41+
}
42+
3443
class PackageDetails(private val packageName: String, private val displayName: String, private val providerName: String, private val parentProjectName: String) {
3544

3645
// buildConfiguration returns a BuildType for a service package
@@ -102,4 +111,4 @@ class PackageDetails(private val packageName: String, private val displayName: S
102111
var id = "%s_%s_PACKAGE_%s".format(this.parentProjectName, this.providerName, this.packageName)
103112
return replaceCharsId(id)
104113
}
105-
}
114+
}

mmv1/third_party/terraform/.teamcity/components/builds/build_parameters.kt

+11-3
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,20 @@ fun ParametrizedWithType.readOnlySettings() {
252252
}
253253

254254
// ParametrizedWithType.terraformCoreBinaryTesting sets environment variables that control what Terraform version is downloaded
255-
// and ensures the testing framework uses that downloaded version
256-
fun ParametrizedWithType.terraformCoreBinaryTesting() {
257-
text("env.TERRAFORM_CORE_VERSION", DefaultTerraformCoreVersion, "The version of Terraform Core which should be used for testing")
255+
// and ensures the testing framework uses that downloaded version. The default Terraform core version is used if no argument is supplied.
256+
fun ParametrizedWithType.terraformCoreBinaryTesting(tfVersion: String = DefaultTerraformCoreVersion) {
257+
text("env.TERRAFORM_CORE_VERSION", tfVersion, "The version of Terraform Core which should be used for testing")
258258
hiddenVariable("env.TF_ACC_TERRAFORM_PATH", "%system.teamcity.build.checkoutDir%/tools/terraform", "The path where the Terraform Binary is located. Used by the testing framework.")
259259
}
260260

261+
// BuildType.overrideTerraformCoreVersion is used to override the value of TERRAFORM_CORE_VERSION in special cases where we're testing new features
262+
// that rely on a specific version of Terraform we might not want to be used for all our tests in TeamCity.
263+
fun BuildType.overrideTerraformCoreVersion(tfVersion: String){
264+
params {
265+
terraformCoreBinaryTesting(tfVersion)
266+
}
267+
}
268+
261269
fun ParametrizedWithType.terraformShouldPanicForSchemaErrors() {
262270
hiddenVariable("env.TF_SCHEMA_PANIC_ON_ERROR", "1", "Panic if unknown/unmatched fields are set into the state")
263271
}

mmv1/third_party/terraform/.teamcity/components/builds/build_steps.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ fun BuildSteps.downloadTerraformBinary() {
6464
// https://releases.hashicorp.com/terraform/0.12.28/terraform_0.12.28_linux_amd64.zip
6565
val terraformUrl = "https://releases.hashicorp.com/terraform/%env.TERRAFORM_CORE_VERSION%/terraform_%env.TERRAFORM_CORE_VERSION%_linux_amd64.zip"
6666
step(ScriptBuildStep {
67-
name = "Download Terraform version %s".format(DefaultTerraformCoreVersion)
67+
name = "Download Terraform"
6868
scriptContent = """
6969
#!/bin/bash
70+
echo "Downloading Terraform version %env.TERRAFORM_CORE_VERSION%"
7071
mkdir -p tools
71-
wget -O tf.zip %s
72+
wget -O tf.zip $terraformUrl
7273
unzip tf.zip
7374
mv terraform tools/
74-
""".format(terraformUrl).trimIndent()
75+
""".trimIndent()
7576
})
7677
}
7778

mmv1/third_party/terraform/.teamcity/components/inputs/packages.kt

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ var PackagesListGa = mapOf(
1313
"displayName" to "Environment Variables",
1414
"path" to "./google/envvar"
1515
),
16+
"functions" to mapOf(
17+
"name" to "functions",
18+
"displayName" to "Provider-Defined Functions",
19+
"path" to "./google/functions"
20+
),
1621
"fwmodels" to mapOf(
1722
"name" to "fwmodels",
1823
"displayName" to "Framework Models",
@@ -64,6 +69,11 @@ var PackagesListBeta = mapOf(
6469
"displayName" to "Environment Variables",
6570
"path" to "./google-beta/envvar"
6671
),
72+
"functions" to mapOf(
73+
"name" to "functions",
74+
"displayName" to "Provider-Defined Functions",
75+
"path" to "./google-beta/functions"
76+
),
6777
"fwmodels" to mapOf(
6878
"name" to "fwmodels",
6979
"displayName" to "Framework Models",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
// This file is controlled by MMv1, any changes made here will be overwritten
7+
8+
package projects.feature_branches
9+
10+
import ProviderNameBeta
11+
import ProviderNameGa
12+
import builds.*
13+
import generated.PackagesListBeta
14+
import generated.PackagesListGa
15+
import jetbrains.buildServer.configs.kotlin.Project
16+
import jetbrains.buildServer.configs.kotlin.vcs.GitVcsRoot
17+
import replaceCharsId
18+
import vcs_roots.ModularMagicianVCSRootBeta
19+
import vcs_roots.ModularMagicianVCSRootGa
20+
21+
const val featureBranchProviderFunctionsName = "FEATURE-BRANCH-provider-functions"
22+
const val providerFunctionsTfCoreVersion = "1.8.0-alpha20240228"
23+
24+
// VCS Roots specifically for pulling code from the feature branches in the downstream and upstream repos
25+
object HashicorpVCSRootGa_featureBranchProviderFunctions: GitVcsRoot({
26+
name = "VCS root for the hashicorp/terraform-provider-${ProviderNameGa} repo @ refs/heads/${featureBranchProviderFunctionsName}"
27+
url = "https://github.com/hashicorp/terraform-provider-${ProviderNameGa}"
28+
branch = "refs/heads/${featureBranchProviderFunctionsName}"
29+
branchSpec = "" // empty as we'll access no other branches
30+
})
31+
32+
object HashicorpVCSRootBeta_featureBranchProviderFunctions: GitVcsRoot({
33+
name = "VCS root for the hashicorp/terraform-provider-${ProviderNameBeta} repo @ refs/heads/${featureBranchProviderFunctionsName}"
34+
url = "https://github.com/hashicorp/terraform-provider-${ProviderNameBeta}"
35+
branch = "refs/heads/${featureBranchProviderFunctionsName}"
36+
branchSpec = "" // empty as we'll access no other branches
37+
})
38+
39+
fun featureBranchProviderFunctionSubProject(allConfig: AllContextParameters): Project {
40+
41+
val projectId = replaceCharsId(featureBranchProviderFunctionsName)
42+
43+
val packageName = "functions" // This project will contain only builds to test this single package
44+
val sharedResourcesEmpty: List<String> = listOf() // No locking when testing functions
45+
val vcrConfig = getVcrAcceptanceTestConfig(allConfig) // Reused below for both MM testing build configs
46+
val trigger = NightlyTriggerConfiguration() // Resued below for running tests against the downstream repos every night.
47+
48+
var parentId: String // To be overwritten when each build config is generated below.
49+
50+
// GA
51+
val gaConfig = getGaAcceptanceTestConfig(allConfig)
52+
// How to make only build configuration to the relevant package(s)
53+
val functionPackageGa = PackagesListGa.getValue(packageName)
54+
55+
// Enable testing using hashicorp/terraform-provider-google
56+
parentId = "${projectId}_HC_GA"
57+
val buildConfigHashiCorpGa = BuildConfigurationForSinglePackage(packageName, functionPackageGa.getValue("path"), "Provider-Defined Functions (GA provider, HashiCorp downstream)", ProviderNameGa, parentId, HashicorpVCSRootGa_featureBranchProviderFunctions, sharedResourcesEmpty, gaConfig)
58+
buildConfigHashiCorpGa.addTrigger(trigger)
59+
60+
// Enable testing using modular-magician/terraform-provider-google
61+
parentId = "${projectId}_MM_GA"
62+
val buildConfigModularMagicianGa = BuildConfigurationForSinglePackage(packageName, functionPackageGa.getValue("path"), "Provider-Defined Functions (GA provider, MM upstream)", ProviderNameGa, parentId, ModularMagicianVCSRootGa, sharedResourcesEmpty, vcrConfig)
63+
64+
// Beta
65+
val betaConfig = getBetaAcceptanceTestConfig(allConfig)
66+
val functionPackageBeta = PackagesListBeta.getValue("functions")
67+
68+
// Enable testing using hashicorp/terraform-provider-google-beta
69+
parentId = "${projectId}_HC_BETA"
70+
val buildConfigHashiCorpBeta = BuildConfigurationForSinglePackage(packageName, functionPackageBeta.getValue("path"), "Provider-Defined Functions (Beta provider, HashiCorp downstream)", ProviderNameBeta, parentId, HashicorpVCSRootBeta_featureBranchProviderFunctions, sharedResourcesEmpty, betaConfig)
71+
buildConfigHashiCorpBeta.addTrigger(trigger)
72+
73+
// Enable testing using modular-magician/terraform-provider-google-beta
74+
parentId = "${projectId}_MM_BETA"
75+
val buildConfigModularMagicianBeta = BuildConfigurationForSinglePackage(packageName, functionPackageBeta.getValue("path"), "Provider-Defined Functions (Beta provider, MM upstream)", ProviderNameBeta, parentId, ModularMagicianVCSRootBeta, sharedResourcesEmpty, vcrConfig)
76+
77+
val allBuildConfigs = listOf(buildConfigHashiCorpGa, buildConfigModularMagicianGa, buildConfigHashiCorpBeta, buildConfigModularMagicianBeta)
78+
79+
// Make these builds use a 1.8.0-ish version of TF core
80+
allBuildConfigs.forEach{ b ->
81+
b.overrideTerraformCoreVersion(providerFunctionsTfCoreVersion)
82+
}
83+
84+
return Project{
85+
id(projectId)
86+
name = featureBranchProviderFunctionsName
87+
description = "Subproject for testing feature branch $featureBranchProviderFunctionsName"
88+
89+
// Register feature branch-specific VCS roots in the project
90+
vcsRoot(HashicorpVCSRootGa_featureBranchProviderFunctions)
91+
vcsRoot(HashicorpVCSRootBeta_featureBranchProviderFunctions)
92+
93+
// Register all build configs in the project
94+
allBuildConfigs.forEach{ b ->
95+
buildType(b)
96+
}
97+
98+
params {
99+
readOnlySettings()
100+
}
101+
}
102+
}

mmv1/third_party/terraform/.teamcity/components/projects/root_project.kt

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import generated.ServicesListBeta
1818
import generated.ServicesListGa
1919
import jetbrains.buildServer.configs.kotlin.Project
2020
import jetbrains.buildServer.configs.kotlin.sharedResource
21+
import projects.feature_branches.featureBranchProviderFunctionSubProject
2122

2223
// googleCloudRootProject returns a root project that contains a subprojects for the GA and Beta version of the
2324
// Google provider. There are also resources to help manage the test projects used for acceptance tests.
@@ -57,10 +58,14 @@ fun googleCloudRootProject(allConfig: AllContextParameters): Project {
5758
}
5859
}
5960

61+
// Projects required for nightly testing, testing MM upstreams, and sweepers
6062
subProject(googleSubProjectGa(allConfig))
6163
subProject(googleSubProjectBeta(allConfig))
6264
subProject(projectSweeperSubProject(allConfig))
6365

66+
// Feature branch-testing projects - these will be added and removed as needed
67+
subProject(featureBranchProviderFunctionSubProject(allConfig))
68+
6469
params {
6570
readOnlySettings()
6671
}

0 commit comments

Comments
 (0)