Skip to content

Commit

Permalink
Merge pull request #2871 from cloudflare/freeze-sdkv2
Browse files Browse the repository at this point in the history
provider: freeze SDKv2 based resources and datasources
  • Loading branch information
jacobbednarz authored Nov 13, 2023
2 parents 2de8cd4 + 52ebb13 commit 18d4c15
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/2871.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:internal
provider: prevent new resources and datasources from being created with `terraform-plugin-sdk`
```
27 changes: 27 additions & 0 deletions internal/sdkv2provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

const (
MAXIMUM_NUMBER_OF_ENTITIES_REACHED_SUMMARY = "You've attempted to add a new %[1]s to the `terraform-plugin-sdkv2` which is no longer considered suitable for use."
MAXIMUM_NUMBER_OF_ENTITIES_REACHED_DETAIL = "Due the number of known internal issues with `terraform-plugin-sdkv2` (most notably handling of zero values), we are no longer recommending using it and instead, advise using `terraform-plugin-framework` exclusively. If you must use terraform-plugin-sdkv2 for this new %[1]s you should first discuss it with a maintainer to fully understand the impact and potential ramifications. Only then should you bump %[2]s to include your %[1]s."
MAXIMUM_ALLOWED_SDKV2_RESOURCES = 110
MAXIMUM_ALLOWED_SDKV2_DATASOURCES = 19
)

func init() {
schema.DescriptionKind = schema.StringMarkdown

Expand Down Expand Up @@ -317,6 +324,26 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema
basePath string
)

if len(p.ResourcesMap) > MAXIMUM_ALLOWED_SDKV2_RESOURCES {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: fmt.Sprintf(MAXIMUM_NUMBER_OF_ENTITIES_REACHED_SUMMARY, "resource"),
Detail: fmt.Sprintf(MAXIMUM_NUMBER_OF_ENTITIES_REACHED_DETAIL, "resource", "MAXIMUM_ALLOWED_SDKV2_RESOURCES"),
})

return nil, diags
}

if len(p.DataSourcesMap) > MAXIMUM_ALLOWED_SDKV2_DATASOURCES {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: fmt.Sprintf(MAXIMUM_NUMBER_OF_ENTITIES_REACHED_SUMMARY, "datasource"),
Detail: fmt.Sprintf(MAXIMUM_NUMBER_OF_ENTITIES_REACHED_DETAIL, "datasource", "MAXIMUM_ALLOWED_SDKV2_DATASOURCES"),
})

return nil, diags
}

if d.Get(consts.APIHostnameSchemaKey).(string) != "" {
baseHostname = d.Get(consts.APIHostnameSchemaKey).(string)
} else {
Expand Down

0 comments on commit 18d4c15

Please sign in to comment.