Closed caleonardo closed 4 years ago
Another possible solution is to use multiple variable files, but then we need to change the tf-wrapper to be aware of that, as in:
For envs/shared:
$ terraform plan –var-file terraform.common.tfvars –var-file terraform.shared.tfvars
For envs/dev|prod|nonprod:
$ terraform plan –var-file terraform.common.tfvars
or point the terraform.tfvars@
link to terraform.common.tfvars
in Terraform v0.12.24 this only give a warning, not an error. Which version of terraform are you using ?
Something like was done in 4-projects could be done here too:
to have in 3-networks:
and on 3-networks/envs/[dev|nonprod|prod] have
commons.auto.tfvar -> ../../commons.auto.tfvar
and on 3-networks/envs/shared have
commons.auto.tfvar -> ../../commons.auto.tfvar shared.auto.tfvar -> ../../shared.auto.tfvar
PR merged
Please note I am opening two bugs, both errors appear in the log below
ERROR:
CAUSE: The variables in
3-networks/terraform.example.tfvars
are the same for all envs and the instructions only ask the user to rename the file.All envs/ in 3-networks share the same terraform.example.tfvars - However, the envs/shared uses different variables that envs/dev, envs/prod and envs/nonpord
POSSIBLE SOLUTION The instructions should ask the user to make two copies of the file: one for 3-networks/envs/shared and one for 3-networks/envs/prod|nonprod|dev
Note that you can also see the error described in https://github.com/terraform-google-modules/terraform-example-foundation/issues/170 - they seem to be two different issues
====================+====================+====================+====================+======
FailedConsole Output Branch indexing
[0m[1mInitializing the backend...[0m [0m[32m Successfully configured the backend "gcs"! Terraform will automatically use this backend unless the backend configuration changes.[0m
[0m[1mInitializing provider plugins...[0m
The following providers do not have any version constraints in configuration, so the latest version was installed.
To prevent automatic upgrades to new major versions that may contain breaking changes, it is recommended to add version = "..." constraints to the corresponding provider blocks in configuration, with the constraint strings suggested below.
[0m[1m[32mTerraform has been successfully initialized![0m[32m[0m [0m[32m You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work.
If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.[0m * TERRAFORM PLAN ***** At environment: envs/prod
[0m[1mRefreshing Terraform state in-memory prior to plan...[0m The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. [0m [0m[1mdata.google_service_account_access_token.default: Refreshing state...[0m [0m[1mmodule.private_shared_vpc.data.google_netblock_ip_ranges.iap_forwarders: Refreshing state...[0m [0m[1mmodule.restricted_shared_vpc.data.google_netblock_ip_ranges.health_checkers: Refreshing state...[0m [0m[1mmodule.restricted_shared_vpc.data.google_netblock_ip_ranges.legacy_health_checkers: Refreshing state...[0m [0m[1mdata.google_active_folder.env: Refreshing state...[0m [0m[1mmodule.private_shared_vpc.data.google_netblock_ip_ranges.health_checkers: Refreshing state...[0m [0m[1mmodule.restricted_shared_vpc.data.google_netblock_ip_ranges.iap_forwarders: Refreshing state...[0m [0m[1mmodule.restricted_shared_vpc.data.google_active_folder.common: Refreshing state...[0m [0m[1mmodule.private_shared_vpc.data.google_netblock_ip_ranges.legacy_health_checkers: Refreshing state...[0m [0m[1mmodule.private_shared_vpc.data.google_active_folder.common: Refreshing state...[0m [0m[1mmodule.private_shared_vpc.data.google_projects.dns_hub: Refreshing state...[0m [0m[1mmodule.restricted_shared_vpc.data.google_projects.dns_hub: Refreshing state...[0m [0m[1mdata.google_projects.restricted_host_project: Refreshing state...[0m [0m[1mdata.google_projects.private_host_project: Refreshing state...[0m [0m[1mdata.google_project.restricted_host_project: Refreshing state...[0m [0m[1mmodule.restricted_shared_vpc.data.google_compute_network.vpc_dns_hub: Refreshing state...[0m [0m[1mmodule.private_shared_vpc.data.google_compute_network.vpc_dns_hub: Refreshing state...[0m
[33m [1m[33mWarning: [0m[0m[1mValue for undeclared variable[0m
[0mThe root module does not declare a variable named "target_name_server_addresses" but a value was found in file "terraform.tfvars". To use this value, add a "variable" block to the configuration.
Using a variables file to set an undeclared variable is deprecated and will become an error in a future release. If you wish to provide certain "global" settings to all configurations in your organization, use TFVAR... environment variables to set these instead. [0m[0m [31m [1m[31mError: [0m[0m[1m"peering_config.0.target_network.0.network_url": required field is not set[0m
[0m on .terraform/modules/private_shared_vpc.peering_zone/terraform-google-cloud-dns-3.0.2/main.tf line 21, in resource "google_dns_managed_zone" "peering": 21: resource "google_dns_managed_zone" "peering" [4m{[0m [0m [0m[0m [31m [1m[31mError: [0m[0m[1m"peering_config.0.target_network.0.network_url": required field is not set[0m
[0m on .terraform/modules/restricted_shared_vpc.peering_zone/terraform-google-cloud-dns-3.0.2/main.tf line 21, in resource "google_dns_managed_zone" "peering": 21: resource "google_dns_managed_zone" "peering" [4m{[0m [0m [0m[0m [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (TF init) Stage "TF init" skipped due to earlier failure(s) [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (TF plan) Stage "TF plan" skipped due to earlier failure(s) [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (TF validate) Stage "TF validate" skipped due to earlier failure(s) [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (TF apply) Stage "TF apply" skipped due to earlier failure(s) [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 21 Finished: FAILURE