Skip to content

Commit 6cd3e5c

Browse files
committed
Fix unknown project name validation
1 parent b572d58 commit 6cd3e5c

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

internal/services/git_integration/resource_environment_git_integration.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1818
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1919
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
20+
"github.com/hashicorp/terraform-plugin-framework/types"
2021
"github.com/hashicorp/terraform-plugin-log/tflog"
2122
"github.com/microsoft/terraform-provider-power-platform/internal/api"
2223
"github.com/microsoft/terraform-provider-power-platform/internal/customerrors"
@@ -126,13 +127,17 @@ func (r *EnvironmentGitIntegrationResource) ValidateConfig(ctx context.Context,
126127
ctx, exitContext := helpers.EnterRequestContext(ctx, r.TypeInfo, req)
127128
defer exitContext()
128129

129-
var data EnvironmentGitIntegrationResourceModel
130-
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
130+
var projectName types.String
131+
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("project_name"), &projectName)...)
131132
if resp.Diagnostics.HasError() {
132133
return
133134
}
134135

135-
if data.ProjectName.IsNull() || data.ProjectName.ValueString() == "" {
136+
if projectName.IsUnknown() {
137+
return
138+
}
139+
140+
if projectName.IsNull() || projectName.ValueString() == "" {
136141
resp.Diagnostics.AddAttributeError(
137142
path.Root("project_name"),
138143
"Missing project_name for AzureDevOps",
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
package git_integration_test
5+
6+
import (
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
"github.com/microsoft/terraform-provider-power-platform/internal/mocks"
11+
)
12+
13+
func TestUnitEnvironmentGitIntegrationResource_ValidateConfig_AllowsUnknownProjectName(t *testing.T) {
14+
t.Parallel()
15+
16+
resource.Test(t, resource.TestCase{
17+
IsUnitTest: true,
18+
ProtoV6ProviderFactories: mocks.TestUnitTestProtoV6ProviderFactories,
19+
Steps: []resource.TestStep{
20+
{
21+
PlanOnly: true,
22+
ExpectNonEmptyPlan: true,
23+
Config: `
24+
resource "powerplatform_environment_git_integration" "seed" {
25+
environment_id = "00000000-0000-0000-0000-000000000001"
26+
git_provider = "AzureDevOps"
27+
scope = "Solution"
28+
organization_name = "example-org"
29+
project_name = "example-project"
30+
repository_name = "example-repo"
31+
}
32+
33+
resource "powerplatform_environment_git_integration" "test" {
34+
environment_id = "00000000-0000-0000-0000-000000000001"
35+
git_provider = "AzureDevOps"
36+
scope = "Solution"
37+
organization_name = "example-org"
38+
project_name = powerplatform_environment_git_integration.seed.id
39+
repository_name = "example-repo"
40+
}
41+
`,
42+
},
43+
},
44+
})
45+
}

0 commit comments

Comments
 (0)