@@ -28,17 +28,13 @@ the Framework.
28
28
29
29
### Example
30
30
31
- The following example is taken from
32
- [ v3.0.1] ( https://github.com/hashicorp/terraform-provider-http/blob/v3.0.1/internal/provider/data_source_http_test.go )
33
- of the http provider.
34
-
35
31
This example shows how you can use external providers to generate a state file with a previous version of the provider
36
32
and then verify that there are no planned changes after migrating to the Framework.
37
33
38
- - The first ` TestStep ` uses ` ExternalProviders ` to cause ` terraform apply ` to execute with ` v2.2.0 ` of the http
34
+ - The first ` TestStep ` uses ` ExternalProviders ` to cause ` terraform apply ` to execute with a previous version of the
39
35
provider, which is built on SDKv2.
40
- - The second ` TestStep ` uses ` ProtoV5ProviderFactories ` so that the test uses the provider code contained within your
41
- repository. The second step also uses ` PlanOnly ` to verify that a no-op plan is generated.
36
+ - The second ` TestStep ` uses ` ProtoV5ProviderFactories ` so that the test uses the provider code contained within the
37
+ http provider repository. The second step also uses ` PlanOnly ` to verify that a no-op plan is generated.
42
38
43
39
``` go
44
40
func TestDataSource_UpgradeFromVersion2_2_0 (t *testing .T ) {
@@ -47,26 +43,24 @@ func TestDataSource_UpgradeFromVersion2_2_0(t *testing.T) {
47
43
Steps: []resource.TestStep {
48
44
{
49
45
ExternalProviders: map [string ]resource.ExternalProvider {
50
- " http " : {
51
- VersionConstraint: " 2.2.0 " ,
52
- Source: " hashicorp/http " ,
46
+ " <provider> " : {
47
+ VersionConstraint: " <sdk_version> " ,
48
+ Source: " hashicorp/<provider> " ,
53
49
},
54
50
},
55
- Config: fmt.Sprintf (`
56
- data "http" "http_test" {
57
- url = "%s/200"
58
- }` , testHttpMock.server .URL ),
51
+ Config: ` data "provider_datasource" "example" {
52
+ /* ... */
53
+ }` ,
59
54
Check: resource.ComposeTestCheckFunc (
60
- resource.TestCheckResourceAttr (" data.http.http_test " , " response_body " , " 1.0.0 " ),
55
+ resource.TestCheckResourceAttr (" data.provider_datasource.example " , " <attribute> " , " <value> " ),
61
56
/* ... */
62
57
),
63
58
},
64
59
{
65
60
ProtoV5ProviderFactories: protoV5ProviderFactories (),
66
- Config: fmt.Sprintf (`
67
- data "http" "http_test" {
68
- url = "%s/200"
69
- }` , testHttpMock.server .URL ),
61
+ Config: ` data "provider_datasource" "example" {
62
+ /* ... */
63
+ }` ,
70
64
PlanOnly: true ,
71
65
},
72
66
},
@@ -109,21 +103,12 @@ resource.UnitTest(t, resource.TestCase{
109
103
110
104
### Example
111
105
112
- The following examples show how to migrate portions of the [http](https://github.com/hashicorp/terraform-provider-http)
113
- provider.
114
-
115
- To review a complete example, clone the
116
- ` terraform-provider-http` repository and compare the ` data_source_test.go ` file in
117
- [v2.2.0](https://github.com/hashicorp/terraform-provider-http/blob/v2.2.0/internal/provider/data_source_test.go) with the ` data_source_http_test.go ` file in
118
- [v3.0.1](https://github.com/hashicorp/terraform-provider-http/blob/v3.0.1/internal/provider/data_source_http_test.go).
119
-
120
106
#### SDKv2
121
107
122
- The following code sample is from the ` data_source_http_test.go ` file and shows how to define provider factories within
123
- a test case when using SDKv2.
108
+ The following code sample shows how to define provider factories within a test case when using SDKv2.
124
109
125
110
` ` ` go
126
- func TestDataSource_http200 (t *testing.T ) {
111
+ func TestDataSource_Exmple (t *testing.T ) {
127
112
/* ... */
128
113
resource.UnitTest (t, resource.TestCase {
129
114
ProviderFactories: testProviders (),
@@ -132,24 +117,22 @@ func TestDataSource_http200(t *testing.T) {
132
117
}
133
118
` ` `
134
119
135
- The following code sample is from the ` provider_test.go ` file and shows how to generate provider factories when using
136
- SDKv2.
120
+ The following shows how to generate provider factories when using SDKv2.
137
121
138
122
` ` ` go
139
123
func testProviders () map [string ]func () (*schema.Provider , error ) {
140
124
return map [string ]func () (*schema.Provider , error ){
141
- " http " : func () (*schema.Provider , error ) { return New (), nil },
125
+ " example " : func () (*schema.Provider , error ) { return New (), nil },
142
126
}
143
127
}
144
128
` ` `
145
129
146
130
#### Framework
147
131
148
- The following code sample is from the ` data_source_http_test.go ` file and shows how to define provider factories within
149
- a test case when using the Framework.
132
+ The following shows how to define provider factories within a test case when using the Framework.
150
133
151
134
` ` ` go
152
- func TestDataSource_200 (t *testing.T ) {
135
+ func TestDataSource_Example (t *testing.T ) {
153
136
/* ... */
154
137
155
138
resource.UnitTest (t, resource.TestCase {
@@ -159,14 +142,14 @@ func TestDataSource_200(t *testing.T) {
159
142
}
160
143
` ` `
161
144
162
- The following code sample is from the ` provider_test. go ` file and shows how to generate provider factories when using
145
+ The following shows how to generate provider factories when using
163
146
the Framework. The call to ` New` returns an instance of the provider. Refer to
164
147
[Provider Definition](/plugin/framework/migrating/providers#provider-definition) in this guide for details.
165
148
166
149
` ` ` go
167
150
func protoV5ProviderFactories () map [string ]func () (tfprotov5.ProviderServer , error ) {
168
151
return map [string ]func () (tfprotov5.ProviderServer , error ){
169
- " http " : providerserver.NewProtocol5WithError (New ()),
152
+ " example " : providerserver.NewProtocol5WithError (New ()),
170
153
}
171
154
}
172
155
` ` `
0 commit comments