From 3e8dcc542b2db1f778b8e9f0f73bc266973f02d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= Date: Tue, 18 Feb 2025 10:51:34 +0100 Subject: [PATCH] fix: make resource/data-source specific region attribute read-only (#682) * fix: make resource/data-source specific region attribute read-only * fix: implemented review feedback --- stackit/internal/services/objectstorage/bucket/datasource.go | 5 +++-- stackit/internal/services/objectstorage/bucket/resource.go | 4 ++-- .../internal/services/objectstorage/credential/datasource.go | 5 +++-- .../internal/services/objectstorage/credential/resource.go | 4 ++-- .../services/objectstorage/credentialsgroup/datasource.go | 5 +++-- .../services/objectstorage/credentialsgroup/resource.go | 4 ++-- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/stackit/internal/services/objectstorage/bucket/datasource.go b/stackit/internal/services/objectstorage/bucket/datasource.go index 6aa39169..0a990276 100644 --- a/stackit/internal/services/objectstorage/bucket/datasource.go +++ b/stackit/internal/services/objectstorage/bucket/datasource.go @@ -84,7 +84,7 @@ func (r *bucketDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, "project_id": "STACKIT Project ID to which the bucket is associated.", "url_path_style": "URL in path style.", "url_virtual_hosted_style": "URL in virtual hosted style.", - "region": "The resource region. If not defined, the provider region is used.", + "region": "The resource region. Read-only attribute that reflects the provider region.", } resp.Schema = schema.Schema{ @@ -117,7 +117,8 @@ func (r *bucketDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, }, "region": schema.StringAttribute{ // the region cannot be found automatically, so it has to be passed - Optional: true, + Optional: false, + Computed: true, Description: descriptions["region"], }, }, diff --git a/stackit/internal/services/objectstorage/bucket/resource.go b/stackit/internal/services/objectstorage/bucket/resource.go index 9e5f4084..65727a61 100644 --- a/stackit/internal/services/objectstorage/bucket/resource.go +++ b/stackit/internal/services/objectstorage/bucket/resource.go @@ -132,7 +132,7 @@ func (r *bucketResource) Schema(_ context.Context, _ resource.SchemaRequest, res "project_id": "STACKIT Project ID to which the bucket is associated.", "url_path_style": "URL in path style.", "url_virtual_hosted_style": "URL in virtual hosted style.", - "region": "The resource region. If not defined, the provider region is used.", + "region": "The resource region. Read-only attribute that reflects the provider region.", } resp.Schema = schema.Schema{ @@ -175,7 +175,7 @@ func (r *bucketResource) Schema(_ context.Context, _ resource.SchemaRequest, res Computed: true, }, "region": schema.StringAttribute{ - Optional: true, + Optional: false, // must be computed to allow for storing the override value from the provider Computed: true, Description: descriptions["region"], diff --git a/stackit/internal/services/objectstorage/credential/datasource.go b/stackit/internal/services/objectstorage/credential/datasource.go index 9080fbb0..9317f28e 100644 --- a/stackit/internal/services/objectstorage/credential/datasource.go +++ b/stackit/internal/services/objectstorage/credential/datasource.go @@ -79,7 +79,7 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ "credential_id": "The credential ID.", "credentials_group_id": "The credential group ID.", "project_id": "STACKIT Project ID to which the credential group is associated.", - "region": "The resource region. If not defined, the provider region is used.", + "region": "The resource region. Read-only attribute that reflects the provider region.", } resp.Schema = schema.Schema{ @@ -116,7 +116,8 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ }, "region": schema.StringAttribute{ // the region cannot be found automatically, so it has to be passed - Optional: true, + Optional: false, + Computed: true, Description: descriptions["region"], }, }, diff --git a/stackit/internal/services/objectstorage/credential/resource.go b/stackit/internal/services/objectstorage/credential/resource.go index 1608eca1..5358fee7 100644 --- a/stackit/internal/services/objectstorage/credential/resource.go +++ b/stackit/internal/services/objectstorage/credential/resource.go @@ -176,7 +176,7 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, "credentials_group_id": "The credential group ID.", "project_id": "STACKIT Project ID to which the credential group is associated.", "expiration_timestamp": "Expiration timestamp, in RFC339 format without fractional seconds. Example: \"2025-01-01T00:00:00Z\". If not set, the credential never expires.", - "region": "The resource region. If not defined, the provider region is used.", + "region": "The resource region. Read-only attribute that reflects the provider region.", } resp.Schema = schema.Schema{ @@ -246,7 +246,7 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, }, }, "region": schema.StringAttribute{ - Optional: true, + Optional: false, // must be computed to allow for storing the override value from the provider Computed: true, Description: descriptions["region"], diff --git a/stackit/internal/services/objectstorage/credentialsgroup/datasource.go b/stackit/internal/services/objectstorage/credentialsgroup/datasource.go index 0e8f88ab..bf5fe146 100644 --- a/stackit/internal/services/objectstorage/credentialsgroup/datasource.go +++ b/stackit/internal/services/objectstorage/credentialsgroup/datasource.go @@ -83,7 +83,7 @@ func (r *credentialsGroupDataSource) Schema(_ context.Context, _ datasource.Sche "name": "The credentials group's display name.", "project_id": "Object Storage Project ID to which the credentials group is associated.", "urn": "Credentials group uniform resource name (URN)", - "region": "The resource region. If not defined, the provider region is used.", + "region": "The resource region. Read-only attribute that reflects the provider region.", } resp.Schema = schema.Schema{ @@ -117,7 +117,8 @@ func (r *credentialsGroupDataSource) Schema(_ context.Context, _ datasource.Sche }, "region": schema.StringAttribute{ // the region cannot be found automatically, so it has to be passed - Optional: true, + Optional: false, + Computed: true, Description: descriptions["region"], }, }, diff --git a/stackit/internal/services/objectstorage/credentialsgroup/resource.go b/stackit/internal/services/objectstorage/credentialsgroup/resource.go index 688891b4..be9c7b35 100644 --- a/stackit/internal/services/objectstorage/credentialsgroup/resource.go +++ b/stackit/internal/services/objectstorage/credentialsgroup/resource.go @@ -132,7 +132,7 @@ func (r *credentialsGroupResource) Schema(_ context.Context, _ resource.SchemaRe "name": "The credentials group's display name.", "project_id": "Project ID to which the credentials group is associated.", "urn": "Credentials group uniform resource name (URN)", - "region": "The resource region. If not defined, the provider region is used.", + "region": "The resource region. Read-only attribute that reflects the provider region.", } resp.Schema = schema.Schema{ @@ -174,7 +174,7 @@ func (r *credentialsGroupResource) Schema(_ context.Context, _ resource.SchemaRe Computed: true, }, "region": schema.StringAttribute{ - Optional: true, + Optional: false, // must be computed to allow for storing the override value from the provider Computed: true, Description: descriptions["region"],