Skip to content

Commit

Permalink
fix: update templated tf versions (#812)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin E. Coe <bencoe@google.com>
  • Loading branch information
bharathkkb and bcoe committed Mar 9, 2021
1 parent 4a9345b commit d222746
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
34 changes: 34 additions & 0 deletions __snapshots__/terraform-module.js
Expand Up @@ -250,6 +250,40 @@ terraform {
}
}
filename: versions.tf.tmpl
/**
* Copyright 2018 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
*
* http://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.
*/
{% if test %}
terraform {
required_version = ">=0.13, <0.14"
required_providers {
google = ">= 3.44.0, <4.0.0"
}
provider_meta "google" {
module_name = "foo/bar/baz/v12.1.1"
}
provider_meta "google-beta" {
module_name = "foo/bar/baz/v12.1.1"
}
}
{% endif %}
`

exports['terraform-module run creates a release PR for simple-module: options'] = `
Expand Down
9 changes: 7 additions & 2 deletions src/releasers/terraform-module.ts
Expand Up @@ -94,8 +94,13 @@ export class TerraformModule extends ReleasePR {
});

// Update versions.tf to current candidate version.
// A module may have submodules, so find all versions.tf to update.
const versionFiles = await this.gh.findFilesByFilename('versions.tf');
// A module may have submodules, so find all versions.tfand versions.tf.tmpl to update.
const versionFiles = await Promise.all([
this.gh.findFilesByFilename('versions.tf'),
this.gh.findFilesByFilename('versions.tf.tmpl'),
]).then(([v, vt]) => {
return v.concat(vt);
});
versionFiles.forEach(path => {
updates.push(
new ModuleVersion({
Expand Down
33 changes: 33 additions & 0 deletions test/releasers/fixtures/terraform/simple-module/versions.tf.tmpl
@@ -0,0 +1,33 @@
/**
* Copyright 2018 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
*
* http://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.
*/

{% if test %}
terraform {
required_version = ">=0.13, <0.14"

required_providers {
google = ">= 3.44.0, <4.0.0"
}

provider_meta "google" {
module_name = "foo/bar/baz/v12.0.0"
}

provider_meta "google-beta" {
module_name = "foo/bar/baz/v12.0.0"
}
}
{% endif %}
13 changes: 11 additions & 2 deletions test/releasers/terraform-module.ts
Expand Up @@ -34,8 +34,13 @@ describe('terraform-module', () => {
// simple-module with module versions defined
name: 'simple-module',
findVersionFiles: ['versions.tf'],
findTemplatedVersionFiles: ['versions.tf.tmpl'],
findReadmeFiles: ['readme.md'],
readFilePaths: ['simple-module/readme.md', 'simple-module/versions.tf'],
readFilePaths: [
'simple-module/readme.md',
'simple-module/versions.tf',
'simple-module/versions.tf.tmpl',
],
expectedVersion: '12.1.0',
},
{
Expand All @@ -47,6 +52,7 @@ describe('terraform-module', () => {
'versions.tf',
'modules/sub-module-with-version/versions.tf',
],
findTemplatedVersionFiles: [],
findReadmeFiles: [
'README.md',
'modules/sub-module-with-version/readme.md',
Expand All @@ -65,6 +71,7 @@ describe('terraform-module', () => {
// module-no-versions with no module versions defined in versions.tf
name: 'module-no-versions',
findVersionFiles: [],
findTemplatedVersionFiles: [],
findReadmeFiles: ['module-no-versions/README.MD'],
readFilePaths: ['module-no-versions/README.MD'],
expectedVersion: '2.1.0',
Expand Down Expand Up @@ -101,7 +108,9 @@ describe('terraform-module', () => {
.onFirstCall()
.returns(Promise.resolve(test.findReadmeFiles))
.onSecondCall()
.returns(Promise.resolve(test.findVersionFiles));
.returns(Promise.resolve(test.findVersionFiles))
.onThirdCall()
.returns(Promise.resolve(test.findTemplatedVersionFiles));

// Return latest tag used to determine next version #:
sandbox.stub(releasePR, 'latestTag').returns(
Expand Down

0 comments on commit d222746

Please sign in to comment.