-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add examples to terraform-module
- Loading branch information
Showing
5 changed files
with
236 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
exports['example.tf updateContent updates version in example.tf 1'] = ` | ||
/** | ||
* Copyright 2024-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 | ||
* | ||
* 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. | ||
*/ | ||
module "gke" { | ||
source = "terraform-google-modules/kubernetes-engine/google//modules/beta-autopilot-private-cluster" | ||
version = "~> 1.0" | ||
project_id = var.project_id | ||
name = "\${local.cluster_type}-cluster" | ||
regional = true | ||
region = var.region | ||
network = module.gcp-network.network_name | ||
subnetwork = local.subnet_names[index(module.gcp-network.subnets_names, local.subnet_name)] | ||
ip_range_pods = local.pods_range_name | ||
ip_range_services = local.svc_range_name | ||
release_channel = "REGULAR" | ||
enable_vertical_pod_autoscaling = true | ||
enable_private_endpoint = true | ||
enable_private_nodes = true | ||
master_ipv4_cidr_block = "172.16.0.0/28" | ||
add_cluster_firewall_rules = true | ||
add_master_webhook_firewall_rules = true | ||
add_shadow_firewall_rules = true | ||
network_tags = ["allow-google-apis"] | ||
deletion_protection = false | ||
enable_binary_authorization = true | ||
master_authorized_networks = [ | ||
{ | ||
cidr_block = "10.60.0.0/17" | ||
display_name = "VPC" | ||
}, | ||
] | ||
} | ||
` | ||
|
||
exports['versions.tf updateContent updates version in examples/**.tf 1'] = ` | ||
/** | ||
* Copyright 2024-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 | ||
* | ||
* 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. | ||
*/ | ||
module "gke" { | ||
source = "terraform-google-modules/kubernetes-engine/google//modules/beta-autopilot-private-cluster" | ||
version = "~> 1.0" | ||
project_id = var.project_id | ||
name = "\${local.cluster_type}-cluster" | ||
regional = true | ||
region = var.region | ||
network = module.gcp-network.network_name | ||
subnetwork = local.subnet_names[index(module.gcp-network.subnets_names, local.subnet_name)] | ||
ip_range_pods = local.pods_range_name | ||
ip_range_services = local.svc_range_name | ||
release_channel = "REGULAR" | ||
enable_vertical_pod_autoscaling = true | ||
enable_private_endpoint = true | ||
enable_private_nodes = true | ||
master_ipv4_cidr_block = "172.16.0.0/28" | ||
add_cluster_firewall_rules = true | ||
add_master_webhook_firewall_rules = true | ||
add_shadow_firewall_rules = true | ||
network_tags = ["allow-google-apis"] | ||
deletion_protection = false | ||
enable_binary_authorization = true | ||
master_authorized_networks = [ | ||
{ | ||
cidr_block = "10.60.0.0/17" | ||
display_name = "VPC" | ||
}, | ||
] | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2020-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 | ||
// | ||
// 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. | ||
|
||
import {DefaultUpdater} from '../default'; | ||
|
||
/** | ||
* Updates a Terraform module's examples versions. | ||
*/ | ||
export class ExampleVersion extends DefaultUpdater { | ||
/** | ||
* Given initial file contents, return updated contents. | ||
* @param {string} content The initial content | ||
* @returns {string} The updated content | ||
*/ | ||
updateContent(content: string): string { | ||
return content.replace( | ||
/version = "~> [\d]+.[\d]+"/, | ||
`version = "~> ${this.version.major}.${this.version.minor}"` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2020-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 | ||
// | ||
// 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. | ||
|
||
import {readFileSync} from 'fs'; | ||
import {resolve} from 'path'; | ||
import * as snapshot from 'snap-shot-it'; | ||
import {describe, it} from 'mocha'; | ||
import {ExampleVersion} from '../../src/updaters/terraform/example-version'; | ||
import {Version} from '../../src/version'; | ||
|
||
const fixturesPath = './test/updaters/fixtures'; | ||
|
||
describe('example.tf', () => { | ||
describe('updateContent', () => { | ||
it('updates version in example.tf', async () => { | ||
const oldContent = readFileSync( | ||
resolve(fixturesPath, './terraform-module/example.tf'), | ||
'utf8' | ||
).replace(/\r\n/g, '\n'); | ||
const version = new ExampleVersion({ | ||
version: Version.parse('2.1.0'), | ||
}); | ||
const newContent = version.updateContent(oldContent); | ||
snapshot(newContent); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2024-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 | ||
* | ||
* 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. | ||
*/ | ||
|
||
module "gke" { | ||
source = "terraform-google-modules/kubernetes-engine/google//modules/beta-autopilot-private-cluster" | ||
version = "~> 1.0" | ||
|
||
project_id = var.project_id | ||
name = "${local.cluster_type}-cluster" | ||
regional = true | ||
region = var.region | ||
network = module.gcp-network.network_name | ||
subnetwork = local.subnet_names[index(module.gcp-network.subnets_names, local.subnet_name)] | ||
ip_range_pods = local.pods_range_name | ||
ip_range_services = local.svc_range_name | ||
release_channel = "REGULAR" | ||
enable_vertical_pod_autoscaling = true | ||
enable_private_endpoint = true | ||
enable_private_nodes = true | ||
master_ipv4_cidr_block = "172.16.0.0/28" | ||
add_cluster_firewall_rules = true | ||
add_master_webhook_firewall_rules = true | ||
add_shadow_firewall_rules = true | ||
network_tags = ["allow-google-apis"] | ||
deletion_protection = false | ||
enable_binary_authorization = true | ||
|
||
master_authorized_networks = [ | ||
{ | ||
cidr_block = "10.60.0.0/17" | ||
display_name = "VPC" | ||
}, | ||
] | ||
} |