Skip to content

Commit a82e56c

Browse files
authored
Merge pull request #71 from pluralsh/marcin/prod-3029-plural_service_context-configuration-type-should-be-any-map
fix: `plural_service_context` `configuration` field type
2 parents 1a35c93 + 306e15c commit a82e56c

File tree

12 files changed

+262
-262
lines changed

12 files changed

+262
-262
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,5 @@ jobs:
9090
check-latest: true
9191
- uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
9292
with:
93-
version: v1.59
93+
version: v1.62
9494
args: --timeout=10m

docs/data-sources/service_context.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ A representation of a service context that can be reused during service deployme
2121

2222
### Read-Only
2323

24-
- `configuration` (Map of String)
24+
- `configuration` (String) Configuration in JSON format. Use `jsondecode` method to decode data.
2525
- `id` (String) Internal identifier of this service context.

docs/resources/cluster.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ A representation of a cluster you can deploy to.
2727
- `helm_repo_url` (String) Helm repository URL you'd like to use in deployment agent Helm install.
2828
- `helm_values` (String) Additional Helm values you'd like to use in deployment agent Helm installs. This is useful for BYOK clusters that need to use custom images or other constructs.
2929
- `kubeconfig` (Attributes) (see [below for nested schema](#nestedatt--kubeconfig))
30-
- `metadata` (String) Arbitrary JSON metadata to store user-specific state of this cluster (e.g. IAM roles for add-ons).
30+
- `metadata` (String) Arbitrary JSON metadata to store user-specific state of this cluster (e.g. IAM roles for add-ons). Use `jsonencode` and `jsondecode` methods to encode and decode data.
3131
- `project_id` (String) ID of the project that this cluster belongs to.
3232
- `protect` (Boolean) If set to `true` then this cluster cannot be deleted.
3333
- `tags` (Map of String) Key-value tags used to filter clusters.

docs/resources/oidc_provider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ description: |-
2222

2323
### Optional
2424

25+
- `auth_method` (String)
2526
- `description` (String) Description of this OIDC provider.
2627
- `redirect_uris` (Set of String)
2728

docs/resources/service_context.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ A representation of a service context that can be reused during service deployme
2121

2222
### Optional
2323

24-
- `configuration` (Map of String)
24+
- `configuration` (String) Configuration in JSON format. Use `jsonencode` and `jsondecode` methods to encode and decode data.
2525
- `secrets` (Map of String, Sensitive)
2626

2727
### Read-Only

example/servicecontext/main.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ provider "plural" {
1313

1414
resource "plural_service_context" "service_context" {
1515
name = "service-context-test"
16-
configuration = {
16+
configuration = jsonencode({
1717
"env" = "prod"
1818
"test" = "some-value"
19-
}
19+
"array" = [1, 2, 3]
20+
"nested_field" = {
21+
"test" = "nested-value"
22+
}
23+
})
2024
secrets = {
2125
"test" = "some-secret-value"
2226
}

go.mod

Lines changed: 76 additions & 76 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 156 additions & 161 deletions
Large diffs are not rendered by default.

internal/datasource/service_context.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/hashicorp/terraform-plugin-framework/datasource"
1212
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
13-
"github.com/hashicorp/terraform-plugin-framework/types"
1413
)
1514

1615
func NewServiceContextDataSource() datasource.DataSource {
@@ -39,11 +38,10 @@ func (d *serviceContextDataSource) Schema(_ context.Context, _ datasource.Schema
3938
MarkdownDescription: "Human-readable name of this service context.",
4039
Required: true,
4140
},
42-
"configuration": schema.MapAttribute{
43-
Description: "",
44-
MarkdownDescription: "",
41+
"configuration": schema.StringAttribute{
42+
Description: "Configuration in JSON format. Use 'jsondecode' method to decode data.",
43+
MarkdownDescription: "Configuration in JSON format. Use `jsondecode` method to decode data.",
4544
Computed: true,
46-
ElementType: types.StringType,
4745
},
4846
},
4947
}

internal/model/service_context.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package model
22

33
import (
44
"context"
5-
6-
"terraform-provider-plural/internal/common"
5+
"encoding/json"
6+
"fmt"
77

88
"github.com/hashicorp/terraform-plugin-framework/diag"
99
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -13,12 +13,18 @@ import (
1313
type ServiceContext struct {
1414
Id types.String `tfsdk:"id"`
1515
Name types.String `tfsdk:"name"`
16-
Configuration types.Map `tfsdk:"configuration"`
16+
Configuration types.String `tfsdk:"configuration"`
1717
}
1818

1919
func (sc *ServiceContext) From(response *console.ServiceContextFragment, ctx context.Context, d diag.Diagnostics) {
20+
configuration, err := json.Marshal(response.Configuration)
21+
if err != nil {
22+
d.AddError("Provider Error", fmt.Sprintf("Cannot marshall metadata, got error: %s", err))
23+
return
24+
}
25+
2026
sc.Id = types.StringValue(response.ID)
21-
sc.Configuration = common.MapFrom(response.Configuration, ctx, d)
27+
sc.Configuration = types.StringValue(string(configuration))
2228
}
2329

2430
type ServiceContextExtended struct {
@@ -27,9 +33,6 @@ type ServiceContextExtended struct {
2733
}
2834

2935
func (sc *ServiceContextExtended) Attributes(ctx context.Context, d diag.Diagnostics) console.ServiceContextAttributes {
30-
configuration := make(map[string]types.String, len(sc.Configuration.Elements()))
31-
sc.Configuration.ElementsAs(ctx, &configuration, false)
32-
3336
secrets := make(map[string]types.String, len(sc.Secrets.Elements()))
3437
sc.Secrets.ElementsAs(ctx, &secrets, false)
3538
configAttributes := make([]*console.ConfigAttributes, 0)
@@ -41,7 +44,7 @@ func (sc *ServiceContextExtended) Attributes(ctx context.Context, d diag.Diagnos
4144
}
4245

4346
return console.ServiceContextAttributes{
44-
Configuration: common.AttributesJson(configuration, d),
47+
Configuration: sc.Configuration.ValueStringPointer(),
4548
Secrets: configAttributes,
4649
}
4750
}

0 commit comments

Comments
 (0)