Skip to content

Commit 297a8a6

Browse files
authored
chore(projectmanager): remove members attribute (#737)
relates to STACKITTPR-165
1 parent a8809a4 commit 297a8a6

File tree

7 files changed

+144
-712
lines changed

7 files changed

+144
-712
lines changed

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ lint: lint-golangci-lint lint-tf
2323
generate-docs:
2424
@echo "Generating documentation with tfplugindocs"
2525
@$(SCRIPTS_BASE)/tfplugindocs.sh
26-
# workaround until STACKITTPR-165 will be resolved
27-
@git apply $(SCRIPTS_BASE)/docs.patch
2826

2927
build:
3028
@go build -o bin/terraform-provider-stackit

docs/data-sources/resourcemanager_project.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ data "stackit_resourcemanager_project" "example" {
2525
### Optional
2626

2727
- `container_id` (String) Project container ID. Globally unique, user-friendly identifier.
28-
- `owner_email` (String) Email address of the owner of the project. This value is only considered during creation. Changing it afterwards will have no effect.
2928
- `project_id` (String) Project UUID identifier. This is the ID that can be used in most of the other resources to identify the project.
3029

3130
### Read-Only

scripts/docs.patch

Lines changed: 0 additions & 46 deletions
This file was deleted.

stackit/internal/services/resourcemanager/project/datasource.go

Lines changed: 13 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@ import (
55
"fmt"
66
"net/http"
77
"regexp"
8-
"strings"
98

109
"github.com/hashicorp/terraform-plugin-framework-validators/mapvalidator"
1110
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1211
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1312
"github.com/hashicorp/terraform-plugin-framework/types"
1413
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
15-
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
1614
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
1715

1816
"github.com/hashicorp/terraform-plugin-framework/datasource"
1917
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
2018
"github.com/hashicorp/terraform-plugin-log/tflog"
2119
"github.com/stackitcloud/stackit-sdk-go/core/config"
2220
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
23-
"github.com/stackitcloud/stackit-sdk-go/services/authorization"
2421
"github.com/stackitcloud/stackit-sdk-go/services/resourcemanager"
2522
)
2623

@@ -36,8 +33,7 @@ func NewProjectDataSource() datasource.DataSource {
3633

3734
// projectDataSource is the data source implementation.
3835
type projectDataSource struct {
39-
resourceManagerClient *resourcemanager.APIClient
40-
membershipClient *authorization.APIClient
36+
client *resourcemanager.APIClient
4137
}
4238

4339
// Metadata returns the data source type name.
@@ -51,7 +47,7 @@ func (d *projectDataSource) Configure(ctx context.Context, req datasource.Config
5147
return
5248
}
5349

54-
var rmClient *resourcemanager.APIClient
50+
var apiClient *resourcemanager.APIClient
5551
var err error
5652
providerData, ok := req.ProviderData.(core.ProviderData)
5753
if !ok {
@@ -60,12 +56,12 @@ func (d *projectDataSource) Configure(ctx context.Context, req datasource.Config
6056
}
6157

6258
if providerData.ResourceManagerCustomEndpoint != "" {
63-
rmClient, err = resourcemanager.NewAPIClient(
59+
apiClient, err = resourcemanager.NewAPIClient(
6460
config.WithCustomAuth(providerData.RoundTripper),
6561
config.WithEndpoint(providerData.ResourceManagerCustomEndpoint),
6662
)
6763
} else {
68-
rmClient, err = resourcemanager.NewAPIClient(
64+
apiClient, err = resourcemanager.NewAPIClient(
6965
config.WithCustomAuth(providerData.RoundTripper),
7066
)
7167
}
@@ -74,44 +70,20 @@ func (d *projectDataSource) Configure(ctx context.Context, req datasource.Config
7470
return
7571
}
7672

77-
var aClient *authorization.APIClient
78-
if providerData.AuthorizationCustomEndpoint != "" {
79-
ctx = tflog.SetField(ctx, "authorization_custom_endpoint", providerData.AuthorizationCustomEndpoint)
80-
aClient, err = authorization.NewAPIClient(
81-
config.WithCustomAuth(providerData.RoundTripper),
82-
config.WithEndpoint(providerData.AuthorizationCustomEndpoint),
83-
)
84-
} else {
85-
aClient, err = authorization.NewAPIClient(
86-
config.WithCustomAuth(providerData.RoundTripper),
87-
)
88-
}
89-
90-
if err != nil {
91-
core.LogAndAddError(ctx, &resp.Diagnostics, "Error configuring Membership API client", fmt.Sprintf("Configuring client: %v. This is an error related to the provider configuration, not to the resource configuration", err))
92-
return
93-
}
94-
95-
d.resourceManagerClient = rmClient
96-
d.membershipClient = aClient
73+
d.client = apiClient
9774
tflog.Info(ctx, "Resource Manager project client configured")
9875
}
9976

10077
// Schema defines the schema for the data source.
10178
func (d *projectDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
10279
descriptions := map[string]string{
103-
"main": "Resource Manager project data source schema. To identify the project, you need to provider either project_id or container_id. If you provide both, project_id will be used.",
104-
"id": "Terraform's internal data source. ID. It is structured as \"`container_id`\".",
105-
"project_id": "Project UUID identifier. This is the ID that can be used in most of the other resources to identify the project.",
106-
"container_id": "Project container ID. Globally unique, user-friendly identifier.",
107-
"parent_container_id": "Parent resource identifier. Both container ID (user-friendly) and UUID are supported",
108-
"name": "Project name.",
109-
"labels": `Labels are key-value string pairs which can be attached to a resource container. A label key must match the regex [A-ZÄÜÖa-zäüöß0-9_-]{1,64}. A label value must match the regex ^$|[A-ZÄÜÖa-zäüöß0-9_-]{1,64}`,
110-
"owner_email": "Email address of the owner of the project. This value is only considered during creation. Changing it afterwards will have no effect.",
111-
"members": "The members assigned to the project. At least one subject needs to be a user, and not a client or service account. This value is only considered during creation. Changing it afterwards will have no effect.",
112-
"members.role": fmt.Sprintf("The role of the member in the project. Legacy roles (%s) are not supported.", strings.Join(utils.QuoteValues(utils.LegacyProjectRoles), ", ")),
113-
"members.subject": "Unique identifier of the user, service account or client. This is usually the email address for users or service accounts, and the name in case of clients.",
114-
"members_deprecation_message": "The \"members\" field has been deprecated in favor of the \"owner_email\" field. Please use the \"owner_email\" field to assign the owner role to a user.",
80+
"main": "Resource Manager project data source schema. To identify the project, you need to provider either project_id or container_id. If you provide both, project_id will be used.",
81+
"id": "Terraform's internal data source. ID. It is structured as \"`container_id`\".",
82+
"project_id": "Project UUID identifier. This is the ID that can be used in most of the other resources to identify the project.",
83+
"container_id": "Project container ID. Globally unique, user-friendly identifier.",
84+
"parent_container_id": "Parent resource identifier. Both container ID (user-friendly) and UUID are supported",
85+
"name": "Project name.",
86+
"labels": `Labels are key-value string pairs which can be attached to a resource container. A label key must match the regex [A-ZÄÜÖa-zäüöß0-9_-]{1,64}. A label value must match the regex ^$|[A-ZÄÜÖa-zäüöß0-9_-]{1,64}`,
11587
}
11688

11789
resp.Schema = schema.Schema{
@@ -167,31 +139,6 @@ func (d *projectDataSource) Schema(_ context.Context, _ datasource.SchemaRequest
167139
),
168140
},
169141
},
170-
"owner_email": schema.StringAttribute{
171-
Description: descriptions["owner_email"],
172-
Optional: true,
173-
},
174-
"members": schema.ListNestedAttribute{
175-
Description: descriptions["members"],
176-
DeprecationMessage: descriptions["members_deprecation_message"],
177-
MarkdownDescription: fmt.Sprintf("%s\n\n!> %s", descriptions["members"], descriptions["members_deprecation_message"]),
178-
Computed: true,
179-
NestedObject: schema.NestedAttributeObject{
180-
Attributes: map[string]schema.Attribute{
181-
"role": schema.StringAttribute{
182-
Description: descriptions["members.role"],
183-
Computed: true,
184-
Validators: []validator.String{
185-
validate.NonLegacyProjectRole(),
186-
},
187-
},
188-
"subject": schema.StringAttribute{
189-
Description: descriptions["members.subject"],
190-
Computed: true,
191-
},
192-
},
193-
},
194-
},
195142
},
196143
}
197144
}
@@ -222,7 +169,7 @@ func (d *projectDataSource) Read(ctx context.Context, req datasource.ReadRequest
222169
identifier = projectId
223170
}
224171

225-
projectResp, err := d.resourceManagerClient.GetProject(ctx, identifier).Execute()
172+
projectResp, err := d.client.GetProject(ctx, identifier).Execute()
226173
if err != nil {
227174
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
228175
if ok && oapiErr.StatusCode == http.StatusForbidden {

0 commit comments

Comments
 (0)