From e35f27834ff0e6328f5b15bd8b9902fadf5e8110 Mon Sep 17 00:00:00 2001 From: Ivan Orlov Date: Fri, 21 Apr 2023 06:57:33 +0000 Subject: [PATCH] Add golden copy tests for terraform IGC * Add golden copy tests for terraform IGC * Improve usability of validate_golden_copy by printing absolute pathes --- .../.ghpc/deployment_metadata.yaml | 37 ++++++++++++++ .../golden_copies/terraform_igc/one/main.tf | 29 +++++++++++ .../terraform_igc/one/outputs.tf | 15 ++++++ .../terraform_igc/one/providers.tf | 27 ++++++++++ .../terraform_igc/one/terraform.tfvars | 23 +++++++++ .../terraform_igc/one/variables.tf | 50 +++++++++++++++++++ .../terraform_igc/one/versions.tf | 30 +++++++++++ .../golden_copies/terraform_igc/zero/main.tf | 22 ++++++++ .../terraform_igc/zero/outputs.tf | 31 ++++++++++++ .../terraform_igc/zero/providers.tf | 25 ++++++++++ .../terraform_igc/zero/terraform.tfvars | 22 ++++++++ .../terraform_igc/zero/variables.tf | 35 +++++++++++++ .../terraform_igc/zero/versions.tf | 30 +++++++++++ .../test_configs/igc_tf_test.yaml | 38 ++++++++++++++ .../validate_configs/validate_golden_copy.sh | 4 +- 15 files changed, 417 insertions(+), 1 deletion(-) create mode 100644 tools/validate_configs/golden_copies/terraform_igc/.ghpc/deployment_metadata.yaml create mode 100644 tools/validate_configs/golden_copies/terraform_igc/one/main.tf create mode 100644 tools/validate_configs/golden_copies/terraform_igc/one/outputs.tf create mode 100644 tools/validate_configs/golden_copies/terraform_igc/one/providers.tf create mode 100644 tools/validate_configs/golden_copies/terraform_igc/one/terraform.tfvars create mode 100644 tools/validate_configs/golden_copies/terraform_igc/one/variables.tf create mode 100644 tools/validate_configs/golden_copies/terraform_igc/one/versions.tf create mode 100644 tools/validate_configs/golden_copies/terraform_igc/zero/main.tf create mode 100644 tools/validate_configs/golden_copies/terraform_igc/zero/outputs.tf create mode 100644 tools/validate_configs/golden_copies/terraform_igc/zero/providers.tf create mode 100644 tools/validate_configs/golden_copies/terraform_igc/zero/terraform.tfvars create mode 100644 tools/validate_configs/golden_copies/terraform_igc/zero/variables.tf create mode 100644 tools/validate_configs/golden_copies/terraform_igc/zero/versions.tf create mode 100644 tools/validate_configs/test_configs/igc_tf_test.yaml diff --git a/tools/validate_configs/golden_copies/terraform_igc/.ghpc/deployment_metadata.yaml b/tools/validate_configs/golden_copies/terraform_igc/.ghpc/deployment_metadata.yaml new file mode 100644 index 0000000000..884c57600c --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/.ghpc/deployment_metadata.yaml @@ -0,0 +1,37 @@ +# Copyright 2023 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. + +deployment_metadata: + - name: zero + deployment_inputs: + - deployment_name + - labels + - project_id + - region + intergroup_inputs: [] + outputs: + - nat_ips_network0 + - network_id_network0 + - subnetwork_name_network0 + - name: one + deployment_inputs: + - deployment_name + - labels + - project_id + - region + - zone + intergroup_inputs: + - network_id_network0 + - subnetwork_name_network0 + outputs: [] diff --git a/tools/validate_configs/golden_copies/terraform_igc/one/main.tf b/tools/validate_configs/golden_copies/terraform_igc/one/main.tf new file mode 100644 index 0000000000..8ebc4ab315 --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/one/main.tf @@ -0,0 +1,29 @@ +/** + * Copyright 2023 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 "homefs" { + source = "./modules/embedded/modules/file-system/filestore" + deployment_name = var.deployment_name + labels = merge(var.labels, { + ghpc_role = "file-system" + }) + local_mount = "/home" + name = var.subnetwork_name_network0 + network_id = var.network_id_network0 + project_id = var.project_id + region = var.region + zone = var.zone +} + diff --git a/tools/validate_configs/golden_copies/terraform_igc/one/outputs.tf b/tools/validate_configs/golden_copies/terraform_igc/one/outputs.tf new file mode 100644 index 0000000000..3a497ec474 --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/one/outputs.tf @@ -0,0 +1,15 @@ +/** + * Copyright 2023 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. + */ diff --git a/tools/validate_configs/golden_copies/terraform_igc/one/providers.tf b/tools/validate_configs/golden_copies/terraform_igc/one/providers.tf new file mode 100644 index 0000000000..a86fa04a75 --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/one/providers.tf @@ -0,0 +1,27 @@ +/** + * Copyright 2023 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. + */ +provider "google" { + project = var.project_id + zone = var.zone + region = var.region +} + +provider "google-beta" { + project = var.project_id + zone = var.zone + region = var.region +} + diff --git a/tools/validate_configs/golden_copies/terraform_igc/one/terraform.tfvars b/tools/validate_configs/golden_copies/terraform_igc/one/terraform.tfvars new file mode 100644 index 0000000000..6b9284baf5 --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/one/terraform.tfvars @@ -0,0 +1,23 @@ +/** + * Copyright 2023 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. + */ +deployment_name = "golden_copy_deployment" +labels = { + ghpc_blueprint = "igc" + ghpc_deployment = "golden_copy_deployment" +} +project_id = "invalid-project" +region = "us-east4" +zone = "us-east4-c" diff --git a/tools/validate_configs/golden_copies/terraform_igc/one/variables.tf b/tools/validate_configs/golden_copies/terraform_igc/one/variables.tf new file mode 100644 index 0000000000..15028ea137 --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/one/variables.tf @@ -0,0 +1,50 @@ +/** + * Copyright 2023 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. + */ + +variable "deployment_name" { + description = "Toolkit deployment variable: deployment_name" + type = string +} + +variable "labels" { + description = "Toolkit deployment variable: labels" + type = any +} + +variable "network_id_network0" { + description = "Toolkit automatically generated variable: network_id_network0" + type = any +} + +variable "project_id" { + description = "Toolkit deployment variable: project_id" + type = string +} + +variable "region" { + description = "Toolkit deployment variable: region" + type = string +} + +variable "subnetwork_name_network0" { + description = "Toolkit automatically generated variable: subnetwork_name_network0" + type = any +} + +variable "zone" { + description = "Toolkit deployment variable: zone" + type = string +} diff --git a/tools/validate_configs/golden_copies/terraform_igc/one/versions.tf b/tools/validate_configs/golden_copies/terraform_igc/one/versions.tf new file mode 100644 index 0000000000..548eac4908 --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/one/versions.tf @@ -0,0 +1,30 @@ +/** + * Copyright 2023 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. + */ + +terraform { + required_version = ">= 0.13" + + required_providers { + google = { + source = "hashicorp/google" + version = "~> 4.61.0" + } + google-beta = { + source = "hashicorp/google-beta" + version = "~> 4.61.0" + } + } +} diff --git a/tools/validate_configs/golden_copies/terraform_igc/zero/main.tf b/tools/validate_configs/golden_copies/terraform_igc/zero/main.tf new file mode 100644 index 0000000000..d6dd0d475e --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/zero/main.tf @@ -0,0 +1,22 @@ +/** + * Copyright 2023 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 "network0" { + source = "./modules/embedded/modules/network/vpc" + deployment_name = var.deployment_name + project_id = var.project_id + region = var.region +} + diff --git a/tools/validate_configs/golden_copies/terraform_igc/zero/outputs.tf b/tools/validate_configs/golden_copies/terraform_igc/zero/outputs.tf new file mode 100644 index 0000000000..6260db8bde --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/zero/outputs.tf @@ -0,0 +1,31 @@ +/** + * Copyright 2023 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. + */ + +output "nat_ips_network0" { + description = "Generated output from module 'network0'" + value = module.network0.nat_ips +} + +output "subnetwork_name_network0" { + description = "Generated output from module 'network0'" + value = module.network0.subnetwork_name +} + +output "network_id_network0" { + description = "Automatically-generated output exported for use by later deployment groups" + value = module.network0.network_id + sensitive = true +} diff --git a/tools/validate_configs/golden_copies/terraform_igc/zero/providers.tf b/tools/validate_configs/golden_copies/terraform_igc/zero/providers.tf new file mode 100644 index 0000000000..43820be7ea --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/zero/providers.tf @@ -0,0 +1,25 @@ +/** + * Copyright 2023 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. + */ +provider "google" { + project = var.project_id + region = var.region +} + +provider "google-beta" { + project = var.project_id + region = var.region +} + diff --git a/tools/validate_configs/golden_copies/terraform_igc/zero/terraform.tfvars b/tools/validate_configs/golden_copies/terraform_igc/zero/terraform.tfvars new file mode 100644 index 0000000000..b077e42e94 --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/zero/terraform.tfvars @@ -0,0 +1,22 @@ +/** + * Copyright 2023 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. + */ +deployment_name = "golden_copy_deployment" +labels = { + ghpc_blueprint = "igc" + ghpc_deployment = "golden_copy_deployment" +} +project_id = "invalid-project" +region = "us-east4" diff --git a/tools/validate_configs/golden_copies/terraform_igc/zero/variables.tf b/tools/validate_configs/golden_copies/terraform_igc/zero/variables.tf new file mode 100644 index 0000000000..1bc3f154da --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/zero/variables.tf @@ -0,0 +1,35 @@ +/** + * Copyright 2023 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. + */ + +variable "deployment_name" { + description = "Toolkit deployment variable: deployment_name" + type = string +} + +variable "labels" { + description = "Toolkit deployment variable: labels" + type = any +} + +variable "project_id" { + description = "Toolkit deployment variable: project_id" + type = string +} + +variable "region" { + description = "Toolkit deployment variable: region" + type = string +} diff --git a/tools/validate_configs/golden_copies/terraform_igc/zero/versions.tf b/tools/validate_configs/golden_copies/terraform_igc/zero/versions.tf new file mode 100644 index 0000000000..548eac4908 --- /dev/null +++ b/tools/validate_configs/golden_copies/terraform_igc/zero/versions.tf @@ -0,0 +1,30 @@ +/** + * Copyright 2023 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. + */ + +terraform { + required_version = ">= 0.13" + + required_providers { + google = { + source = "hashicorp/google" + version = "~> 4.61.0" + } + google-beta = { + source = "hashicorp/google-beta" + version = "~> 4.61.0" + } + } +} diff --git a/tools/validate_configs/test_configs/igc_tf_test.yaml b/tools/validate_configs/test_configs/igc_tf_test.yaml new file mode 100644 index 0000000000..ad50266198 --- /dev/null +++ b/tools/validate_configs/test_configs/igc_tf_test.yaml @@ -0,0 +1,38 @@ +# Copyright 2022 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. + +--- +blueprint_name: igc + +vars: + project_id: # + deployment_name: igc-tf-test + region: us-east4 + zone: us-east4-c + +deployment_groups: +- group: zero + modules: + - id: network0 + source: modules/network/vpc + outputs: [nat_ips, subnetwork_name] + +- group: one + modules: + - id: homefs + source: modules/file-system/filestore + use: [network0] # wires network_id + settings: + local_mount: /home + name: $(network0.subnetwork_name) diff --git a/tools/validate_configs/validate_golden_copy.sh b/tools/validate_configs/validate_golden_copy.sh index 0bc154d051..cafe485939 100755 --- a/tools/validate_configs/validate_golden_copy.sh +++ b/tools/validate_configs/validate_golden_copy.sh @@ -74,7 +74,8 @@ run_test() { addlicense -c "Google LLC" -l apache . # Compare the deployment folder with the golden copy - diff --recursive --exclude="previous_deployment_groups" . "${cwd}/${gc}" || { + diff --recursive --exclude="previous_deployment_groups" \ + "$(pwd)" "${cwd}/${gc}" || { echo "*** ERROR: ${tmpdir}/${DEPLOYMENT} does not match ${gc}" exit 1 } @@ -95,3 +96,4 @@ ls ${gcs} >/dev/null 2>&1 || { } # Tests: run_test "tools/validate_configs/test_configs/igc_pkr_test.yaml" "${gcs}/packer_igc" +run_test "tools/validate_configs/test_configs/igc_tf_test.yaml" "${gcs}/terraform_igc"