hashicorp / terraform-config-inspect

A helper library for shallow inspection of Terraform configurations
Mozilla Public License 2.0
383 stars 76 forks source link

Merge source across required_providers blocks #46

Closed alisdair closed 4 years ago

alisdair commented 4 years ago

Rebase of #44, to keep the required providers logic in sync with Terraform. See also: hashicorp/terraform#25034

If multiple terraform.required_providers blocks are in the config, we already merge the version constraints for each provider. We should also merge the source attribute, and warn if there are duplicates.

Consider the following configuration:

terraform {
  required_providers {
    foo = {
      version = "1.0.0"
    }
  }
}

terraform {
  required_providers {
    foo = {
      source = "abc/foo"
    }
  }
}

Before this commit, this would result in a provider requirement for "foo" with version "1.0.0", but no source. This commit merges the source attribute from the second block into this requirement.