Skip to content

Commit

Permalink
Reflect v0.15 configuration_aliases in provider referencing
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Mar 17, 2021
1 parent a8c0201 commit 5bb0815
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/hashicorp/go-version v1.2.1
github.com/hashicorp/hcl-lang v0.0.0-20210317074414-9bb6847208c3
github.com/hashicorp/hcl/v2 v2.9.1
github.com/hashicorp/terraform-config-inspect v0.0.0-20201102131242-0c45ba392e51
github.com/hashicorp/terraform-config-inspect v0.0.0-20210311141537-e23e4a7f8c02
github.com/hashicorp/terraform-json v0.8.0
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
github.com/mh-cbon/go-fmt-fail v0.0.0-20160815164508-67765b3fbcb5
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ github.com/hashicorp/hcl-lang v0.0.0-20210317074414-9bb6847208c3/go.mod h1:ZGuDQ
github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90=
github.com/hashicorp/hcl/v2 v2.9.1 h1:eOy4gREY0/ZQHNItlfuEZqtcQbXIxzojlP301hDpnac=
github.com/hashicorp/hcl/v2 v2.9.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
github.com/hashicorp/terraform-config-inspect v0.0.0-20201102131242-0c45ba392e51 h1:SEGO1vz/pFLfKy4QpABIMCe7wffmtsOiWO4yc1E87cU=
github.com/hashicorp/terraform-config-inspect v0.0.0-20201102131242-0c45ba392e51/go.mod h1:Z0Nnk4+3Cy89smEbrq+sl1bxc9198gIP4I7wcQF6Kqs=
github.com/hashicorp/terraform-config-inspect v0.0.0-20210311141537-e23e4a7f8c02 h1:60W+BPDl3hFDYEF/E6W0e+QHmJtNqPWxPWDeXfrZfas=
github.com/hashicorp/terraform-config-inspect v0.0.0-20210311141537-e23e4a7f8c02/go.mod h1:Z0Nnk4+3Cy89smEbrq+sl1bxc9198gIP4I7wcQF6Kqs=
github.com/hashicorp/terraform-json v0.8.0 h1:XObQ3PgqU52YLQKEaJ08QtUshAfN3yu4u8ebSW0vztc=
github.com/hashicorp/terraform-json v0.8.0/go.mod h1:3defM4kkMfttwiE7VakJDwCd4R+umhSQnvJwORXbprE=
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
Expand All @@ -62,6 +62,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down
7 changes: 7 additions & 0 deletions internal/refdecoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ func DecodeProviderReferences(m map[string]*hcl.File) (addrs.ProviderReferences,
refs[addrs.LocalProviderConfig{
LocalName: name,
}] = src

for _, alias := range req.ConfigurationAliases {
refs[addrs.LocalProviderConfig{
LocalName: alias.Name,
Alias: alias.Alias,
}] = src
}
}

for _, cfg := range mod.ProviderConfigs {
Expand Down
31 changes: 31 additions & 0 deletions internal/refdecoder/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,37 @@ data "mycloud_instance" "foo" {
},
},
},
{
"configuration aliases",
`
terraform {
required_providers {
xyz = {
source = "grafana/grafana"
version = "1.9.0"
configuration_aliases = [xyz.blah]
}
}
}
`,
addrs.ProviderReferences{
addrs.LocalProviderConfig{
LocalName: "xyz",
}: addrs.Provider{
Hostname: addrs.DefaultRegistryHost,
Namespace: "grafana",
Type: "grafana",
},
addrs.LocalProviderConfig{
LocalName: "xyz",
Alias: "blah",
}: addrs.Provider{
Hostname: addrs.DefaultRegistryHost,
Namespace: "grafana",
Type: "grafana",
},
},
},
}

for i, tc := range testCases {
Expand Down

0 comments on commit 5bb0815

Please sign in to comment.