Skip to content

Commit 53ec973

Browse files
committed
fix: fixed a bug where provider_meta was not recognized because of missing schema
1 parent 6d00406 commit 53ec973

File tree

10 files changed

+58
-19
lines changed

10 files changed

+58
-19
lines changed

docs/resources/path_exists.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
page_title: "value_path_exists Resource - terraform-provider-value"
44
subcategory: ""
55
description: |-
6-
Checks if an OS path exists and caches its computation at plan-time and won't change afterapply-time even the path may have been removed.
6+
Checks if an OS path exists and caches its computation at plan-time and won't change after apply-time even the path may have been removed.
77
Provider Metadata
88
Each module can use providermeta. Please keep in mind that these settings only count for resources of this module! (see https://www.terraform.io/internals/provider-meta https://www.terraform.io/internals/provider-meta):
99
```terraform
@@ -27,7 +27,7 @@ description: |-
2727

2828
# value_path_exists (Resource)
2929

30-
Checks if an OS path exists and caches its computation at plan-time and won't change afterapply-time even the path may have been removed.
30+
Checks if an OS path exists and caches its computation at plan-time and won't change after apply-time even the path may have been removed.
3131
## Provider Metadata
3232
Each module can use provider_meta. Please keep in mind that these settings only count for resources of this module! (see [https://www.terraform.io/internals/provider-meta](https://www.terraform.io/internals/provider-meta)):
3333
```terraform

examples/replaced_when/file_inexistence_check/findme

Whitespace-only changes.

examples/replaced_when/file_inexistence_check/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ terraform {
55
version = "0.1.0"
66
}
77
}
8+
9+
provider_meta "value" {
10+
guid_seed_addition = "module(file_inexistence_check)"
11+
}
12+
}
13+
14+
provider "value" {
15+
guid_seed_addition = "project(file_inexistence_check)"
816
}
917

1018
resource "value_unknown_proposer" "default" {}

internal/fwkprovider/path_exists.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (r *pathExistsResource) Configure(ctx context.Context, req resource.Configu
4545

4646
func (r pathExistsResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) {
4747
return tfsdk.Schema{
48-
Description: "Checks if an OS path exists and caches its computation at plan-time and won't change after" +
48+
Description: "Checks if an OS path exists and caches its computation at plan-time and won't change after " +
4949
"apply-time even the path may have been removed." + "\n" + goproviderconfig.GetProviderMetaGuidSeedAdditionAttributeDescription(),
5050
Attributes: map[string]tfsdk.Attribute{
5151
"path": {

internal/fwkprovider/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type providerWithTraits interface {
2121
fwkprovider.ProviderWithMetadata
2222
fwkprovider.ProviderWithResources
2323
fwkprovider.ProviderWithDataSources
24+
fwkprovider.ProviderWithMetaSchema
2425
}
2526

2627
// Provider schema struct
@@ -46,6 +47,11 @@ func (p *provider) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics)
4647
return *fwkproviderconfig.GetProviderConfigSchema(), nil
4748
}
4849

50+
// GetMetaSchema implements providerWithTraits
51+
func (*provider) GetMetaSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) {
52+
return *fwkproviderconfig.GetProviderMetaSchema(), nil
53+
}
54+
4955
func (p *provider) Configure(ctx context.Context, req fwkprovider.ConfigureRequest, resp *fwkprovider.ConfigureResponse) {
5056
// Retrieve provider data from configuration
5157
var config providerConfig

internal/fwkproviderconfig/attribute_guid_seed_addition.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,27 @@ import (
55

66
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
77
"github.com/hashicorp/terraform-plugin-framework/types"
8+
"github.com/pseudo-dynamic/terraform-provider-value/internal/goproviderconfig"
89
)
910

11+
const GuidSeedAdditionAttributeName string = "guid_seed_addition"
12+
13+
func getGuidSeedAdditionAttribute() tfsdk.Attribute {
14+
return tfsdk.Attribute{
15+
Type: types.StringType,
16+
Required: false,
17+
Optional: true,
18+
Computed: false,
19+
Validators: []tfsdk.AttributeValidator{
20+
&PlanKnownValidator{},
21+
},
22+
PlanModifiers: tfsdk.AttributePlanModifiers{
23+
guidSeedAdditionDefaultEmptyModifier{},
24+
},
25+
Description: goproviderconfig.GetGuidSeedAdditionAttributeDescription(),
26+
}
27+
}
28+
1029
type guidSeedAdditionDefaultEmptyModifier struct{}
1130

1231
func (r guidSeedAdditionDefaultEmptyModifier) Modify(ctx context.Context, req tfsdk.ModifyAttributePlanRequest, resp *tfsdk.ModifyAttributePlanResponse) {

internal/fwkproviderconfig/provider_config_schema.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,13 @@ package fwkproviderconfig
22

33
import (
44
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
5-
"github.com/hashicorp/terraform-plugin-framework/types"
6-
"github.com/pseudo-dynamic/terraform-provider-value/internal/goproviderconfig"
75
)
86

97
func GetProviderConfigSchema() *tfsdk.Schema {
108
return &tfsdk.Schema{
119
Version: 0,
1210
Attributes: map[string]tfsdk.Attribute{
13-
"guid_seed_addition": {
14-
Type: types.StringType,
15-
Required: false,
16-
Optional: true,
17-
Computed: false,
18-
Validators: []tfsdk.AttributeValidator{
19-
&PlanKnownValidator{},
20-
},
21-
PlanModifiers: tfsdk.AttributePlanModifiers{
22-
guidSeedAdditionDefaultEmptyModifier{},
23-
},
24-
Description: goproviderconfig.GetGuidSeedAdditionAttributeDescription(),
25-
},
11+
GuidSeedAdditionAttributeName: getGuidSeedAdditionAttribute(),
2612
},
2713
}
2814
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package fwkproviderconfig
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
5+
)
6+
7+
func GetProviderMetaSchema() *tfsdk.Schema {
8+
return &tfsdk.Schema{
9+
Version: 0,
10+
Attributes: map[string]tfsdk.Attribute{
11+
GuidSeedAdditionAttributeName: getGuidSeedAdditionAttribute(),
12+
},
13+
}
14+
}

internal/goproviderconfig/attribute_guid_seed_addition.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ func TryUnmarshalValueThenExtractGuidSeedAddition(value *tftypes.Value) (string,
4242
var diags []*tfprotov6.Diagnostic
4343

4444
if valueMap, diags, isErroneous = schema.UnmarshalValue(value); isErroneous {
45+
diags = append(diags, &tfprotov6.Diagnostic{
46+
Severity: tfprotov6.DiagnosticSeverityError,
47+
Summary: "Could unmarshal value to map[string]tftypes.Value",
48+
Detail: "Could unmarshal value to map[string]tftypes.Value to extract guid_seed_addition",
49+
})
4550
goto Return
4651
}
4752
_ = value
4853

4954
if seedAdditionValue, isSuccesful = valueMap["guid_seed_addition"]; !isSuccesful {
55+
// Not having guid_seed_addition is fine.
5056
goto Return
5157
}
5258
_ = seedAdditionValue

internal/goproviderconfig/provider_meta_schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func GetProviderMetaSchema() *tfprotov6.Schema {
1818
Version: 0,
1919
Block: &tfprotov6.SchemaBlock{
2020
Attributes: []*tfprotov6.SchemaAttribute{
21-
GetGuidSeedAdditionSchemaAttribute(GetProviderMetaGuidSeedAdditionAttributeDescription()),
21+
GetGuidSeedAdditionSchemaAttribute(GetGuidSeedAdditionAttributeDescription()),
2222
},
2323
},
2424
}

0 commit comments

Comments
 (0)