Skip to content

Commit 20d1c5f

Browse files
Tests: Replace ProviderFactories with ProtoV5ProviderFactories (#1423)
* Tests: Replace `ProviderFactories` with `ProtoV5ProviderFactories` This is needed for the migration to the new Terraform plugin framework The `ProviderFactories` attribute directly refers to an old SDKv2 provider, while the `ProtoV5ProviderFactories` attribute allows to reference the full provider setup (muxed from the SDKv2 and Plugin Framework resources) * Generate docs
1 parent bd938ad commit 20d1c5f

File tree

81 files changed

+339
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+339
-293
lines changed

docs/resources/contact_point.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ page_title: "grafana_contact_point Resource - terraform-provider-grafana"
44
subcategory: "Alerting"
55
description: |-
66
Manages Grafana Alerting contact points.
7-
Official documentation https://grafana.com/docs/grafana/next/alerting/fundamentals/contact-points/HTTP API https://grafana.com/docs/grafana/latest/developers/http_api/alerting_provisioning/#contact-points
7+
Official documentation https://grafana.com/docs/grafana/next/alerting/fundamentals/notifications/contact-points/HTTP API https://grafana.com/docs/grafana/latest/developers/http_api/alerting_provisioning/#contact-points
88
This resource requires Grafana 9.1.0 or later.
99
---
1010

1111
# grafana_contact_point (Resource)
1212

1313
Manages Grafana Alerting contact points.
1414

15-
* [Official documentation](https://grafana.com/docs/grafana/next/alerting/fundamentals/contact-points/)
15+
* [Official documentation](https://grafana.com/docs/grafana/next/alerting/fundamentals/notifications/contact-points/)
1616
* [HTTP API](https://grafana.com/docs/grafana/latest/developers/http_api/alerting_provisioning/#contact-points)
1717

1818
This resource requires Grafana 9.1.0 or later.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
github.com/hashicorp/hcl/v2 v2.20.0
2222
github.com/hashicorp/terraform-plugin-docs v0.18.0
2323
github.com/hashicorp/terraform-plugin-framework v1.6.1
24+
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
2425
github.com/hashicorp/terraform-plugin-go v0.22.1
2526
github.com/hashicorp/terraform-plugin-mux v0.15.0
2627
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ github.com/hashicorp/terraform-plugin-docs v0.18.0 h1:2bINhzXc+yDeAcafurshCrIjtd
149149
github.com/hashicorp/terraform-plugin-docs v0.18.0/go.mod h1:iIUfaJpdUmpi+rI42Kgq+63jAjI8aZVTyxp3Bvk9Hg8=
150150
github.com/hashicorp/terraform-plugin-framework v1.6.1 h1:hw2XrmUu8d8jVL52ekxim2IqDc+2Kpekn21xZANARLU=
151151
github.com/hashicorp/terraform-plugin-framework v1.6.1/go.mod h1:aJI+n/hBPhz1J+77GdgNfk5svW12y7fmtxe/5L5IuwI=
152+
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc=
153+
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg=
152154
github.com/hashicorp/terraform-plugin-go v0.22.1 h1:iTS7WHNVrn7uhe3cojtvWWn83cm2Z6ryIUDTRO0EV7w=
153155
github.com/hashicorp/terraform-plugin-go v0.22.1/go.mod h1:qrjnqRghvQ6KnDbB12XeZ4FluclYwptntoWCr9QaXTI=
154156
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=

internal/provider/provider.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-framework/providerserver"
7+
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
8+
"github.com/hashicorp/terraform-plugin-mux/tf5muxserver"
9+
"github.com/hashicorp/terraform-plugin-mux/tf6to5server"
10+
)
11+
12+
func MakeProviderServer(ctx context.Context, version string) (tfprotov5.ProviderServer, error) {
13+
// While we still have the SDK2 provider, we have to use the provider v5 protocol
14+
// See https://developer.hashicorp.com/terraform/plugin/mux/translating-protocol-version-6-to-5
15+
downgradedFrameworkProvider, err := tf6to5server.DowngradeServer(
16+
context.Background(),
17+
providerserver.NewProtocol6(FrameworkProvider(version)),
18+
)
19+
if err != nil {
20+
return nil, err
21+
}
22+
23+
providers := []func() tfprotov5.ProviderServer{
24+
func() tfprotov5.ProviderServer {
25+
return downgradedFrameworkProvider
26+
},
27+
Provider(version).GRPCProvider,
28+
}
29+
muxServer, err := tf5muxserver.NewMuxServer(ctx, providers...)
30+
if err != nil {
31+
return nil, err
32+
}
33+
return muxServer, nil
34+
}

internal/resources/cloud/data_source_cloud_ips_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestAccDataSourceIPsRead(t *testing.T) {
1616
testutils.CheckCloudAPITestsEnabled(t)
1717

1818
resource.ParallelTest(t, resource.TestCase{
19-
ProviderFactories: testutils.ProviderFactories,
19+
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
2020
Steps: []resource.TestStep{
2121
{
2222
Config: testutils.TestAccExample(t, "data-sources/grafana_cloud_ips/data-source.tf"),

internal/resources/cloud/data_source_cloud_organization_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestAccDataSourceOrganization_Basic(t *testing.T) {
2020
`, os.Getenv("GRAFANA_CLOUD_ORG"))
2121

2222
resource.ParallelTest(t, resource.TestCase{
23-
ProviderFactories: testutils.ProviderFactories,
23+
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
2424
Steps: []resource.TestStep{
2525
{
2626
Config: config,

internal/resources/cloud/data_source_cloud_stack_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func TestAccDataSourceStack_Basic(t *testing.T) {
2020
PreCheck: func() {
2121
testAccDeleteExistingStacks(t, prefix)
2222
},
23-
ProviderFactories: testutils.ProviderFactories,
24-
CheckDestroy: testAccStackCheckDestroy(&stack),
23+
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
24+
CheckDestroy: testAccStackCheckDestroy(&stack),
2525
Steps: []resource.TestStep{
2626
{
2727
Config: testAccDataSourceStackConfig(resourceName),

internal/resources/cloud/resource_cloud_access_policy_token_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestResourceAccessPolicyToken_Basic(t *testing.T) {
3838
}
3939

4040
resource.Test(t, resource.TestCase{
41-
ProviderFactories: testutils.ProviderFactories,
41+
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
4242
CheckDestroy: resource.ComposeTestCheckFunc(
4343
testAccCloudAccessPolicyCheckDestroy("us", &policy),
4444
testAccCloudAccessPolicyTokenCheckDestroy("us", &policyToken),
@@ -123,7 +123,7 @@ func TestResourceAccessPolicyToken_NoExpiration(t *testing.T) {
123123
var policyToken gcom.AuthToken
124124

125125
resource.Test(t, resource.TestCase{
126-
ProviderFactories: testutils.ProviderFactories,
126+
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
127127
Steps: []resource.TestStep{
128128
{
129129
Config: testAccCloudAccessPolicyTokenConfigBasic("initial-no-expiration", "", []string{"metrics:read"}, ""),

internal/resources/cloud/resource_cloud_api_key_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func TestAccCloudApiKey_Basic(t *testing.T) {
3636
resourceName := prefix + acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
3737

3838
resource.ParallelTest(t, resource.TestCase{
39-
ProviderFactories: testutils.ProviderFactories,
40-
CheckDestroy: testAccCheckCloudAPIKeyDestroy(resourceName),
39+
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
40+
CheckDestroy: testAccCheckCloudAPIKeyDestroy(resourceName),
4141
Steps: []resource.TestStep{
4242
{
4343
Config: testAccCloudAPIKeyConfig(resourceName, tt.role),

internal/resources/cloud/resource_cloud_plugin_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func TestAccResourcePluginInstallation(t *testing.T) {
2323
pluginVersion := "1.2.5"
2424

2525
resource.ParallelTest(t, resource.TestCase{
26-
PreCheck: func() { testAccDeleteExistingStacks(t, stackPrefix) },
27-
ProviderFactories: testutils.ProviderFactories,
26+
PreCheck: func() { testAccDeleteExistingStacks(t, stackPrefix) },
27+
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
2828
Steps: []resource.TestStep{
2929
{
3030
Config: testAccGrafanaCloudPluginInstallation(stackSlug, pluginSlug, pluginVersion),

0 commit comments

Comments
 (0)