Skip to content

Commit eb9e32d

Browse files
authored
Merge pull request #25861 from hashicorp/alisdair/builtin-provider-legacy-string
addrs: Fix LegacyString for builtin providers
2 parents 95eca06 + e02e53e commit eb9e32d

File tree

4 files changed

+103
-2
lines changed

4 files changed

+103
-2
lines changed

addrs/provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ func (pt Provider) LegacyString() string {
156156
if pt.IsZero() {
157157
panic("called LegacyString on zero-value addrs.Provider")
158158
}
159-
if pt.Namespace != LegacyProviderNamespace {
160-
panic(pt.String() + " is not a legacy addrs.Provider")
159+
if pt.Namespace != LegacyProviderNamespace && pt.Namespace != BuiltInProviderNamespace {
160+
panic(pt.String() + " cannot be represented as a legacy string")
161161
}
162162
return pt.Type
163163
}

addrs/provider_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,37 @@ func TestProviderString(t *testing.T) {
5454
}
5555
}
5656

57+
func TestProviderLegacyString(t *testing.T) {
58+
tests := []struct {
59+
Input Provider
60+
Want string
61+
}{
62+
{
63+
Provider{
64+
Type: "test",
65+
Hostname: DefaultRegistryHost,
66+
Namespace: LegacyProviderNamespace,
67+
},
68+
"test",
69+
},
70+
{
71+
Provider{
72+
Type: "terraform",
73+
Hostname: BuiltInProviderHost,
74+
Namespace: BuiltInProviderNamespace,
75+
},
76+
"terraform",
77+
},
78+
}
79+
80+
for _, test := range tests {
81+
got := test.Input.LegacyString()
82+
if got != test.Want {
83+
t.Errorf("wrong result for %s\ngot: %s\nwant: %s", test.Input.String(), got, test.Want)
84+
}
85+
}
86+
}
87+
5788
func TestProviderDisplay(t *testing.T) {
5889
tests := []struct {
5990
Input Provider
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"version": 3,
3+
"terraform_version": "0.11.14",
4+
"serial": 1,
5+
"lineage": "b707851e-4209-9792-e752-bc0dd6c81fcf",
6+
"modules": [
7+
{
8+
"path": [
9+
"root"
10+
],
11+
"outputs": {},
12+
"resources": {
13+
"data.terraform_remote_state.test": {
14+
"type": "terraform_remote_state",
15+
"depends_on": [],
16+
"primary": {
17+
"id": "2020-08-14 19:13:36.875081 +0000 UTC",
18+
"attributes": {
19+
"backend": "remote",
20+
"config.#": "1",
21+
"config.345861710.organization": "hashicorp",
22+
"config.345861710.workspaces.#": "1",
23+
"config.345861710.workspaces.0.%": "1",
24+
"config.345861710.workspaces.0.name": "test",
25+
"environment": "default",
26+
"id": "2020-08-14 19:13:36.875081 +0000 UTC",
27+
"workspace": "default"
28+
},
29+
"meta": {},
30+
"tainted": false
31+
},
32+
"deposed": [],
33+
"provider": "provider.terraform"
34+
}
35+
},
36+
"depends_on": []
37+
}
38+
]
39+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"version": 4,
3+
"terraform_version": "0.12.28",
4+
"serial": 1,
5+
"lineage": "b707851e-4209-9792-e752-bc0dd6c81fcf",
6+
"outputs": {},
7+
"resources": [
8+
{
9+
"mode": "data",
10+
"type": "terraform_remote_state",
11+
"name": "test",
12+
"provider": "provider.terraform",
13+
"instances": [
14+
{
15+
"schema_version": 0,
16+
"attributes_flat": {
17+
"backend": "remote",
18+
"config.#": "1",
19+
"config.345861710.organization": "hashicorp",
20+
"config.345861710.workspaces.#": "1",
21+
"config.345861710.workspaces.0.%": "1",
22+
"config.345861710.workspaces.0.name": "test",
23+
"environment": "default",
24+
"id": "2020-08-14 19:13:36.875081 +0000 UTC",
25+
"workspace": "default"
26+
}
27+
}
28+
]
29+
}
30+
]
31+
}

0 commit comments

Comments
 (0)