From 2c6f1b66bacb44a85905b3bdad97f9f91dc1cb03 Mon Sep 17 00:00:00 2001 From: isaac Date: Wed, 7 Aug 2024 16:44:47 +0930 Subject: [PATCH] Some more updates --- docs/data-sources/environments.md | 15 +++--- docs/data-sources/feeds.md | 23 ++++----- docs/data-sources/git_credentials.md | 4 +- docs/data-sources/library_variable_sets.md | 4 +- docs/data-sources/lifecycles.md | 7 +-- docs/data-sources/space.md | 8 +-- docs/data-sources/spaces.md | 8 +-- docs/data-sources/tenants.md | 10 ++-- .../datasource_environments.go | 4 +- .../datasource_project_groups.go | 4 +- octopusdeploy_framework/datasource_spaces.go | 2 +- .../schemas/environment.go | 15 +++--- octopusdeploy_framework/schemas/feed.go | 33 ++++++------ .../schemas/gitCredential.go | 10 ++-- .../schemas/library_variable_set.go | 8 +-- octopusdeploy_framework/schemas/lifecycle.go | 10 ++-- octopusdeploy_framework/schemas/schema.go | 50 +++++++++++++++---- octopusdeploy_framework/schemas/space.go | 21 +++++--- octopusdeploy_framework/schemas/tenant.go | 13 +++-- octopusdeploy_framework/util/schema.go | 32 ++++-------- 20 files changed, 145 insertions(+), 136 deletions(-) diff --git a/docs/data-sources/environments.md b/docs/data-sources/environments.md index fe2db8529..7c2154936 100644 --- a/docs/data-sources/environments.md +++ b/docs/data-sources/environments.md @@ -39,26 +39,23 @@ data "octopusdeploy_environments" "example" { ### Nested Schema for `environments` -Required: +Optional: -- `name` (String) The name of this resource, no more than 50 characters long +- `jira_extension_settings` (Attributes List) Provides extension settings for the Jira integration for this environment. (see [below for nested schema](#nestedatt--environments--jira_extension_settings)) +- `space_id` (String) The space ID associated with this environment. -Optional: +Read-Only: - `allow_dynamic_infrastructure` (Boolean) +- `description` (String) The description of this environment. - `id` (String) The unique ID for this resource. -- `jira_extension_settings` (Attributes List) Provides extension settings for the Jira integration for this environment. (see [below for nested schema](#nestedatt--environments--jira_extension_settings)) - `jira_service_management_extension_settings` (Attributes List) Provides extension settings for the Jira Service Management (JSM) integration for this environment. (see [below for nested schema](#nestedatt--environments--jira_service_management_extension_settings)) +- `name` (String) The name of this resource. - `servicenow_extension_settings` (Attributes List) Provides extension settings for the ServiceNow integration for this environment. (see [below for nested schema](#nestedatt--environments--servicenow_extension_settings)) - `slug` (String) The unique slug of this environment - `sort_order` (Number) The order number to sort an environment -- `space_id` (String) The space ID associated with this environment. - `use_guided_failure` (Boolean) -Read-Only: - -- `description` (String) The description of this environment. - ### Nested Schema for `environments.jira_extension_settings` diff --git a/docs/data-sources/feeds.md b/docs/data-sources/feeds.md index 91fde3c96..7afdb726d 100644 --- a/docs/data-sources/feeds.md +++ b/docs/data-sources/feeds.md @@ -27,8 +27,6 @@ data "octopusdeploy_feeds" "example" { ### Optional - `feed_type` (String) A filter to search by feed type. Valid feed types are `AwsElasticContainerRegistry`, `BuiltIn`, `Docker`, `GitHub`, `Helm`, `Maven`, `NuGet`, or `OctopusProject`. -- `feeds` (Block List) (see [below for nested schema](#nestedblock--feeds)) -- `id` (String) The unique ID for this resource. - `ids` (List of String) A filter to search by a list of IDs. - `name` (String) The name of this resource. - `partial_name` (String) A filter to search by a partial name. @@ -36,31 +34,30 @@ data "octopusdeploy_feeds" "example" { - `space_id` (String) The space ID associated with this feeds. - `take` (Number) A filter to specify the number of items to take (or return) in the response. +### Read-Only + +- `feeds` (Block List) (see [below for nested schema](#nestedblock--feeds)) +- `id` (String) The unique ID for this resource. + ### Nested Schema for `feeds` -Required: +Read-Only: - `access_key` (String) The AWS access key to use when authenticating against Amazon Web Services. -- `feed_uri` (String) -- `name` (String) The name of this resource. - -Optional: - - `api_version` (String) - `delete_unreleased_packages_after_days` (Number) - `download_attempts` (Number) The number of times a deployment should attempt to download a package from this feed before failing. - `download_retry_backoff_seconds` (Number) The number of seconds to apply as a linear back off between download attempts. - `feed_type` (String) A filter to search by feed type. Valid feed types are `AwsElasticContainerRegistry`, `BuiltIn`, `Docker`, `GitHub`, `Helm`, `Maven`, `NuGet`, or `OctopusProject`. +- `feed_uri` (String) - `id` (String) The unique ID for this resource. - `is_enhanced_mode` (Boolean) +- `name` (String) The name of this resource. - `package_acquisition_location_options` (List of String) - `password` (String, Sensitive) The password associated with this resource. +- `region` (String) - `registry_path` (String) - `secret_key` (String, Sensitive) - `space_id` (String) The space ID associated with this feeds. -- `username` (String, Sensitive) The username associated with this resource. - -Read-Only: - -- `region` (String) \ No newline at end of file +- `username` (String, Sensitive) The username associated with this resource. \ No newline at end of file diff --git a/docs/data-sources/git_credentials.md b/docs/data-sources/git_credentials.md index 16eba8ac5..cfdeababb 100644 --- a/docs/data-sources/git_credentials.md +++ b/docs/data-sources/git_credentials.md @@ -32,13 +32,13 @@ A list of Git Credentials that match the filter(s). Optional: -- `id` (String) The unique ID for this resource. - `name` (String) A filter search by exact name -- `space_id` (String) The space ID associated with this Git Credential. Read-Only: - `description` (String) The description of this Git Credential. +- `id` (String) The unique ID for this resource. +- `space_id` (String) The space ID associated with this Git Credential. - `type` (String) The Git credential authentication type. - `username` (String) The username for the Git credential. diff --git a/docs/data-sources/library_variable_sets.md b/docs/data-sources/library_variable_sets.md index 8b6eeb19f..3b09deb58 100644 --- a/docs/data-sources/library_variable_sets.md +++ b/docs/data-sources/library_variable_sets.md @@ -32,13 +32,13 @@ Provides information about existing library variable sets. Optional: - `description` (String) The description of this library variable set. -- `id` (String) The unique ID for this resource. - `name` (String) The name of this resource. -- `space_id` (String) The space ID associated with this library variable set. - `template` (List of Object) (see [below for nested schema](#nestedatt--library_variable_sets--template)) Read-Only: +- `id` (String) The unique ID for this resource. +- `space_id` (String) The space ID associated with this library variable set. - `template_ids` (Map of String) - `variable_set_id` (String) diff --git a/docs/data-sources/lifecycles.md b/docs/data-sources/lifecycles.md index b637d14d8..1954554ba 100644 --- a/docs/data-sources/lifecycles.md +++ b/docs/data-sources/lifecycles.md @@ -44,16 +44,13 @@ Required: - `name` (String) The name of this resource. -Optional: - -- `id` (String) The unique ID for this resource. -- `space_id` (String) The space ID associated with this lifecycle. - Read-Only: - `description` (String) The description of this lifecycle. +- `id` (String) The unique ID for this resource. - `phase` (Attributes List) (see [below for nested schema](#nestedatt--lifecycles--phase)) - `release_retention_policy` (Attributes List) (see [below for nested schema](#nestedatt--lifecycles--release_retention_policy)) +- `space_id` (String) The space ID associated with this lifecycle. - `tentacle_retention_policy` (Attributes List) (see [below for nested schema](#nestedatt--lifecycles--tentacle_retention_policy)) diff --git a/docs/data-sources/space.md b/docs/data-sources/space.md index 42b588b46..e2cab7bad 100644 --- a/docs/data-sources/space.md +++ b/docs/data-sources/space.md @@ -15,16 +15,16 @@ Provides information about an existing space. ## Schema -### Required - -- `name` (String) The name of this resource, no more than 20 characters long - ### Optional - `description` (String) The description of this space. + +### Read-Only + - `id` (String) The unique ID for this resource. - `is_default` (Boolean) Specifies if this space is the default space in Octopus. - `is_task_queue_stopped` (Boolean) Specifies the status of the task queue for this space. +- `name` (String) The name of this resource, no more than 20 characters long - `slug` (String) The unique slug of this space - `space_managers_team_members` (Set of String) A list of user IDs designated to be managers of this space. - `space_managers_teams` (Set of String) A list of team IDs designated to be managers of this space. diff --git a/docs/data-sources/spaces.md b/docs/data-sources/spaces.md index 01ddee258..273f2784f 100644 --- a/docs/data-sources/spaces.md +++ b/docs/data-sources/spaces.md @@ -36,16 +36,16 @@ data "octopusdeploy_spaces" "spaces" { ### Nested Schema for `spaces` -Required: - -- `name` (String) The name of this resource, no more than 20 characters long - Optional: - `description` (String) The description of this space. + +Read-Only: + - `id` (String) The unique ID for this resource. - `is_default` (Boolean) Specifies if this space is the default space in Octopus. - `is_task_queue_stopped` (Boolean) Specifies the status of the task queue for this space. +- `name` (String) The name of this resource, no more than 20 characters long - `slug` (String) The unique slug of this space - `space_managers_team_members` (Set of String) A list of user IDs designated to be managers of this space. - `space_managers_teams` (Set of String) A list of team IDs designated to be managers of this space. diff --git a/docs/data-sources/tenants.md b/docs/data-sources/tenants.md index 2542c3d56..a43442882 100644 --- a/docs/data-sources/tenants.md +++ b/docs/data-sources/tenants.md @@ -28,21 +28,21 @@ Provides information about existing tenants. - `space_id` (String) The space ID associated with this tenants. - `tags` (List of String) A filter to search by a list of tags. - `take` (Number) A filter to specify the number of items to take (or return) in the response. + +### Read-Only + - `tenants` (Block List) A list of tenants that match the filter(s). (see [below for nested schema](#nestedblock--tenants)) ### Nested Schema for `tenants` -Optional: +Read-Only: - `cloned_from_tenant_id` (String) The ID of the tenant from which this tenant was cloned. +- `description` (String) The description of this tenants. - `id` (String) The unique ID for this resource. - `name` (String) The name of this resource. - `space_id` (String) The space ID associated with this tenant. - `tenant_tags` (List of String) A list of tenant tags associated with this resource. -Read-Only: - -- `description` (String) The description of this tenants. - diff --git a/octopusdeploy_framework/datasource_environments.go b/octopusdeploy_framework/datasource_environments.go index b788107d5..7677c90bd 100644 --- a/octopusdeploy_framework/datasource_environments.go +++ b/octopusdeploy_framework/datasource_environments.go @@ -45,14 +45,14 @@ func (*environmentDataSource) Schema(_ context.Context, req datasource.SchemaReq Attributes: map[string]schema.Attribute{ //request "ids": util.GetQueryIDsDatasourceSchema(), - "space_id": util.GetSpaceIdDatasourceSchema(schemas.EnvironmentResourceDescription), + "space_id": schemas.GetSpaceIdDatasourceSchema(schemas.EnvironmentResourceDescription, false), "name": util.GetQueryNameDatasourceSchema(), "partial_name": util.GetQueryPartialNameDatasourceSchema(), "skip": util.GetQuerySkipDatasourceSchema(), "take": util.GetQueryTakeDatasourceSchema(), //response - "id": util.GetIdDatasourceSchema(), + "id": schemas.GetIdDatasourceSchema(false), }, Blocks: map[string]schema.Block{ "environments": schema.ListNestedBlock{ diff --git a/octopusdeploy_framework/datasource_project_groups.go b/octopusdeploy_framework/datasource_project_groups.go index 01713abbc..ab046b0b2 100644 --- a/octopusdeploy_framework/datasource_project_groups.go +++ b/octopusdeploy_framework/datasource_project_groups.go @@ -50,14 +50,14 @@ func (p *projectGroupsDataSource) Schema(_ context.Context, _ datasource.SchemaR resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ // request - "space_id": util.GetSpaceIdDatasourceSchema(description), + "space_id": schemas.GetSpaceIdDatasourceSchema(description, false), "ids": util.GetQueryIDsDatasourceSchema(), "partial_name": util.GetQueryPartialNameDatasourceSchema(), "skip": util.GetQuerySkipDatasourceSchema(), "take": util.GetQueryTakeDatasourceSchema(), // response - "id": util.GetIdDatasourceSchema(), + "id": schemas.GetIdDatasourceSchema(false), }, Blocks: map[string]schema.Block{ "project_groups": schema.ListNestedBlock{ diff --git a/octopusdeploy_framework/datasource_spaces.go b/octopusdeploy_framework/datasource_spaces.go index c7ec6414c..04a9f9309 100644 --- a/octopusdeploy_framework/datasource_spaces.go +++ b/octopusdeploy_framework/datasource_spaces.go @@ -42,7 +42,7 @@ func (*spacesDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, r "take": schemas.GetQueryTakeDatasourceSchema(), // response - "id": schemas.GetIdDatasourceSchema(), + "id": schemas.GetIdDatasourceSchema(false), }, Blocks: map[string]schema.Block{ "spaces": schema.ListNestedBlock{ diff --git a/octopusdeploy_framework/schemas/environment.go b/octopusdeploy_framework/schemas/environment.go index af4a31e20..4d5109f1a 100644 --- a/octopusdeploy_framework/schemas/environment.go +++ b/octopusdeploy_framework/schemas/environment.go @@ -27,21 +27,20 @@ const ( func GetEnvironmentDatasourceSchema() map[string]datasourceSchema.Attribute { return map[string]datasourceSchema.Attribute{ - "id": util.GetIdDatasourceSchema(), - "slug": util.GetSlugDatasourceSchema(EnvironmentResourceDescription), - "name": util.GetNameDatasourceWithMaxLengthSchema(true, 50), + "id": GetIdDatasourceSchema(true), + "slug": util.GetSlugDatasourceSchema(EnvironmentResourceDescription, true), + "name": GetReadonlyNameDatasourceSchema(), "description": util.GetDescriptionDatasourceSchema(EnvironmentResourceDescription), EnvironmentSortOrder: util.GetSortOrderDataSourceSchema(EnvironmentResourceDescription), EnvironmentAllowDynamicInfrastructure: datasourceSchema.BoolAttribute{ - Optional: true, + Computed: true, }, EnvironmentUseGuidedFailure: datasourceSchema.BoolAttribute{ - Optional: true, + Computed: true, }, - "space_id": util.GetSpaceIdDatasourceSchema(EnvironmentResourceDescription), + "space_id": GetSpaceIdDatasourceSchema(EnvironmentResourceDescription, true), EnvironmentJiraExtensionSettings: datasourceSchema.ListNestedAttribute{ Description: "Provides extension settings for the Jira integration for this environment.", - Optional: true, Computed: true, NestedObject: datasourceSchema.NestedAttributeObject{ Attributes: map[string]datasourceSchema.Attribute{ @@ -62,7 +61,6 @@ func GetEnvironmentDatasourceSchema() map[string]datasourceSchema.Attribute { }, EnvironmentJiraServiceManagementExtensionSettings: datasourceSchema.ListNestedAttribute{ Description: "Provides extension settings for the Jira Service Management (JSM) integration for this environment.", - Optional: true, Computed: true, NestedObject: datasourceSchema.NestedAttributeObject{ Attributes: map[string]datasourceSchema.Attribute{ @@ -72,7 +70,6 @@ func GetEnvironmentDatasourceSchema() map[string]datasourceSchema.Attribute { }, EnvironmentServiceNowExtensionSettings: datasourceSchema.ListNestedAttribute{ Description: "Provides extension settings for the ServiceNow integration for this environment.", - Optional: true, Computed: true, NestedObject: datasourceSchema.NestedAttributeObject{ Attributes: map[string]datasourceSchema.Attribute{ diff --git a/octopusdeploy_framework/schemas/feed.go b/octopusdeploy_framework/schemas/feed.go index 60a084e64..61b01ae23 100644 --- a/octopusdeploy_framework/schemas/feed.go +++ b/octopusdeploy_framework/schemas/feed.go @@ -78,10 +78,10 @@ func GetFeedsDataSourceSchema() map[string]datasourceSchema.Attribute { "partial_name": util.GetQueryPartialNameDatasourceSchema(), "skip": util.GetQuerySkipDatasourceSchema(), "take": util.GetQueryTakeDatasourceSchema(), - "space_id": util.GetSpaceIdDatasourceSchema("feeds"), + "space_id": GetSpaceIdDatasourceSchema("feeds", false), // response - "id": util.GetIdDatasourceSchema(), + "id": GetIdDatasourceSchema(true), } } @@ -89,7 +89,7 @@ func GetFeedDataSourceSchema() map[string]datasourceSchema.Attribute { return map[string]datasourceSchema.Attribute{ "feed_type": datasourceSchema.StringAttribute{ Description: "A filter to search by feed type. Valid feed types are `AwsElasticContainerRegistry`, `BuiltIn`, `Docker`, `GitHub`, `Helm`, `Maven`, `NuGet`, or `OctopusProject`.", - Optional: true, + Computed: true, Validators: []validator.String{ stringvalidator.OneOf( "AwsElasticContainerRegistry", @@ -103,17 +103,17 @@ func GetFeedDataSourceSchema() map[string]datasourceSchema.Attribute { }, }, "feed_uri": datasourceSchema.StringAttribute{ - Required: true, + Computed: true, }, - "id": util.GetIdDatasourceSchema(), + "id": GetIdDatasourceSchema(true), "is_enhanced_mode": datasourceSchema.BoolAttribute{ - Optional: true, + Computed: true, }, - "name": util.GetNameDatasourceSchema(true), + "name": GetReadonlyNameDatasourceSchema(), "password": datasourceSchema.StringAttribute{ Description: "The password associated with this resource.", Sensitive: true, - Optional: true, + Computed: true, Validators: []validator.String{ stringvalidator.LengthAtLeast(1), }, @@ -121,45 +121,42 @@ func GetFeedDataSourceSchema() map[string]datasourceSchema.Attribute { "package_acquisition_location_options": datasourceSchema.ListAttribute{ Computed: true, ElementType: types.StringType, - Optional: true, }, "region": datasourceSchema.StringAttribute{ Computed: true, }, "registry_path": datasourceSchema.StringAttribute{ - Optional: true, + Computed: true, }, "secret_key": datasourceSchema.StringAttribute{ - Optional: true, + Computed: true, Sensitive: true, }, - "space_id": util.GetSpaceIdDatasourceSchema("feeds"), + "space_id": GetSpaceIdDatasourceSchema("feeds", true), "username": datasourceSchema.StringAttribute{ Description: "The username associated with this resource.", Sensitive: true, - Optional: true, + Computed: true, Validators: []validator.String{ stringvalidator.LengthAtLeast(1), }, }, "delete_unreleased_packages_after_days": datasourceSchema.Int64Attribute{ - Optional: true, + Computed: true, }, "access_key": datasourceSchema.StringAttribute{ - Required: true, + Computed: true, Description: "The AWS access key to use when authenticating against Amazon Web Services.", }, "api_version": datasourceSchema.StringAttribute{ - Optional: true, + Computed: true, }, "download_attempts": datasourceSchema.Int64Attribute{ Description: "The number of times a deployment should attempt to download a package from this feed before failing.", - Optional: true, Computed: true, }, "download_retry_backoff_seconds": datasourceSchema.Int64Attribute{ Description: "The number of seconds to apply as a linear back off between download attempts.", - Optional: true, Computed: true, }, } diff --git a/octopusdeploy_framework/schemas/gitCredential.go b/octopusdeploy_framework/schemas/gitCredential.go index 2a29f1b4d..5e3f07a33 100644 --- a/octopusdeploy_framework/schemas/gitCredential.go +++ b/octopusdeploy_framework/schemas/gitCredential.go @@ -47,8 +47,8 @@ func GetGitCredentialResourceSchema() resourceSchema.Schema { func GetGitCredentialDataSourceSchema() map[string]datasourceSchema.Attribute { return map[string]datasourceSchema.Attribute{ - "id": util.GetIdDatasourceSchema(), - "space_id": util.GetSpaceIdDatasourceSchema(GitCredentialResourceDescription), + "id": GetIdDatasourceSchema(false), + "space_id": GetSpaceIdDatasourceSchema(GitCredentialResourceDescription, false), "name": util.GetQueryNameDatasourceSchema(), "skip": util.GetQuerySkipDatasourceSchema(), "take": util.GetQueryTakeDatasourceSchema(), @@ -64,9 +64,9 @@ func GetGitCredentialDataSourceSchema() map[string]datasourceSchema.Attribute { func GetGitCredentialAttributes() map[string]datasourceSchema.Attribute { return map[string]datasourceSchema.Attribute{ - "id": util.GetIdDatasourceSchema(), - "space_id": util.GetSpaceIdDatasourceSchema(GitCredentialResourceDescription), - "name": util.GetQueryNameDatasourceSchema(), + "id": GetIdDatasourceSchema(true), + "space_id": GetSpaceIdDatasourceSchema(GitCredentialResourceDescription, true), + "name": GetReadonlyNameDatasourceSchema(), "description": util.GetDescriptionDatasourceSchema(GitCredentialResourceDescription), "type": datasourceSchema.StringAttribute{ Computed: true, diff --git a/octopusdeploy_framework/schemas/library_variable_set.go b/octopusdeploy_framework/schemas/library_variable_set.go index 5fab75d02..0d110a5c9 100644 --- a/octopusdeploy_framework/schemas/library_variable_set.go +++ b/octopusdeploy_framework/schemas/library_variable_set.go @@ -41,8 +41,8 @@ func getLibraryVariableSetDataSchema() map[string]datasourceSchema.Attribute { Description: "A filter to search by content type.", Optional: true, }, - "id": util.GetIdDatasourceSchema(), - "space_id": util.GetSpaceIdDatasourceSchema("library variable set"), + "id": GetIdDatasourceSchema(false), + "space_id": GetSpaceIdDatasourceSchema("library variable set", false), "ids": util.GetQueryIDsDatasourceSchema(), "partial_name": util.GetQueryPartialNameDatasourceSchema(), "skip": util.GetQuerySkipDatasourceSchema(), @@ -53,9 +53,9 @@ func getLibraryVariableSetDataSchema() map[string]datasourceSchema.Attribute { func GetLibraryVariableSetObjectDatasourceSchema() map[string]datasourceSchema.Attribute { return map[string]datasourceSchema.Attribute{ "description": GetDescriptionDatasourceSchema("library variable set"), - "id": GetIdDatasourceSchema(), + "id": GetIdDatasourceSchema(true), "name": GetNameDatasourceSchema(false), - "space_id": GetSpaceIdDatasourceSchema("library variable set"), + "space_id": GetSpaceIdDatasourceSchema("library variable set", true), "template_ids": datasourceSchema.MapAttribute{ ElementType: types.StringType, Computed: true, diff --git a/octopusdeploy_framework/schemas/lifecycle.go b/octopusdeploy_framework/schemas/lifecycle.go index 092d48ab6..916e139bf 100644 --- a/octopusdeploy_framework/schemas/lifecycle.go +++ b/octopusdeploy_framework/schemas/lifecycle.go @@ -89,8 +89,8 @@ func GetDatasourceLifecycleSchema() datasourceSchema.Schema { description := "lifecycle" return datasourceSchema.Schema{ Attributes: map[string]datasourceSchema.Attribute{ - "id": util.GetIdDatasourceSchema(), - "space_id": util.GetSpaceIdDatasourceSchema(description), + "id": GetIdDatasourceSchema(false), + "space_id": GetSpaceIdDatasourceSchema(description, false), "ids": util.GetQueryIDsDatasourceSchema(), "partial_name": util.GetQueryPartialNameDatasourceSchema(), "skip": util.GetQuerySkipDatasourceSchema(), @@ -99,8 +99,8 @@ func GetDatasourceLifecycleSchema() datasourceSchema.Schema { Computed: true, NestedObject: datasourceSchema.NestedAttributeObject{ Attributes: map[string]datasourceSchema.Attribute{ - "id": util.GetIdDatasourceSchema(), - "space_id": util.GetSpaceIdDatasourceSchema(description), + "id": GetIdDatasourceSchema(true), + "space_id": GetSpaceIdDatasourceSchema(description, true), "name": util.GetNameDatasourceSchema(true), "description": util.GetDescriptionDatasourceSchema(description), "phase": getDatasourcePhasesSchema(), @@ -118,7 +118,7 @@ func getDatasourcePhasesSchema() datasourceSchema.ListNestedAttribute { Computed: true, NestedObject: datasourceSchema.NestedAttributeObject{ Attributes: map[string]datasourceSchema.Attribute{ - "id": util.GetIdDatasourceSchema(), + "id": GetIdDatasourceSchema(false), "name": util.GetNameDatasourceSchema(true), "automatic_deployment_targets": datasourceSchema.ListAttribute{ElementType: types.StringType, Computed: true}, "optional_deployment_targets": datasourceSchema.ListAttribute{ElementType: types.StringType, Computed: true}, diff --git a/octopusdeploy_framework/schemas/schema.go b/octopusdeploy_framework/schemas/schema.go index ea92da635..b3071aae3 100644 --- a/octopusdeploy_framework/schemas/schema.go +++ b/octopusdeploy_framework/schemas/schema.go @@ -55,20 +55,41 @@ func GetQueryTakeDatasourceSchema() datasourceSchema.Attribute { } } -func GetIdDatasourceSchema() datasourceSchema.Attribute { +func GetReadonlyNameDatasourceSchema() datasourceSchema.Attribute { return datasourceSchema.StringAttribute{ - Description: "The unique ID for this resource.", + Description: "The name of this resource.", Computed: true, - Optional: true, } } -func GetSpaceIdDatasourceSchema(resourceDescription string) datasourceSchema.Attribute { - return datasourceSchema.StringAttribute{ +func GetIdDatasourceSchema(isReadOnly bool) datasourceSchema.Attribute { + s := datasourceSchema.StringAttribute{ + Description: "The unique ID for this resource.", + } + + if isReadOnly { + s.Computed = true + } else { + s.Computed = true + s.Optional = true + } + + return s +} + +func GetSpaceIdDatasourceSchema(resourceDescription string, isReadOnly bool) datasourceSchema.Attribute { + s := datasourceSchema.StringAttribute{ Description: "The space ID associated with this " + resourceDescription + ".", - Computed: true, - Optional: true, } + + if isReadOnly { + s.Computed = true + } else { + s.Computed = true + s.Optional = true + } + + return s } func GetNameDatasourceWithMaxLengthSchema(isRequired bool, maxLength int) datasourceSchema.Attribute { @@ -154,12 +175,19 @@ func GetDescriptionResourceSchema(resourceDescription string) resourceSchema.Att } } -func GetSlugDatasourceSchema(resourceDescription string) datasourceSchema.Attribute { - return datasourceSchema.StringAttribute{ +func GetSlugDatasourceSchema(resourceDescription string, isReadOnly bool) datasourceSchema.Attribute { + s := datasourceSchema.StringAttribute{ Description: fmt.Sprintf("The unique slug of this %s", resourceDescription), - Optional: true, - Computed: true, } + + if isReadOnly { + s.Computed = true + } else { + s.Optional = true + s.Computed = true + } + + return s } func GetSlugResourceSchema(resourceDescription string) resourceSchema.Attribute { diff --git a/octopusdeploy_framework/schemas/space.go b/octopusdeploy_framework/schemas/space.go index c14354752..eb818e338 100644 --- a/octopusdeploy_framework/schemas/space.go +++ b/octopusdeploy_framework/schemas/space.go @@ -1,10 +1,13 @@ package schemas import ( + "fmt" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -56,29 +59,33 @@ func GetSpaceResourceSchema() map[string]resourceSchema.Attribute { func GetSpaceDatasourceSchema() map[string]datasourceSchema.Attribute { return map[string]datasourceSchema.Attribute{ - "id": GetIdDatasourceSchema(), + "id": GetIdDatasourceSchema(true), "description": GetDescriptionDatasourceSchema(spaceDescription), - "name": GetNameDatasourceWithMaxLengthSchema(true, 20), - "slug": GetSlugDatasourceSchema(spaceDescription), + "name": datasourceSchema.StringAttribute{ + Description: fmt.Sprintf("The name of this resource, no more than %d characters long", 20), + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 20), + }, + Computed: true, + }, + "slug": GetSlugDatasourceSchema(spaceDescription, true), "space_managers_teams": datasourceSchema.SetAttribute{ ElementType: types.StringType, Description: "A list of team IDs designated to be managers of this space.", - Optional: true, Computed: true, }, "space_managers_team_members": datasourceSchema.SetAttribute{ ElementType: types.StringType, Description: "A list of user IDs designated to be managers of this space.", - Optional: true, Computed: true, }, "is_task_queue_stopped": datasourceSchema.BoolAttribute{ Description: "Specifies the status of the task queue for this space.", - Optional: true, + Computed: true, }, "is_default": datasourceSchema.BoolAttribute{ Description: "Specifies if this space is the default space in Octopus.", - Optional: true, + Computed: true, }, } } diff --git a/octopusdeploy_framework/schemas/tenant.go b/octopusdeploy_framework/schemas/tenant.go index a2865755c..b5ae61b19 100644 --- a/octopusdeploy_framework/schemas/tenant.go +++ b/octopusdeploy_framework/schemas/tenant.go @@ -66,7 +66,7 @@ func GetTenantsDataSourceSchema() map[string]datasourceSchema.Attribute { Description: "A filter to search for a cloned tenant by its ID.", Optional: true, }, - "id": util.GetIdDatasourceSchema(), + "id": GetIdDatasourceSchema(false), "ids": util.GetQueryIDsDatasourceSchema(), "is_clone": datasourceSchema.BoolAttribute{ Description: "A filter to search for cloned resources.", @@ -83,7 +83,7 @@ func GetTenantsDataSourceSchema() map[string]datasourceSchema.Attribute { }, "skip": util.GetQuerySkipDatasourceSchema(), "tags": util.GetQueryDatasourceTags(), - "space_id": util.GetSpaceIdDatasourceSchema("tenants"), + "space_id": GetSpaceIdDatasourceSchema("tenants", false), "take": util.GetQueryTakeDatasourceSchema(), } } @@ -92,17 +92,16 @@ func GetTenantDataSourceSchema() map[string]datasourceSchema.Attribute { return map[string]datasourceSchema.Attribute{ "cloned_from_tenant_id": datasourceSchema.StringAttribute{ Description: "The ID of the tenant from which this tenant was cloned.", - Optional: true, + Computed: true, }, "description": util.GetDescriptionDatasourceSchema("tenants"), - "id": util.GetIdDatasourceSchema(), - "name": util.GetNameDatasourceSchema(false), - "space_id": util.GetSpaceIdDatasourceSchema("tenant"), + "id": GetIdDatasourceSchema(true), + "name": GetReadonlyNameDatasourceSchema(), + "space_id": GetSpaceIdDatasourceSchema("tenant", true), "tenant_tags": datasourceSchema.ListAttribute{ Computed: true, Description: "A list of tenant tags associated with this resource.", ElementType: types.StringType, - Optional: true, }, } } diff --git a/octopusdeploy_framework/util/schema.go b/octopusdeploy_framework/util/schema.go index 4b8c49bcd..d8108b803 100644 --- a/octopusdeploy_framework/util/schema.go +++ b/octopusdeploy_framework/util/schema.go @@ -60,22 +60,6 @@ func GetQueryTakeDatasourceSchema() datasourceSchema.Attribute { } } -func GetIdDatasourceSchema() datasourceSchema.Attribute { - return datasourceSchema.StringAttribute{ - Description: "The unique ID for this resource.", - Computed: true, - Optional: true, - } -} - -func GetSpaceIdDatasourceSchema(resourceDescription string) datasourceSchema.Attribute { - return datasourceSchema.StringAttribute{ - Description: "The space ID associated with this " + resourceDescription + ".", - Computed: true, - Optional: true, - } -} - func GetNameDatasourceWithMaxLengthSchema(isRequired bool, maxLength int) datasourceSchema.Attribute { s := datasourceSchema.StringAttribute{ Description: fmt.Sprintf("The name of this resource, no more than %d characters long", maxLength), @@ -173,12 +157,19 @@ func GetDescriptionResourceSchema(resourceDescription string) resourceSchema.Att } } -func GetSlugDatasourceSchema(resourceDescription string) resourceSchema.Attribute { - return resourceSchema.StringAttribute{ +func GetSlugDatasourceSchema(resourceDescription string, isReadOnly bool) datasourceSchema.Attribute { + s := datasourceSchema.StringAttribute{ Description: fmt.Sprintf("The unique slug of this %s", resourceDescription), - Optional: true, - Computed: true, } + + if isReadOnly { + s.Computed = true + } else { + s.Optional = true + s.Computed = true + } + + return s } func GetSlugResourceSchema(resourceDescription string) resourceSchema.Attribute { @@ -192,7 +183,6 @@ func GetSlugResourceSchema(resourceDescription string) resourceSchema.Attribute func GetSortOrderDataSourceSchema(resourceDescription string) resourceSchema.Attribute { return resourceSchema.Int64Attribute{ Description: fmt.Sprintf("The order number to sort an %s", resourceDescription), - Optional: true, Computed: true, } }