Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue setting required field from an output inside a nested field in a module #16306

Open
danawillow opened this issue Oct 11, 2017 · 1 comment

Comments

@danawillow
Copy link
Contributor

Terraform Version

0.10.7
terraform-provider-google built at master

Terraform Configuration Files

module "mig1" {
  source = "GoogleCloudPlatform/managed-instance-group/google"

  project = "${google_project_services.apis.project}"
  region  = "us-west1"
  zone    = "us-west1-b"

  name              = "group1"
  size              = "2"
  target_tags       = ["allow-group1"]
  service_port      = 80
  service_port_name = "http"
  startup_script    = "${data.template_file.group-startup-script.rendered}"
}

module "mig2" {
  source = "GoogleCloudPlatform/managed-instance-group/google"

  project = "${google_project_services.apis.project}"
  region  = "us-east1"
  zone    = "us-east1-b"

  name              = "group2"
  size              = "2"
  target_tags       = ["allow-group2"]
  service_port      = 80
  service_port_name = "http"
  startup_script    = "${data.template_file.group-startup-script.rendered}"
}

module "lb-http" {
  # source = "GoogleCloudPlatform/lb-http/google"
  source = "/Users/danahoffman/go/src/github.com/GoogleCloudPlatform/terraform-google-lb-http"

  project     = "${google_project_services.apis.project}"
  name        = "global-lb-http"
  target_tags = ["${module.mig1.target_tags}", "${module.mig2.target_tags}"]

  backends = {
    "0" = [
      {
        group = "${module.mig1.instance_group}"
      },
      {
        group = "${module.mig2.instance_group}"
      },
    ]
  }

  backend_params = [
    // health check path, port name, port number, timeout seconds.
    "/,http,80,10",
  ]
}

The important block there is backends inside the lb-http module.

Since my google provider is at master, google_backend_service.backend.group is a Required field. Running terraform plan for this config gives the error:
* module.lb-http.google_compute_backend_service.default: "backend.0.group": required field is not set.

If I rebuild and change group to Optional, it applies just fine, so it's clearly able to map these variables to the appropriate resource. Setting the fields to explicit values also works. The error only comes up when group is a required field and I try to set it to an output from another module.

(and just as an fyi, the only changes I made to the module itself are to add the project field to more resources, so the fact that it's using a local version of the module shouldn't make a difference for a repro)

So whoever debugs this doesn't have to look it up, this is what backend looks like within resource_compute_backend_service.go:

			"backend": &schema.Schema{
				Type: schema.TypeSet,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"group": &schema.Schema{
							Type:             schema.TypeString,
							Required:         true,
							DiffSuppressFunc: compareSelfLinkRelativePaths,
						},
						[other fields]
					},
				},
				Optional: true,
				Set:      resourceGoogleComputeBackendServiceBackendHash,
			},

Trace logs here, though I took a quick look through and didn't see anything that looked useful: https://gist.github.com/danawillow/bdf9d68641aebb0a2b2afbb38b29cf4d

@rileykarson
Copy link
Contributor

Upon testing this with local modules (not the original repro) on 0.12.7, I'm unable to reproduce the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants