From 491bed872ad7604b5ec910174f9753145eb295f1 Mon Sep 17 00:00:00 2001 From: Quentin Date: Mon, 7 Oct 2024 10:00:15 +0200 Subject: [PATCH] Fix : User and group permission.name validation (#9) * fix: Remove regex validation on user and group permission name * chore: Print git diff on CI test.generate job --- .github/workflows/test.yml | 1 + internal/provider/user_v2_resource_test.go | 4 +-- .../group_v2_resource_gen.go | 3 -- .../resource_user_v2/user_v2_resource_gen.go | 3 -- internal/testdata/user_v2_resource_create.tf | 2 +- internal/testdata/user_v2_resource_update.tf | 2 +- provider_code_spec.json | 34 ++----------------- 7 files changed, 7 insertions(+), 42 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f62b237..2bf9562 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,6 +51,7 @@ jobs: - run: go generate ./... - name: git diff run: | + git diff --compact-summary git diff --compact-summary --exit-code || \ (echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1) diff --git a/internal/provider/user_v2_resource_test.go b/internal/provider/user_v2_resource_test.go index 72798bf..7d428a6 100644 --- a/internal/provider/user_v2_resource_test.go +++ b/internal/provider/user_v2_resource_test.go @@ -24,7 +24,7 @@ func TestAccUserV2Resource(t *testing.T) { resource.TestCheckResourceAttr(resourceRef, "spec.lastname", "Beesly"), resource.TestCheckResourceAttr(resourceRef, "spec.permissions.#", "1"), resource.TestCheckResourceAttr(resourceRef, "spec.permissions.0.resource_type", "TOPIC"), - resource.TestCheckResourceAttr(resourceRef, "spec.permissions.0.name", "test-topic"), + resource.TestCheckResourceAttr(resourceRef, "spec.permissions.0.name", "team1.test-topic"), resource.TestCheckResourceAttr(resourceRef, "spec.permissions.0.pattern_type", "LITERAL"), resource.TestCheckResourceAttr(resourceRef, "spec.permissions.0.cluster", "*"), resource.TestCheckResourceAttr(resourceRef, "spec.permissions.0.permissions.#", "3"), @@ -49,7 +49,7 @@ func TestAccUserV2Resource(t *testing.T) { resource.TestCheckResourceAttr(resourceRef, "spec.permissions.0.resource_type", "PLATFORM"), resource.TestCheckResourceAttr(resourceRef, "spec.permissions.0.permissions.#", "4"), resource.TestCheckResourceAttr(resourceRef, "spec.permissions.1.resource_type", "TOPIC"), - resource.TestCheckResourceAttr(resourceRef, "spec.permissions.1.name", "test-topic"), + resource.TestCheckResourceAttr(resourceRef, "spec.permissions.1.name", "team1.test-topic"), resource.TestCheckResourceAttr(resourceRef, "spec.permissions.1.pattern_type", "LITERAL"), resource.TestCheckResourceAttr(resourceRef, "spec.permissions.1.cluster", "*"), ), diff --git a/internal/schema/resource_group_v2/group_v2_resource_gen.go b/internal/schema/resource_group_v2/group_v2_resource_gen.go index 410c0f5..b33787e 100644 --- a/internal/schema/resource_group_v2/group_v2_resource_gen.go +++ b/internal/schema/resource_group_v2/group_v2_resource_gen.go @@ -96,9 +96,6 @@ func GroupV2ResourceSchema(ctx context.Context) schema.Schema { Optional: true, Description: "Name of the resource to apply permission could be a topic, a cluster, a consumer group, etc. depending on resource_type", MarkdownDescription: "Name of the resource to apply permission could be a topic, a cluster, a consumer group, etc. depending on resource_type", - Validators: []validator.String{ - stringvalidator.RegexMatches(regexp.MustCompile("^[0-9a-z\\_\\-\\*]+$"), ""), - }, }, "pattern_type": schema.StringAttribute{ Optional: true, diff --git a/internal/schema/resource_user_v2/user_v2_resource_gen.go b/internal/schema/resource_user_v2/user_v2_resource_gen.go index d8e5823..b40dd60 100644 --- a/internal/schema/resource_user_v2/user_v2_resource_gen.go +++ b/internal/schema/resource_user_v2/user_v2_resource_gen.go @@ -67,9 +67,6 @@ func UserV2ResourceSchema(ctx context.Context) schema.Schema { Optional: true, Description: "Name of the resource to apply permission could be a topic, a cluster, a consumer group, etc. depending on resource_type", MarkdownDescription: "Name of the resource to apply permission could be a topic, a cluster, a consumer group, etc. depending on resource_type", - Validators: []validator.String{ - stringvalidator.RegexMatches(regexp.MustCompile("^[0-9a-z\\_\\-\\*]+$"), ""), - }, }, "pattern_type": schema.StringAttribute{ Optional: true, diff --git a/internal/testdata/user_v2_resource_create.tf b/internal/testdata/user_v2_resource_create.tf index 0ace3f1..1b64f6b 100644 --- a/internal/testdata/user_v2_resource_create.tf +++ b/internal/testdata/user_v2_resource_create.tf @@ -8,7 +8,7 @@ resource "conduktor_user_v2" "test" { { resource_type = "TOPIC" permissions = ["topicViewConfig", "topicConsume", "topicProduce"] - name = "test-topic" + name = "team1.test-topic" pattern_type = "LITERAL" cluster = "*" } diff --git a/internal/testdata/user_v2_resource_update.tf b/internal/testdata/user_v2_resource_update.tf index fd548ce..4de2437 100644 --- a/internal/testdata/user_v2_resource_update.tf +++ b/internal/testdata/user_v2_resource_update.tf @@ -12,7 +12,7 @@ resource "conduktor_user_v2" "test" { { resource_type = "TOPIC" permissions = ["topicViewConfig", "topicConsume", "topicProduce"] - name = "test-topic" + name = "team1.test-topic" pattern_type = "LITERAL" cluster = "*" } diff --git a/provider_code_spec.json b/provider_code_spec.json index 0081274..eea514d 100644 --- a/provider_code_spec.json +++ b/provider_code_spec.json @@ -135,22 +135,7 @@ "name": "name", "string": { "description": "Name of the resource to apply permission could be a topic, a cluster, a consumer group, etc. depending on resource_type", - "computed_optional_required": "optional", - "validators": [ - { - "custom": { - "imports": [ - { - "path": "regexp" - }, - { - "path": "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - } - ], - "schema_definition": "stringvalidator.RegexMatches(regexp.MustCompile(\"^[0-9a-z\\\\_\\\\-\\\\*]+$\"), \"\")" - } - } - ] + "computed_optional_required": "optional" } }, { @@ -394,22 +379,7 @@ "name": "name", "string": { "description": "Name of the resource to apply permission could be a topic, a cluster, a consumer group, etc. depending on resource_type", - "computed_optional_required": "optional", - "validators": [ - { - "custom": { - "imports": [ - { - "path": "regexp" - }, - { - "path": "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - } - ], - "schema_definition": "stringvalidator.RegexMatches(regexp.MustCompile(\"^[0-9a-z\\\\_\\\\-\\\\*]+$\"), \"\")" - } - } - ] + "computed_optional_required": "optional" } }, {