From 721731321c6b1f673f9a645ac815744356a4708e Mon Sep 17 00:00:00 2001 From: Ben Pearce Date: Thu, 22 Aug 2024 17:20:51 +1000 Subject: [PATCH] fix: fix datasource result blocks (#763) --- docs/data-sources/environments.md | 4 +-- docs/data-sources/feeds.md | 4 +-- docs/data-sources/library_variable_sets.md | 4 +-- docs/data-sources/project_groups.md | 4 +-- docs/data-sources/spaces.md | 4 +-- docs/data-sources/tag_sets.md | 12 +++---- docs/data-sources/tenant_projects.md | 4 +-- docs/data-sources/variables.md | 4 +-- .../datasource_environments.go | 9 +++-- octopusdeploy_framework/datasource_feeds.go | 7 ---- .../datasource_project_groups.go | 7 ++-- octopusdeploy_framework/datasource_spaces.go | 9 +++-- .../datasource_tenant_projects.go | 8 ++--- octopusdeploy_framework/schemas/feed.go | 7 ++++ .../schemas/gitCredential.go | 1 + .../schemas/library_variable_set.go | 35 ++++++++----------- octopusdeploy_framework/schemas/lifecycle.go | 1 + octopusdeploy_framework/schemas/tag_set.go | 28 +++++++++++++-- octopusdeploy_framework/schemas/variable.go | 4 +-- .../schemas/variable_scope.go | 8 ++--- 20 files changed, 90 insertions(+), 74 deletions(-) diff --git a/docs/data-sources/environments.md b/docs/data-sources/environments.md index d67c25219..c028f00a7 100644 --- a/docs/data-sources/environments.md +++ b/docs/data-sources/environments.md @@ -36,10 +36,10 @@ data "octopusdeploy_environments" "example" { ### Read-Only -- `environments` (Block List) Provides information about existing environments. (see [below for nested schema](#nestedblock--environments)) +- `environments` (Attributes List) (see [below for nested schema](#nestedatt--environments)) - `id` (String) The unique ID for this resource. - + ### Nested Schema for `environments` Read-Only: diff --git a/docs/data-sources/feeds.md b/docs/data-sources/feeds.md index 7afdb726d..3cc2e6fd9 100644 --- a/docs/data-sources/feeds.md +++ b/docs/data-sources/feeds.md @@ -36,10 +36,10 @@ data "octopusdeploy_feeds" "example" { ### Read-Only -- `feeds` (Block List) (see [below for nested schema](#nestedblock--feeds)) +- `feeds` (Attributes List) (see [below for nested schema](#nestedatt--feeds)) - `id` (String) The unique ID for this resource. - + ### Nested Schema for `feeds` Read-Only: diff --git a/docs/data-sources/library_variable_sets.md b/docs/data-sources/library_variable_sets.md index 9b10353eb..66a69bee8 100644 --- a/docs/data-sources/library_variable_sets.md +++ b/docs/data-sources/library_variable_sets.md @@ -27,9 +27,9 @@ Provides information about existing library variable sets. ### Read-Only - `id` (String) The unique ID for this resource. -- `library_variable_sets` (Block List) A list of library variable sets that match the filter(s). (see [below for nested schema](#nestedblock--library_variable_sets)) +- `library_variable_sets` (Attributes List) (see [below for nested schema](#nestedatt--library_variable_sets)) - + ### Nested Schema for `library_variable_sets` Read-Only: diff --git a/docs/data-sources/project_groups.md b/docs/data-sources/project_groups.md index d956ca1b3..63d339a72 100644 --- a/docs/data-sources/project_groups.md +++ b/docs/data-sources/project_groups.md @@ -35,9 +35,9 @@ data "octopusdeploy_project_groups" "example" { ### Read-Only - `id` (String) The unique ID for this resource. -- `project_groups` (Block List) A list of project groups that match the filter(s). (see [below for nested schema](#nestedblock--project_groups)) +- `project_groups` (Attributes List) A list of project groups that match the filter(s). (see [below for nested schema](#nestedatt--project_groups)) - + ### Nested Schema for `project_groups` Read-Only: diff --git a/docs/data-sources/spaces.md b/docs/data-sources/spaces.md index 612366c9e..8313e89c9 100644 --- a/docs/data-sources/spaces.md +++ b/docs/data-sources/spaces.md @@ -34,9 +34,9 @@ data "octopusdeploy_spaces" "spaces" { ### Read-Only - `id` (String) The unique ID for this resource. -- `spaces` (Block List) Provides information about existing spaces. (see [below for nested schema](#nestedblock--spaces)) +- `spaces` (Attributes List) (see [below for nested schema](#nestedatt--spaces)) - + ### Nested Schema for `spaces` Read-Only: diff --git a/docs/data-sources/tag_sets.md b/docs/data-sources/tag_sets.md index 56b41b61b..d13876c4e 100644 --- a/docs/data-sources/tag_sets.md +++ b/docs/data-sources/tag_sets.md @@ -26,17 +26,17 @@ Provides information about existing tag sets. ### Read-Only - `id` (String) The ID of this resource. -- `tag_sets` (List of Object) A list of tag sets that match the filter(s). (see [below for nested schema](#nestedatt--tag_sets)) +- `tag_sets` (Attributes List) A list of tag sets that match the filter(s). (see [below for nested schema](#nestedatt--tag_sets)) ### Nested Schema for `tag_sets` Read-Only: -- `description` (String) -- `id` (String) -- `name` (String) -- `sort_order` (Number) -- `space_id` (String) +- `description` (String) The description of this tag set. +- `id` (String) The unique ID for this resource. +- `name` (String) The name of this resource. +- `sort_order` (Number) The sort order associated with this resource. +- `space_id` (String) The space ID associated with this resource. diff --git a/docs/data-sources/tenant_projects.md b/docs/data-sources/tenant_projects.md index 4275f7459..23b39f665 100644 --- a/docs/data-sources/tenant_projects.md +++ b/docs/data-sources/tenant_projects.md @@ -24,9 +24,9 @@ Provides information about existing tenants. ### Read-Only -- `tenant_projects` (Block List) A list of related tenants, projects and environments that match the filter(s). (see [below for nested schema](#nestedblock--tenant_projects)) +- `tenant_projects` (Attributes List) A list of related tenants, projects and environments that match the filter(s). (see [below for nested schema](#nestedatt--tenant_projects)) - + ### Nested Schema for `tenant_projects` Read-Only: diff --git a/docs/data-sources/variables.md b/docs/data-sources/variables.md index 558e16455..d51c6d5c0 100644 --- a/docs/data-sources/variables.md +++ b/docs/data-sources/variables.md @@ -24,10 +24,10 @@ data "octopusdeploy_variables" "example" { - `name` (String) The name of variable to find. - `owner_id` (String) Owner ID for the variable to find. +- `scope` (Attributes List) As variable names can appear more than once under different scopes, a VariableScope must also be provided (see [below for nested schema](#nestedatt--scope)) ### Optional -- `scope` (Block List) As variable names can appear more than once under different scopes, a VariableScope must also be provided (see [below for nested schema](#nestedblock--scope)) - `space_id` (String) A Space ID to filter by. Will revert what is specified on the provider if not set. ### Read-Only @@ -41,7 +41,7 @@ data "octopusdeploy_variables" "example" { - `type` (String) The type of variable represented by this resource. Valid types are `AmazonWebServicesAccount`, `AzureAccount`, `GoogleCloudAccount`, `UsernamePasswordAccount`, `Certificate`, `Sensitive`, `String`, `WorkerPool`. - `value` (String) - + ### Nested Schema for `scope` Optional: diff --git a/octopusdeploy_framework/datasource_environments.go b/octopusdeploy_framework/datasource_environments.go index d8ff7c4f8..df7b0993c 100644 --- a/octopusdeploy_framework/datasource_environments.go +++ b/octopusdeploy_framework/datasource_environments.go @@ -52,11 +52,10 @@ func (*environmentDataSource) Schema(_ context.Context, req datasource.SchemaReq //response "id": schemas.GetIdDatasourceSchema(true), - }, - Blocks: map[string]schema.Block{ - "environments": schema.ListNestedBlock{ - Description: "Provides information about existing environments.", - NestedObject: schema.NestedBlockObject{ + "environments": schema.ListNestedAttribute{ + Computed: true, + Optional: false, + NestedObject: schema.NestedAttributeObject{ Attributes: schemas.GetEnvironmentDatasourceSchema(), }, }, diff --git a/octopusdeploy_framework/datasource_feeds.go b/octopusdeploy_framework/datasource_feeds.go index 58fcd2087..ac178edac 100644 --- a/octopusdeploy_framework/datasource_feeds.go +++ b/octopusdeploy_framework/datasource_feeds.go @@ -32,13 +32,6 @@ func (*feedsDataSource) Schema(_ context.Context, req datasource.SchemaRequest, resp.Schema = datasourceSchema.Schema{ Description: "Provides information about existing feeds.", Attributes: schemas.GetFeedsDataSourceSchema(), - Blocks: map[string]datasourceSchema.Block{ - "feeds": datasourceSchema.ListNestedBlock{ - NestedObject: datasourceSchema.NestedBlockObject{ - Attributes: schemas.GetFeedDataSourceSchema(), - }, - }, - }, } } diff --git a/octopusdeploy_framework/datasource_project_groups.go b/octopusdeploy_framework/datasource_project_groups.go index 5f8ac460c..1e25a0912 100644 --- a/octopusdeploy_framework/datasource_project_groups.go +++ b/octopusdeploy_framework/datasource_project_groups.go @@ -57,11 +57,10 @@ func (p *projectGroupsDataSource) Schema(_ context.Context, _ datasource.SchemaR // response "id": schemas.GetIdDatasourceSchema(true), - }, - Blocks: map[string]schema.Block{ - "project_groups": schema.ListNestedBlock{ + "project_groups": schema.ListNestedAttribute{ + Computed: true, Description: "A list of project groups that match the filter(s).", - NestedObject: schema.NestedBlockObject{ + NestedObject: schema.NestedAttributeObject{ Attributes: schemas.GetProjectGroupDatasourceSchema(), }, }, diff --git a/octopusdeploy_framework/datasource_spaces.go b/octopusdeploy_framework/datasource_spaces.go index 5828974b0..9bc1ee3b5 100644 --- a/octopusdeploy_framework/datasource_spaces.go +++ b/octopusdeploy_framework/datasource_spaces.go @@ -43,11 +43,10 @@ func (*spacesDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, r // response "id": schemas.GetIdDatasourceSchema(true), - }, - Blocks: map[string]schema.Block{ - "spaces": schema.ListNestedBlock{ - Description: "Provides information about existing spaces.", - NestedObject: schema.NestedBlockObject{ + "spaces": schema.ListNestedAttribute{ + Computed: true, + Optional: false, + NestedObject: schema.NestedAttributeObject{ Attributes: schemas.GetSpacesDatasourceSchema(), }, }, diff --git a/octopusdeploy_framework/datasource_tenant_projects.go b/octopusdeploy_framework/datasource_tenant_projects.go index 2814811c9..8bf5dbf2c 100644 --- a/octopusdeploy_framework/datasource_tenant_projects.go +++ b/octopusdeploy_framework/datasource_tenant_projects.go @@ -46,11 +46,11 @@ func (*tenantProjectsDataSource) Schema(_ context.Context, req datasource.Schema "project_ids": schemas.GetQueryIDsDatasourceSchema(), "environment_ids": schemas.GetQueryIDsDatasourceSchema(), "space_id": schemas.GetSpaceIdDatasourceSchema("tenant projects", false), - }, - Blocks: map[string]datasourceSchema.Block{ - "tenant_projects": datasourceSchema.ListNestedBlock{ + "tenant_projects": datasourceSchema.ListNestedAttribute{ + Computed: true, + Optional: false, Description: "A list of related tenants, projects and environments that match the filter(s).", - NestedObject: datasourceSchema.NestedBlockObject{ + NestedObject: datasourceSchema.NestedAttributeObject{ Attributes: map[string]datasourceSchema.Attribute{ "id": schemas.GetIdDatasourceSchema(true), "tenant_id": datasourceSchema.StringAttribute{ diff --git a/octopusdeploy_framework/schemas/feed.go b/octopusdeploy_framework/schemas/feed.go index 61b01ae23..edacbed95 100644 --- a/octopusdeploy_framework/schemas/feed.go +++ b/octopusdeploy_framework/schemas/feed.go @@ -82,6 +82,13 @@ func GetFeedsDataSourceSchema() map[string]datasourceSchema.Attribute { // response "id": GetIdDatasourceSchema(true), + "feeds": datasourceSchema.ListNestedAttribute{ + Computed: true, + Optional: false, + NestedObject: datasourceSchema.NestedAttributeObject{ + Attributes: GetFeedDataSourceSchema(), + }, + }, } } diff --git a/octopusdeploy_framework/schemas/gitCredential.go b/octopusdeploy_framework/schemas/gitCredential.go index 071461f7f..1352a2ddc 100644 --- a/octopusdeploy_framework/schemas/gitCredential.go +++ b/octopusdeploy_framework/schemas/gitCredential.go @@ -53,6 +53,7 @@ func GetGitCredentialDataSourceSchema() datasourceSchema.Schema { "take": util.DataSourceInt64().Optional().Description("The number of records to take.").Build(), "git_credentials": datasourceSchema.ListNestedAttribute{ Computed: true, + Optional: false, Description: "Provides information about existing GitCredentials.", NestedObject: datasourceSchema.NestedAttributeObject{ Attributes: GetGitCredentialDatasourceAttributes(), diff --git a/octopusdeploy_framework/schemas/library_variable_set.go b/octopusdeploy_framework/schemas/library_variable_set.go index efec16d39..c449dc51f 100644 --- a/octopusdeploy_framework/schemas/library_variable_set.go +++ b/octopusdeploy_framework/schemas/library_variable_set.go @@ -25,12 +25,22 @@ type LibraryVariableSetResourceModel struct { func GetLibraryVariableSetDataSourceSchema() datasourceSchema.Schema { return datasourceSchema.Schema{ - Attributes: getLibraryVariableSetDataSchema(), Description: "Provides information about existing library variable sets.", - Blocks: map[string]datasourceSchema.Block{ - "library_variable_sets": datasourceSchema.ListNestedBlock{ - Description: "A list of library variable sets that match the filter(s).", - NestedObject: datasourceSchema.NestedBlockObject{ + Attributes: map[string]datasourceSchema.Attribute{ + "content_type": datasourceSchema.StringAttribute{ + Description: "A filter to search by content type.", + Optional: true, + }, + "id": GetIdDatasourceSchema(true), + "space_id": GetSpaceIdDatasourceSchema("library variable set", false), + "ids": util.GetQueryIDsDatasourceSchema(), + "partial_name": util.GetQueryPartialNameDatasourceSchema(), + "skip": util.GetQuerySkipDatasourceSchema(), + "take": util.GetQueryTakeDatasourceSchema(), + "library_variable_sets": datasourceSchema.ListNestedAttribute{ + Computed: true, + Optional: false, + NestedObject: datasourceSchema.NestedAttributeObject{ Attributes: GetLibraryVariableSetObjectDatasourceSchema(), }, }, @@ -38,21 +48,6 @@ func GetLibraryVariableSetDataSourceSchema() datasourceSchema.Schema { } } -func getLibraryVariableSetDataSchema() map[string]datasourceSchema.Attribute { - return map[string]datasourceSchema.Attribute{ - "content_type": datasourceSchema.StringAttribute{ - Description: "A filter to search by content type.", - Optional: true, - }, - "id": GetIdDatasourceSchema(true), - "space_id": GetSpaceIdDatasourceSchema("library variable set", false), - "ids": util.GetQueryIDsDatasourceSchema(), - "partial_name": util.GetQueryPartialNameDatasourceSchema(), - "skip": util.GetQuerySkipDatasourceSchema(), - "take": util.GetQueryTakeDatasourceSchema(), - } -} - func GetLibraryVariableSetObjectDatasourceSchema() map[string]datasourceSchema.Attribute { return map[string]datasourceSchema.Attribute{ "description": GetReadonlyDescriptionDatasourceSchema("library variable set"), diff --git a/octopusdeploy_framework/schemas/lifecycle.go b/octopusdeploy_framework/schemas/lifecycle.go index c2c433e83..ff6941d3b 100644 --- a/octopusdeploy_framework/schemas/lifecycle.go +++ b/octopusdeploy_framework/schemas/lifecycle.go @@ -114,6 +114,7 @@ func getResourceRetentionPolicyBlockSchema() resourceSchema.ListNestedBlock { func getLifecyclesAttribute() datasourceSchema.ListNestedAttribute { return datasourceSchema.ListNestedAttribute{ Computed: true, + Optional: false, NestedObject: datasourceSchema.NestedAttributeObject{ Attributes: map[string]datasourceSchema.Attribute{ "id": util.DataSourceString().Computed().Description("The ID of the lifecycle.").Build(), diff --git a/octopusdeploy_framework/schemas/tag_set.go b/octopusdeploy_framework/schemas/tag_set.go index a75ef2a5d..017ebf9af 100644 --- a/octopusdeploy_framework/schemas/tag_set.go +++ b/octopusdeploy_framework/schemas/tag_set.go @@ -74,10 +74,34 @@ func GetTagSetDataSourceSchema() datasourceSchema.Schema { Optional(). Description("A filter to specify the number of items to take (or return) in the response."). Build(), - "tag_sets": datasourceSchema.ListAttribute{ + "tag_sets": datasourceSchema.ListNestedAttribute{ Computed: true, - ElementType: types.ObjectType{AttrTypes: GetTagSetAttrTypes()}, + Optional: false, Description: "A list of tag sets that match the filter(s).", + NestedObject: datasourceSchema.NestedAttributeObject{ + Attributes: map[string]datasourceSchema.Attribute{ + "id": util.DataSourceString(). + Computed(). + Description("The unique ID for this resource."). + Build(), + "name": util.DataSourceString(). + Computed(). + Description("The name of this resource."). + Build(), + "description": util.DataSourceString(). + Computed(). + Description("The description of this tag set."). + Build(), + "sort_order": util.DataSourceInt64(). + Computed(). + Description("The sort order associated with this resource."). + Build(), + "space_id": util.DataSourceString(). + Computed(). + Description("The space ID associated with this resource."). + Build(), + }, + }, }, }, } diff --git a/octopusdeploy_framework/schemas/variable.go b/octopusdeploy_framework/schemas/variable.go index 5d9836e99..36d38366f 100644 --- a/octopusdeploy_framework/schemas/variable.go +++ b/octopusdeploy_framework/schemas/variable.go @@ -135,9 +135,7 @@ func GetVariableDatasourceSchema() datasourceSchema.Schema { Computed: true, }, VariableSchemaAttributeNames.Prompt: getVariablePromptDatasourceSchema(), - }, - Blocks: map[string]datasourceSchema.Block{ - VariableSchemaAttributeNames.Scope: getVariableScopeDatasourceSchema(), + VariableSchemaAttributeNames.Scope: getVariableScopeDatasourceSchema(), }, } } diff --git a/octopusdeploy_framework/schemas/variable_scope.go b/octopusdeploy_framework/schemas/variable_scope.go index 40a23550c..6f0d02aea 100644 --- a/octopusdeploy_framework/schemas/variable_scope.go +++ b/octopusdeploy_framework/schemas/variable_scope.go @@ -128,10 +128,11 @@ func getVariableScopeFieldResourceSchema(scopeDescription string) resourceSchema } } -func getVariableScopeDatasourceSchema() datasourceSchema.ListNestedBlock { - return datasourceSchema.ListNestedBlock{ +func getVariableScopeDatasourceSchema() datasourceSchema.ListNestedAttribute { + return datasourceSchema.ListNestedAttribute{ Description: "As variable names can appear more than once under different scopes, a VariableScope must also be provided", - NestedObject: datasourceSchema.NestedBlockObject{ + Required: true, + NestedObject: datasourceSchema.NestedAttributeObject{ Attributes: map[string]datasourceSchema.Attribute{ variableScopeFieldNames.Actions: getVariableScopeFieldDatasourceSchema(variableScopeFieldNames.Actions), variableScopeFieldNames.Channels: getVariableScopeFieldDatasourceSchema(variableScopeFieldNames.Channels), @@ -143,7 +144,6 @@ func getVariableScopeDatasourceSchema() datasourceSchema.ListNestedBlock { }, }, Validators: []validator.List{ - listvalidator.IsRequired(), listvalidator.SizeAtMost(1), }, }