diff --git a/docs/data-sources/space.md b/docs/data-sources/space.md index 2ec59a7f5..8857324cf 100644 --- a/docs/data-sources/space.md +++ b/docs/data-sources/space.md @@ -15,16 +15,13 @@ Provides information about an existing space. ## Schema -### Required - -- `name` (String) The name of this resource, no more than 20 characters long - ### Read-Only - `description` (String) The description of this space. - `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/variables.md b/docs/data-sources/variables.md index d51c6d5c0..5dac93d0c 100644 --- a/docs/data-sources/variables.md +++ b/docs/data-sources/variables.md @@ -28,7 +28,7 @@ data "octopusdeploy_variables" "example" { ### Optional -- `space_id` (String) A Space ID to filter by. Will revert what is specified on the provider if not set. +- `space_id` (String) The space ID associated with this variable. ### Read-Only diff --git a/docs/resources/environment.md b/docs/resources/environment.md index 22b847d57..ec90437fe 100644 --- a/docs/resources/environment.md +++ b/docs/resources/environment.md @@ -48,14 +48,11 @@ resource "octopusdeploy_environment" "example" { - `jira_extension_settings` (Block List) Provides extension settings for the Jira integration for this environment. (see [below for nested schema](#nestedblock--jira_extension_settings)) - `jira_service_management_extension_settings` (Block List) Provides extension settings for the Jira Service Management (JSM) integration for this environment. (see [below for nested schema](#nestedblock--jira_service_management_extension_settings)) - `servicenow_extension_settings` (Block List) Provides extension settings for the ServiceNow integration for this environment. (see [below for nested schema](#nestedblock--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 - -- `slug` (String) The unique slug of this environment - ### Nested Schema for `jira_extension_settings` diff --git a/octopusdeploy_framework/data_source_library_variable_sets.go b/octopusdeploy_framework/data_source_library_variable_sets.go index 5f8137d29..a0eaabd05 100644 --- a/octopusdeploy_framework/data_source_library_variable_sets.go +++ b/octopusdeploy_framework/data_source_library_variable_sets.go @@ -42,7 +42,7 @@ func (l *libraryVariableSetDataSource) Metadata(ctx context.Context, req datasou func (l *libraryVariableSetDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { tflog.Debug(ctx, "library variable set Schema") - resp.Schema = schemas.GetLibraryVariableSetDataSourceSchema() + resp.Schema = schemas.LibraryVariableSetSchema{}.GetDatasourceSchema() } func (l *libraryVariableSetDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { diff --git a/octopusdeploy_framework/data_source_script_modules.go b/octopusdeploy_framework/data_source_script_modules.go index c56ab3cee..28aa260a4 100644 --- a/octopusdeploy_framework/data_source_script_modules.go +++ b/octopusdeploy_framework/data_source_script_modules.go @@ -30,7 +30,7 @@ func (l *scriptModulesDataSource) Metadata(ctx context.Context, req datasource.M func (l *scriptModulesDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { tflog.Debug(ctx, "script modules datasource Schema") - resp.Schema = schemas.GetDatasourceScriptModuleSchema() + resp.Schema = schemas.ScriptModuleSchema{}.GetDatasourceSchema() } func (l *scriptModulesDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { diff --git a/octopusdeploy_framework/datasource_environments.go b/octopusdeploy_framework/datasource_environments.go index df7b0993c..35951cd98 100644 --- a/octopusdeploy_framework/datasource_environments.go +++ b/octopusdeploy_framework/datasource_environments.go @@ -10,7 +10,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -39,28 +38,7 @@ func (*environmentDataSource) Metadata(_ context.Context, req datasource.Metadat } func (*environmentDataSource) Schema(_ context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{ - Description: "Provides information about existing environments.", - Attributes: map[string]schema.Attribute{ - //request - "ids": util.GetQueryIDsDatasourceSchema(), - "space_id": schemas.GetSpaceIdDatasourceSchema(schemas.EnvironmentResourceDescription, false), - "name": util.GetQueryNameDatasourceSchema(), - "partial_name": util.GetQueryPartialNameDatasourceSchema(), - "skip": util.GetQuerySkipDatasourceSchema(), - "take": util.GetQueryTakeDatasourceSchema(), - - //response - "id": schemas.GetIdDatasourceSchema(true), - "environments": schema.ListNestedAttribute{ - Computed: true, - Optional: false, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemas.GetEnvironmentDatasourceSchema(), - }, - }, - }, - } + resp.Schema = schemas.EnvironmentSchema{}.GetDatasourceSchema() } func (e *environmentDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { diff --git a/octopusdeploy_framework/datasource_feeds.go b/octopusdeploy_framework/datasource_feeds.go index ac178edac..356e8c509 100644 --- a/octopusdeploy_framework/datasource_feeds.go +++ b/octopusdeploy_framework/datasource_feeds.go @@ -5,7 +5,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/datasource" - datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "time" @@ -29,10 +28,7 @@ func (e *feedsDataSource) Configure(_ context.Context, req datasource.ConfigureR } func (*feedsDataSource) Schema(_ context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = datasourceSchema.Schema{ - Description: "Provides information about existing feeds.", - Attributes: schemas.GetFeedsDataSourceSchema(), - } + resp.Schema = schemas.FeedsSchema{}.GetDatasourceSchema() } func (e *feedsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { diff --git a/octopusdeploy_framework/datasource_git_credentials.go b/octopusdeploy_framework/datasource_git_credentials.go index 961ef3e40..96ba1673c 100644 --- a/octopusdeploy_framework/datasource_git_credentials.go +++ b/octopusdeploy_framework/datasource_git_credentials.go @@ -45,7 +45,7 @@ func (g *gitCredentialsDataSource) Metadata(_ context.Context, req datasource.Me } func (g *gitCredentialsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schemas.GetGitCredentialDataSourceSchema() + resp.Schema = schemas.GitCredentialSchema{}.GetDatasourceSchema() } func (g *gitCredentialsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { diff --git a/octopusdeploy_framework/datasource_lifecycle.go b/octopusdeploy_framework/datasource_lifecycle.go index 3acd52a0e..5da184b85 100644 --- a/octopusdeploy_framework/datasource_lifecycle.go +++ b/octopusdeploy_framework/datasource_lifecycle.go @@ -3,10 +3,10 @@ package octopusdeploy_framework import ( "context" "fmt" + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" "time" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/lifecycles" - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -28,6 +28,8 @@ type lifecyclesDataSourceModel struct { Lifecycles types.List `tfsdk:"lifecycles"` } +var _ datasource.DataSource = &lifecyclesDataSource{} + func NewLifecyclesDataSource() datasource.DataSource { return &lifecyclesDataSource{} } @@ -39,7 +41,7 @@ func (l *lifecyclesDataSource) Metadata(ctx context.Context, req datasource.Meta func (l *lifecyclesDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { tflog.Debug(ctx, "lifecycles datasource Schema") - resp.Schema = schemas.GetDatasourceLifecycleSchema() + resp.Schema = schemas.LifecycleSchema{}.GetDatasourceSchema() } func (l *lifecyclesDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { diff --git a/octopusdeploy_framework/datasource_project.go b/octopusdeploy_framework/datasource_project.go index 8d68227a7..e413fa960 100644 --- a/octopusdeploy_framework/datasource_project.go +++ b/octopusdeploy_framework/datasource_project.go @@ -39,7 +39,7 @@ func (p *projectsDataSource) Metadata(_ context.Context, req datasource.Metadata } func (p *projectsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schemas.GetProjectDataSourceSchema() + resp.Schema = schemas.ProjectSchema{}.GetDatasourceSchema() } func (p *projectsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { diff --git a/octopusdeploy_framework/datasource_project_groups.go b/octopusdeploy_framework/datasource_project_groups.go index 1e25a0912..6a51b7325 100644 --- a/octopusdeploy_framework/datasource_project_groups.go +++ b/octopusdeploy_framework/datasource_project_groups.go @@ -7,7 +7,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" "time" @@ -45,27 +44,7 @@ func (p *projectGroupsDataSource) Metadata(_ context.Context, _ datasource.Metad } func (p *projectGroupsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { - description := "project group" - resp.Schema = schema.Schema{ - Attributes: map[string]schema.Attribute{ - // request - "space_id": schemas.GetSpaceIdDatasourceSchema(description, false), - "ids": util.GetQueryIDsDatasourceSchema(), - "partial_name": util.GetQueryPartialNameDatasourceSchema(), - "skip": util.GetQuerySkipDatasourceSchema(), - "take": util.GetQueryTakeDatasourceSchema(), - - // response - "id": schemas.GetIdDatasourceSchema(true), - "project_groups": schema.ListNestedAttribute{ - Computed: true, - Description: "A list of project groups that match the filter(s).", - NestedObject: schema.NestedAttributeObject{ - Attributes: schemas.GetProjectGroupDatasourceSchema(), - }, - }, - }, - } + resp.Schema = schemas.ProjectGroupSchema{}.GetDatasourceSchema() } func (p *projectGroupsDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { diff --git a/octopusdeploy_framework/datasource_space.go b/octopusdeploy_framework/datasource_space.go index 1a261ed3e..defcc7af8 100644 --- a/octopusdeploy_framework/datasource_space.go +++ b/octopusdeploy_framework/datasource_space.go @@ -10,7 +10,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -27,10 +26,7 @@ func (*spaceDataSource) Metadata(_ context.Context, _ datasource.MetadataRequest } func (*spaceDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{ - Description: "Provides information about an existing space.", - Attributes: schemas.GetSpaceDatasourceSchema(), - } + resp.Schema = schemas.SpaceSchema{}.GetDatasourceSchema() } func (b *spaceDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { diff --git a/octopusdeploy_framework/datasource_spaces.go b/octopusdeploy_framework/datasource_spaces.go index 9bc1ee3b5..dcb66e07f 100644 --- a/octopusdeploy_framework/datasource_spaces.go +++ b/octopusdeploy_framework/datasource_spaces.go @@ -6,7 +6,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "time" ) @@ -33,25 +32,7 @@ func (*spacesDataSource) Metadata(_ context.Context, _ datasource.MetadataReques } func (*spacesDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: map[string]schema.Attribute{ - // request - "ids": schemas.GetQueryIDsDatasourceSchema(), - "partial_name": schemas.GetQueryPartialNameDatasourceSchema(), - "skip": schemas.GetQuerySkipDatasourceSchema(), - "take": schemas.GetQueryTakeDatasourceSchema(), - - // response - "id": schemas.GetIdDatasourceSchema(true), - "spaces": schema.ListNestedAttribute{ - Computed: true, - Optional: false, - NestedObject: schema.NestedAttributeObject{ - Attributes: schemas.GetSpacesDatasourceSchema(), - }, - }, - }, - } + resp.Schema = schemas.SpacesSchema{}.GetDatasourceSchema() } func (b *spacesDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { @@ -67,7 +48,7 @@ func (b *spacesDataSource) Read(ctx context.Context, req datasource.ReadRequest, } query := spaces.SpacesQuery{ - IDs: schemas.GetIds(data.IDs), + IDs: util.GetIds(data.IDs), PartialName: data.PartialName.ValueString(), Skip: schemas.GetNumber(data.Skip), Take: schemas.GetNumber(data.Take), diff --git a/octopusdeploy_framework/datasource_tag_sets.go b/octopusdeploy_framework/datasource_tag_sets.go index 53cfc3ebd..cad823bd6 100644 --- a/octopusdeploy_framework/datasource_tag_sets.go +++ b/octopusdeploy_framework/datasource_tag_sets.go @@ -27,7 +27,7 @@ func (t *tagSetsDataSource) Metadata(_ context.Context, req datasource.MetadataR } func (t *tagSetsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schemas.GetTagSetDataSourceSchema() + resp.Schema = schemas.TagSetSchema{}.GetDatasourceSchema() } func (t *tagSetsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { @@ -42,7 +42,7 @@ func (t *tagSetsDataSource) Read(ctx context.Context, req datasource.ReadRequest } query := tagsets.TagSetsQuery{ - IDs: schemas.GetIds(data.IDs), + IDs: util.GetIds(data.IDs), PartialName: data.PartialName.ValueString(), Skip: int(data.Skip.ValueInt64()), Take: int(data.Take.ValueInt64()), diff --git a/octopusdeploy_framework/datasource_tenant_projects.go b/octopusdeploy_framework/datasource_tenant_projects.go index b88ac1e85..4495b5f76 100644 --- a/octopusdeploy_framework/datasource_tenant_projects.go +++ b/octopusdeploy_framework/datasource_tenant_projects.go @@ -30,7 +30,7 @@ func (t *tenantProjectsDataSource) Configure(_ context.Context, req datasource.C } func (*tenantProjectsDataSource) Schema(_ context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schemas.GetTenantProjectsDataSourceSchema() + resp.Schema = schemas.TenantProjectVariableSchema{}.GetDatasourceSchema() } func (t *tenantProjectsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { diff --git a/octopusdeploy_framework/datasource_tenants.go b/octopusdeploy_framework/datasource_tenants.go index e9559ff49..d7bcf71da 100644 --- a/octopusdeploy_framework/datasource_tenants.go +++ b/octopusdeploy_framework/datasource_tenants.go @@ -6,7 +6,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/datasource" - datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "time" ) @@ -28,10 +27,7 @@ func (e *tenantsDataSource) Configure(_ context.Context, req datasource.Configur } func (*tenantsDataSource) Schema(_ context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = datasourceSchema.Schema{ - Description: "Provides information about existing tenants.", - Attributes: schemas.GetTenantsDataSourceSchema(), - } + resp.Schema = schemas.TenantSchema{}.GetDatasourceSchema() } func (b *tenantsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { diff --git a/octopusdeploy_framework/datasource_variables.go b/octopusdeploy_framework/datasource_variables.go index a87cc421a..4d652aa7f 100644 --- a/octopusdeploy_framework/datasource_variables.go +++ b/octopusdeploy_framework/datasource_variables.go @@ -25,7 +25,7 @@ func (*variablesDataSource) Metadata(_ context.Context, req datasource.MetadataR } func (*variablesDataSource) Schema(_ context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schemas.GetVariableDatasourceSchema() + resp.Schema = schemas.VariableSchema{}.GetDatasourceSchema() } func (e *variablesDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_artifactory_generic_feed.go b/octopusdeploy_framework/resource_artifactory_generic_feed.go index 857043fd9..28fd95963 100644 --- a/octopusdeploy_framework/resource_artifactory_generic_feed.go +++ b/octopusdeploy_framework/resource_artifactory_generic_feed.go @@ -11,7 +11,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds" @@ -33,10 +32,7 @@ func (r *artifactoryGenericFeedTypeResource) Metadata(ctx context.Context, req r } func (r *artifactoryGenericFeedTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: schemas.GetArtifactoryGenericFeedResourceSchema(), - Description: "This resource manages a Artifactory Generic feed in Octopus Deploy.", - } + resp.Schema = schemas.ArtifactoryGenericFeedSchema{}.GetResourceSchema() } func (r *artifactoryGenericFeedTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_aws_elastic_container_registry.go b/octopusdeploy_framework/resource_aws_elastic_container_registry.go index b54adf9d7..dae213ec9 100644 --- a/octopusdeploy_framework/resource_aws_elastic_container_registry.go +++ b/octopusdeploy_framework/resource_aws_elastic_container_registry.go @@ -12,7 +12,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -32,10 +31,7 @@ func (r *awsElasticContainerRegistryFeedTypeResource) Metadata(ctx context.Conte } func (r *awsElasticContainerRegistryFeedTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: schemas.GetAwsElasticContainerRegistryFeedResourceSchema(), - Description: "This resource manages an AWS Elastic Container Registry in Octopus Deploy.", - } + resp.Schema = schemas.AwsElasticContainerRegistrySchema{}.GetResourceSchema() } func (r *awsElasticContainerRegistryFeedTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_docker_container_registry.go b/octopusdeploy_framework/resource_docker_container_registry.go index 97131399b..c43208478 100644 --- a/octopusdeploy_framework/resource_docker_container_registry.go +++ b/octopusdeploy_framework/resource_docker_container_registry.go @@ -12,7 +12,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -32,10 +31,7 @@ func (r *dockerContainerRegistryFeedTypeResource) Metadata(ctx context.Context, } func (r *dockerContainerRegistryFeedTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: schemas.GetDockerContainerRegistryFeedResourceSchema(), - Description: "This resource manages a Docker Container Registry in Octopus Deploy.", - } + resp.Schema = schemas.DockerContainerRegistryFeedSchema{}.GetResourceSchema() } func (r *dockerContainerRegistryFeedTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_environment.go b/octopusdeploy_framework/resource_environment.go index 9c076a7b9..779841fec 100644 --- a/octopusdeploy_framework/resource_environment.go +++ b/octopusdeploy_framework/resource_environment.go @@ -28,7 +28,7 @@ func (r *environmentTypeResource) Metadata(ctx context.Context, req resource.Met } func (r *environmentTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schemas.GetEnvironmentResourceSchema() + resp.Schema = schemas.EnvironmentSchema{}.GetResourceSchema() } func (r *environmentTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_git_credential.go b/octopusdeploy_framework/resource_git_credential.go index 8a5baeec1..197776069 100644 --- a/octopusdeploy_framework/resource_git_credential.go +++ b/octopusdeploy_framework/resource_git_credential.go @@ -39,7 +39,7 @@ func (g *gitCredentialResource) Metadata(_ context.Context, req resource.Metadat } func (g *gitCredentialResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schemas.GetGitCredentialResourceSchema() + resp.Schema = schemas.GitCredentialSchema{}.GetResourceSchema() } func (g *gitCredentialResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_github_repository_feed.go b/octopusdeploy_framework/resource_github_repository_feed.go index ae4f95977..8d1743092 100644 --- a/octopusdeploy_framework/resource_github_repository_feed.go +++ b/octopusdeploy_framework/resource_github_repository_feed.go @@ -12,7 +12,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -32,10 +31,7 @@ func (r *githubRepositoryFeedTypeResource) Metadata(ctx context.Context, req res } func (r *githubRepositoryFeedTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: schemas.GetGitHubRepositoryFeedResourceSchema(), - Description: "This resource manages a GitHub repository feed in Octopus Deploy.", - } + resp.Schema = schemas.GitHubRepositoryFeedSchema{}.GetResourceSchema() } func (r *githubRepositoryFeedTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_helm_feed.go b/octopusdeploy_framework/resource_helm_feed.go index c8204a63e..9276d9273 100644 --- a/octopusdeploy_framework/resource_helm_feed.go +++ b/octopusdeploy_framework/resource_helm_feed.go @@ -11,7 +11,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds" @@ -33,10 +32,7 @@ func (r *helmFeedTypeResource) Metadata(ctx context.Context, req resource.Metada } func (r *helmFeedTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: schemas.GetHelmFeedResourceSchema(), - Description: "This resource manages a Helm Feed in Octopus Deploy.", - } + resp.Schema = schemas.HelmFeedSchema{}.GetResourceSchema() } func (r *helmFeedTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_library_variable_set.go b/octopusdeploy_framework/resource_library_variable_set.go index 795482862..d32f052fb 100644 --- a/octopusdeploy_framework/resource_library_variable_set.go +++ b/octopusdeploy_framework/resource_library_variable_set.go @@ -29,7 +29,7 @@ func (r *libraryVariableSetFeedTypeResource) Metadata(ctx context.Context, req r } func (r *libraryVariableSetFeedTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schemas.GetLibraryVariableSetResourceSchema() + resp.Schema = schemas.LibraryVariableSetSchema{}.GetResourceSchema() } func (r *libraryVariableSetFeedTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_lifecycle.go b/octopusdeploy_framework/resource_lifecycle.go index a4c863f8c..839a611ff 100644 --- a/octopusdeploy_framework/resource_lifecycle.go +++ b/octopusdeploy_framework/resource_lifecycle.go @@ -51,7 +51,7 @@ func (r *lifecycleTypeResource) Metadata(_ context.Context, req resource.Metadat } func (r *lifecycleTypeResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schemas.GetResourceLifecycleSchema() + resp.Schema = schemas.LifecycleSchema{}.GetResourceSchema() } func (r *lifecycleTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_maven_feed.go b/octopusdeploy_framework/resource_maven_feed.go index e260debcd..7920d77a3 100644 --- a/octopusdeploy_framework/resource_maven_feed.go +++ b/octopusdeploy_framework/resource_maven_feed.go @@ -12,7 +12,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -32,10 +31,7 @@ func (r *mavenFeedTypeResource) Metadata(ctx context.Context, req resource.Metad } func (r *mavenFeedTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: schemas.GetMavenFeedResourceSchema(), - Description: "This resource manages a Maven feed in Octopus Deploy.", - } + resp.Schema = schemas.MavenFeedSchema{}.GetResourceSchema() } func (r *mavenFeedTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_nuget_feed.go b/octopusdeploy_framework/resource_nuget_feed.go index 6a737e8b5..71229b558 100644 --- a/octopusdeploy_framework/resource_nuget_feed.go +++ b/octopusdeploy_framework/resource_nuget_feed.go @@ -12,7 +12,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -32,10 +31,7 @@ func (r *nugetFeedTypeResource) Metadata(ctx context.Context, req resource.Metad } func (r *nugetFeedTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: schemas.GetNugetFeedResourceSchema(), - Description: "This resource manages a Nuget feed in Octopus Deploy.", - } + resp.Schema = schemas.NugetFeedSchema{}.GetResourceSchema() } func (r *nugetFeedTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_project.go b/octopusdeploy_framework/resource_project.go index 7a8ece169..692ec1794 100644 --- a/octopusdeploy_framework/resource_project.go +++ b/octopusdeploy_framework/resource_project.go @@ -28,7 +28,7 @@ func (r *projectResource) Metadata(_ context.Context, req resource.MetadataReque } func (r *projectResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schemas.GetProjectResourceSchema() + resp.Schema = schemas.ProjectSchema{}.GetResourceSchema() } func (r *projectResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_project_group.go b/octopusdeploy_framework/resource_project_group.go index 2411a8d0f..d3f87ddd8 100644 --- a/octopusdeploy_framework/resource_project_group.go +++ b/octopusdeploy_framework/resource_project_group.go @@ -9,7 +9,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -27,9 +26,7 @@ func (r *projectGroupTypeResource) Metadata(ctx context.Context, req resource.Me } func (r *projectGroupTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: schemas.GetProjectGroupResourceSchema(), - } + resp.Schema = schemas.ProjectGroupSchema{}.GetResourceSchema() } func (r *projectGroupTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_runbook.go b/octopusdeploy_framework/resource_runbook.go index 066f32b13..c4829f365 100644 --- a/octopusdeploy_framework/resource_runbook.go +++ b/octopusdeploy_framework/resource_runbook.go @@ -28,7 +28,7 @@ func (*runbookTypeResource) Metadata(ctx context.Context, req resource.MetadataR } func (*runbookTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schemas.GetRunbookResourceSchema() + resp.Schema = schemas.RunbookSchema{}.GetResourceSchema() } func (r *runbookTypeResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_script_module.go b/octopusdeploy_framework/resource_script_module.go index bb2f5fcee..b98d7b9c0 100644 --- a/octopusdeploy_framework/resource_script_module.go +++ b/octopusdeploy_framework/resource_script_module.go @@ -10,7 +10,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -29,10 +28,7 @@ func (r *scriptModuleTypeResource) Metadata(ctx context.Context, req resource.Me } func (r *scriptModuleTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: schemas.GetScriptModuleResourceSchema(), - Blocks: schemas.GetScriptModuleSchemaBlock(), - } + resp.Schema = schemas.ScriptModuleSchema{}.GetResourceSchema() } func (r *scriptModuleTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_space.go b/octopusdeploy_framework/resource_space.go index 92c60f7e6..d90101a9e 100644 --- a/octopusdeploy_framework/resource_space.go +++ b/octopusdeploy_framework/resource_space.go @@ -12,7 +12,6 @@ import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -31,10 +30,7 @@ func NewSpaceResource() resource.Resource { } func (s *spaceResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - Description: "This resource manages spaces in Octopus Deploy.", - Attributes: schemas.GetSpaceResourceSchema(), - } + resp.Schema = schemas.SpaceSchema{}.GetResourceSchema() } func (s *spaceResource) Metadata(_ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse) { diff --git a/octopusdeploy_framework/resource_tag.go b/octopusdeploy_framework/resource_tag.go index f8b46dad2..3941b433f 100644 --- a/octopusdeploy_framework/resource_tag.go +++ b/octopusdeploy_framework/resource_tag.go @@ -33,7 +33,7 @@ func (r *tagTypeResource) Metadata(ctx context.Context, req resource.MetadataReq } func (r *tagTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schemas.GetTagResourceSchema() + resp.Schema = schemas.TagSchema{}.GetResourceSchema() } func (r *tagTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_tag_set.go b/octopusdeploy_framework/resource_tag_set.go index b14ae7eaa..df5f7d9e2 100644 --- a/octopusdeploy_framework/resource_tag_set.go +++ b/octopusdeploy_framework/resource_tag_set.go @@ -27,7 +27,7 @@ func (r *tagSetResource) Metadata(_ context.Context, req resource.MetadataReques } func (r *tagSetResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schemas.GetTagSetResourceSchema() + resp.Schema = schemas.TagSetSchema{}.GetResourceSchema() } func (r *tagSetResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_tenant.go b/octopusdeploy_framework/resource_tenant.go index cc0b04b67..9e038757a 100644 --- a/octopusdeploy_framework/resource_tenant.go +++ b/octopusdeploy_framework/resource_tenant.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" "sort" @@ -32,10 +31,7 @@ func (r *tenantTypeResource) Metadata(ctx context.Context, req resource.Metadata } func (r *tenantTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: schemas.GetTenantResourceSchema(), - Description: "This resource manages tenants in Octopus Deploy.", - } + resp.Schema = schemas.TenantSchema{}.GetResourceSchema() } func (r *tenantTypeResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_tenant_project.go b/octopusdeploy_framework/resource_tenant_project.go index 7f8d4102d..a5f68eac7 100644 --- a/octopusdeploy_framework/resource_tenant_project.go +++ b/octopusdeploy_framework/resource_tenant_project.go @@ -34,7 +34,7 @@ func (t *tenantProjectResource) Metadata(ctx context.Context, req resource.Metad } func (t *tenantProjectResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schemas.GetTenantProjectsResourceSchema() + resp.Schema = schemas.TenantProjectsSchema{}.GetResourceSchema() } func (t *tenantProjectResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_tenant_project_variable.go b/octopusdeploy_framework/resource_tenant_project_variable.go index 7718f658e..65d5e8261 100644 --- a/octopusdeploy_framework/resource_tenant_project_variable.go +++ b/octopusdeploy_framework/resource_tenant_project_variable.go @@ -43,7 +43,7 @@ func (t *tenantProjectVariableResource) Metadata(_ context.Context, req resource } func (t *tenantProjectVariableResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schemas.GetTenantProjectVariableResourceSchema() + resp.Schema = schemas.TenantProjectVariableSchema{}.GetResourceSchema() } func (t *tenantProjectVariableResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_username_password_account.go b/octopusdeploy_framework/resource_username_password_account.go index 307ffe3fd..0a70b2127 100644 --- a/octopusdeploy_framework/resource_username_password_account.go +++ b/octopusdeploy_framework/resource_username_password_account.go @@ -30,7 +30,7 @@ func (r *usernamePasswordAccountResource) Metadata(_ context.Context, req resour } func (r *usernamePasswordAccountResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schemas.GetUsernamePasswordAccountResourceSchema() + resp.Schema = schemas.UsernamePasswordAccountSchema{}.GetResourceSchema() } func (r *usernamePasswordAccountResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/resource_variable.go b/octopusdeploy_framework/resource_variable.go index af4e5b775..e8ecd9448 100644 --- a/octopusdeploy_framework/resource_variable.go +++ b/octopusdeploy_framework/resource_variable.go @@ -48,7 +48,7 @@ func (r *variableTypeResource) Metadata(ctx context.Context, req resource.Metada } func (r *variableTypeResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schemas.GetVariableResourceSchema() + resp.Schema = schemas.VariableSchema{}.GetResourceSchema() } func (r *variableTypeResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/octopusdeploy_framework/schemas/action_template_parameter.go b/octopusdeploy_framework/schemas/action_template_parameter.go index bee1f1262..bf116b767 100644 --- a/octopusdeploy_framework/schemas/action_template_parameter.go +++ b/octopusdeploy_framework/schemas/action_template_parameter.go @@ -3,9 +3,9 @@ package schemas import ( "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/actiontemplates" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core" - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "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/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" @@ -14,6 +14,10 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" ) +type ActionTemplateParameterSchema struct{} + +var _ EntitySchema = ActionTemplateParameterSchema{} + func expandActionTemplateParameter(tfTemplate map[string]attr.Value) actiontemplates.ActionTemplateParameter { actionTemplateParameter := actiontemplates.NewActionTemplateParameter() @@ -68,44 +72,77 @@ func TemplateObjectType() map[string]attr.Type { } } -func GetActionTemplateParameterSchema() map[string]resourceSchema.Attribute { - return map[string]resourceSchema.Attribute{ - "default_value": resourceSchema.StringAttribute{ - Description: "A default value for the parameter, if applicable. This can be a hard-coded value or a variable reference.", - Optional: true, - Computed: true, - Default: stringdefault.StaticString(""), - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), +func (a ActionTemplateParameterSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{} +} + +func (a ActionTemplateParameterSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Attributes: map[string]resourceSchema.Attribute{ + "description": GetDescriptionResourceSchema("library variable set"), + "id": GetIdResourceSchema(), + "name": GetNameResourceSchema(true), + "space_id": GetSpaceIdResourceSchema("library variable set"), + "template_ids": resourceSchema.MapAttribute{ + ElementType: types.StringType, + Computed: true, }, - }, - "display_settings": resourceSchema.MapAttribute{ - Description: "The display settings for the parameter.", - Optional: true, - ElementType: types.StringType, - }, - "help_text": resourceSchema.StringAttribute{ - Description: "The help presented alongside the parameter input.", - Optional: true, - Computed: true, - Default: stringdefault.StaticString(""), - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), + "variable_set_id": resourceSchema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, }, }, - "id": util.GetIdResourceSchema(), - "label": resourceSchema.StringAttribute{ - Description: "The label shown beside the parameter when presented in the deployment process. Example: `Server name`.", - Optional: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, + Description: "This resource manages library variable sets in Octopus Deploy.", + Blocks: map[string]resourceSchema.Block{ + "template": GetActionTemplateParameterSchema(), }, - "name": resourceSchema.StringAttribute{ - Description: "The name of the variable set by the parameter. The name can contain letters, digits, dashes and periods. Example: `ServerName`", - Required: true, - Validators: []validator.String{ - stringvalidator.LengthAtLeast(1), + } +} + +func GetActionTemplateParameterSchema() resourceSchema.ListNestedBlock { + return resourceSchema.ListNestedBlock{ + NestedObject: resourceSchema.NestedBlockObject{ + Attributes: map[string]resourceSchema.Attribute{ + "default_value": resourceSchema.StringAttribute{ + Description: "A default value for the parameter, if applicable. This can be a hard-coded value or a variable reference.", + Optional: true, + Computed: true, + Default: stringdefault.StaticString(""), + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "display_settings": resourceSchema.MapAttribute{ + Description: "The display settings for the parameter.", + Optional: true, + ElementType: types.StringType, + }, + "help_text": resourceSchema.StringAttribute{ + Description: "The help presented alongside the parameter input.", + Optional: true, + Computed: true, + Default: stringdefault.StaticString(""), + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "id": GetIdResourceSchema(), + "label": resourceSchema.StringAttribute{ + Description: "The label shown beside the parameter when presented in the deployment process. Example: `Server name`.", + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "name": resourceSchema.StringAttribute{ + Description: "The name of the variable set by the parameter. The name can contain letters, digits, dashes and periods. Example: `ServerName`", + Required: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + }, }, }, } diff --git a/octopusdeploy_framework/schemas/artifactory_generic_feed.go b/octopusdeploy_framework/schemas/artifactory_generic_feed.go index 375c3c331..ff98caf57 100644 --- a/octopusdeploy_framework/schemas/artifactory_generic_feed.go +++ b/octopusdeploy_framework/schemas/artifactory_generic_feed.go @@ -1,36 +1,47 @@ package schemas import ( - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" ) const artifactoryGenericFeedDescription = "artifactory generic feed" -func GetArtifactoryGenericFeedResourceSchema() map[string]resourceSchema.Attribute { - return map[string]resourceSchema.Attribute{ - "feed_uri": resourceSchema.StringAttribute{ - Required: true, - }, - "id": util.GetIdResourceSchema(), - "name": util.GetNameResourceSchema(true), - "package_acquisition_location_options": util.GetPackageAcquisitionLocationOptionsResourceSchema(), - "password": util.GetPasswordResourceSchema(false), - "space_id": util.GetSpaceIdResourceSchema(artifactoryGenericFeedDescription), - "username": util.GetUsernameResourceSchema(false), - "repository": resourceSchema.StringAttribute{ - Computed: false, - Required: true, - }, - "layout_regex": resourceSchema.StringAttribute{ - Computed: false, - Required: false, - Optional: true, +type ArtifactoryGenericFeedSchema struct{} + +var _ EntitySchema = ArtifactoryGenericFeedSchema{} + +func (a ArtifactoryGenericFeedSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Description: "This resource manages a Artifactory Generic feed in Octopus Deploy.", + Attributes: map[string]resourceSchema.Attribute{ + "feed_uri": resourceSchema.StringAttribute{ + Required: true, + }, + "id": GetIdResourceSchema(), + "name": GetNameResourceSchema(true), + "package_acquisition_location_options": GetPackageAcquisitionLocationOptionsResourceSchema(), + "password": GetPasswordResourceSchema(false), + "space_id": GetSpaceIdResourceSchema(artifactoryGenericFeedDescription), + "username": GetUsernameResourceSchema(false), + "repository": resourceSchema.StringAttribute{ + Computed: false, + Required: true, + }, + "layout_regex": resourceSchema.StringAttribute{ + Computed: false, + Required: false, + Optional: true, + }, }, } } +func (a ArtifactoryGenericFeedSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{} +} + type ArtifactoryGenericFeedTypeResourceModel struct { FeedUri types.String `tfsdk:"feed_uri"` Name types.String `tfsdk:"name"` diff --git a/octopusdeploy_framework/schemas/aws_elastic_container_registry.go b/octopusdeploy_framework/schemas/aws_elastic_container_registry.go index fbc321f9e..82c070586 100644 --- a/octopusdeploy_framework/schemas/aws_elastic_container_registry.go +++ b/octopusdeploy_framework/schemas/aws_elastic_container_registry.go @@ -1,32 +1,43 @@ package schemas import ( - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" ) const awsElasticContainerRegistryFeedDescription = "aws elastic container registry" -func GetAwsElasticContainerRegistryFeedResourceSchema() map[string]resourceSchema.Attribute { - return map[string]resourceSchema.Attribute{ - "access_key": resourceSchema.StringAttribute{ - Required: true, - Description: "The AWS access key to use when authenticating against Amazon Web Services.", - }, - "id": util.GetIdResourceSchema(), - "name": util.GetNameResourceSchema(true), - "package_acquisition_location_options": util.GetPackageAcquisitionLocationOptionsResourceSchema(), - "region": resourceSchema.StringAttribute{ - Required: true, - Description: "The AWS region where the registry resides.", - }, - "secret_key": resourceSchema.StringAttribute{ - Required: true, - Sensitive: true, - Description: "The AWS secret key to use when authenticating against Amazon Web Services.", +type AwsElasticContainerRegistrySchema struct{} + +var _ EntitySchema = AwsElasticContainerRegistrySchema{} + +func (a AwsElasticContainerRegistrySchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{} +} + +func (a AwsElasticContainerRegistrySchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Description: "This resource manages an AWS Elastic Container Registry in Octopus Deploy.", + Attributes: map[string]resourceSchema.Attribute{ + "access_key": resourceSchema.StringAttribute{ + Required: true, + Description: "The AWS access key to use when authenticating against Amazon Web Services.", + }, + "id": GetIdResourceSchema(), + "name": GetNameResourceSchema(true), + "package_acquisition_location_options": GetPackageAcquisitionLocationOptionsResourceSchema(), + "region": resourceSchema.StringAttribute{ + Required: true, + Description: "The AWS region where the registry resides.", + }, + "secret_key": resourceSchema.StringAttribute{ + Required: true, + Sensitive: true, + Description: "The AWS secret key to use when authenticating against Amazon Web Services.", + }, + "space_id": GetSpaceIdResourceSchema(awsElasticContainerRegistryFeedDescription), }, - "space_id": util.GetSpaceIdResourceSchema(awsElasticContainerRegistryFeedDescription), } } diff --git a/octopusdeploy_framework/schemas/docker_container_registry_feed.go b/octopusdeploy_framework/schemas/docker_container_registry_feed.go index 346eee869..7597ab5ee 100644 --- a/octopusdeploy_framework/schemas/docker_container_registry_feed.go +++ b/octopusdeploy_framework/schemas/docker_container_registry_feed.go @@ -1,31 +1,42 @@ package schemas import ( - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" ) const dockerContainerRegistryFeedDescription = "docker container registry feed" -func GetDockerContainerRegistryFeedResourceSchema() map[string]resourceSchema.Attribute { - return map[string]resourceSchema.Attribute{ - "api_version": resourceSchema.StringAttribute{ - Optional: true, - }, - "feed_uri": util.GetFeedUriResourceSchema(), - "id": util.GetIdResourceSchema(), - "name": util.GetNameResourceSchema(true), - "package_acquisition_location_options": util.GetPackageAcquisitionLocationOptionsResourceSchema(), - "password": util.GetPasswordResourceSchema(false), - "space_id": util.GetSpaceIdResourceSchema(dockerContainerRegistryFeedDescription), - "username": util.GetUsernameResourceSchema(false), - "registry_path": resourceSchema.StringAttribute{ - Optional: true, +type DockerContainerRegistryFeedSchema struct{} + +var _ EntitySchema = DockerContainerRegistryFeedSchema{} + +func (d DockerContainerRegistryFeedSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Attributes: map[string]resourceSchema.Attribute{ + "api_version": resourceSchema.StringAttribute{ + Optional: true, + }, + "feed_uri": GetFeedUriResourceSchema(), + "id": GetIdResourceSchema(), + "name": GetNameResourceSchema(true), + "package_acquisition_location_options": GetPackageAcquisitionLocationOptionsResourceSchema(), + "password": GetPasswordResourceSchema(false), + "space_id": GetSpaceIdResourceSchema(dockerContainerRegistryFeedDescription), + "username": GetUsernameResourceSchema(false), + "registry_path": resourceSchema.StringAttribute{ + Optional: true, + }, }, + Description: "This resource manages a Docker Container Registry in Octopus Deploy.", } } +func (d DockerContainerRegistryFeedSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{} +} + type DockerContainerRegistryFeedTypeResourceModel struct { APIVersion types.String `tfsdk:"api_version"` FeedUri types.String `tfsdk:"feed_uri"` diff --git a/octopusdeploy_framework/schemas/entity_schema.go b/octopusdeploy_framework/schemas/entity_schema.go new file mode 100644 index 000000000..83d4075ca --- /dev/null +++ b/octopusdeploy_framework/schemas/entity_schema.go @@ -0,0 +1,11 @@ +package schemas + +import ( + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" +) + +type EntitySchema interface { + GetResourceSchema() resourceSchema.Schema + GetDatasourceSchema() datasourceSchema.Schema +} diff --git a/octopusdeploy_framework/schemas/environment.go b/octopusdeploy_framework/schemas/environment.go index 3090f7cc1..e28bb710f 100644 --- a/octopusdeploy_framework/schemas/environment.go +++ b/octopusdeploy_framework/schemas/environment.go @@ -30,6 +30,10 @@ const ( EnvironmentServiceNowExtensionSettingsIsEnabled = "is_enabled" ) +type EnvironmentSchema struct{} + +var _ EntitySchema = EnvironmentSchema{} + var jiraEnvironmentTypeNames = struct { Development string Production string @@ -74,13 +78,38 @@ func EnvironmentObjectType() map[string]attr.Type { } } -func GetEnvironmentDatasourceSchema() map[string]datasourceSchema.Attribute { +func (e EnvironmentSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{ + Description: "Provides information about existing environments.", + Attributes: map[string]datasourceSchema.Attribute{ + //request + "ids": GetQueryIDsDatasourceSchema(), + "space_id": GetSpaceIdDatasourceSchema(EnvironmentResourceDescription, false), + "name": GetQueryNameDatasourceSchema(), + "partial_name": GetQueryPartialNameDatasourceSchema(), + "skip": GetQuerySkipDatasourceSchema(), + "take": GetQueryTakeDatasourceSchema(), + + //response + "id": GetIdDatasourceSchema(true), + "environments": datasourceSchema.ListNestedAttribute{ + Computed: true, + Optional: false, + NestedObject: datasourceSchema.NestedAttributeObject{ + Attributes: e.GetDatasourceSchemaAttributes(), + }, + }, + }, + } +} + +func (e EnvironmentSchema) GetDatasourceSchemaAttributes() map[string]datasourceSchema.Attribute { return map[string]datasourceSchema.Attribute{ "id": GetIdDatasourceSchema(true), - "slug": util.GetSlugDatasourceSchema(EnvironmentResourceDescription, true), + "slug": GetSlugDatasourceSchema(EnvironmentResourceDescription, true), "name": GetReadonlyNameDatasourceSchema(), - "description": util.GetDescriptionDatasourceSchema(EnvironmentResourceDescription), - EnvironmentSortOrder: util.GetSortOrderDataSourceSchema(EnvironmentResourceDescription), + "description": GetDescriptionDatasourceSchema(EnvironmentResourceDescription), + EnvironmentSortOrder: GetSortOrderDatasourceSchema(EnvironmentResourceDescription), EnvironmentAllowDynamicInfrastructure: datasourceSchema.BoolAttribute{ Computed: true, }, @@ -125,15 +154,15 @@ func GetEnvironmentDatasourceSchema() map[string]datasourceSchema.Attribute { } } -func GetEnvironmentResourceSchema() resourceSchema.Schema { +func (e EnvironmentSchema) GetResourceSchema() resourceSchema.Schema { return resourceSchema.Schema{ Description: util.GetResourceSchemaDescription(EnvironmentResourceDescription), Attributes: map[string]resourceSchema.Attribute{ - "id": util.GetIdResourceSchema(), - "slug": util.GetSlugResourceSchema(EnvironmentResourceDescription), - "name": util.GetNameResourceSchema(true), - "description": util.GetDescriptionResourceSchema(EnvironmentResourceDescription), - EnvironmentSortOrder: util.GetSortOrderResourceSchema(EnvironmentResourceDescription), + "id": GetIdResourceSchema(), + "slug": GetSlugResourceSchema(EnvironmentResourceDescription), + "name": GetNameResourceSchema(true), + "description": GetDescriptionResourceSchema(EnvironmentResourceDescription), + EnvironmentSortOrder: GetSortOrderResourceSchema(EnvironmentResourceDescription), EnvironmentAllowDynamicInfrastructure: resourceSchema.BoolAttribute{ Optional: true, Computed: true, @@ -144,7 +173,7 @@ func GetEnvironmentResourceSchema() resourceSchema.Schema { Computed: true, Default: booldefault.StaticBool(false), }, - "space_id": util.GetSpaceIdResourceSchema(EnvironmentResourceDescription), + "space_id": GetSpaceIdResourceSchema(EnvironmentResourceDescription), }, Blocks: map[string]resourceSchema.Block{ EnvironmentJiraExtensionSettings: resourceSchema.ListNestedBlock{ diff --git a/octopusdeploy_framework/schemas/feed.go b/octopusdeploy_framework/schemas/feed.go index edacbed95..a792610cc 100644 --- a/octopusdeploy_framework/schemas/feed.go +++ b/octopusdeploy_framework/schemas/feed.go @@ -3,10 +3,7 @@ package schemas import ( "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds" "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" - datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -55,128 +52,3 @@ func FeedObjectType() map[string]attr.Type { "secret_key": types.StringType, } } - -func GetFeedsDataSourceSchema() 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, - Validators: []validator.String{ - stringvalidator.OneOf( - "AwsElasticContainerRegistry", - "BuiltIn", - "Docker", - "GitHub", - "Helm", - "Maven", - "NuGet", - "OctopusProject"), - }, - }, - "ids": util.GetQueryIDsDatasourceSchema(), - "name": util.GetNameDatasourceSchema(false), - "partial_name": util.GetQueryPartialNameDatasourceSchema(), - "skip": util.GetQuerySkipDatasourceSchema(), - "take": util.GetQueryTakeDatasourceSchema(), - "space_id": GetSpaceIdDatasourceSchema("feeds", false), - - // response - "id": GetIdDatasourceSchema(true), - "feeds": datasourceSchema.ListNestedAttribute{ - Computed: true, - Optional: false, - NestedObject: datasourceSchema.NestedAttributeObject{ - Attributes: GetFeedDataSourceSchema(), - }, - }, - } -} - -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`.", - Computed: true, - Validators: []validator.String{ - stringvalidator.OneOf( - "AwsElasticContainerRegistry", - "BuiltIn", - "Docker", - "GitHub", - "Helm", - "Maven", - "NuGet", - "OctopusProject"), - }, - }, - "feed_uri": datasourceSchema.StringAttribute{ - Computed: true, - }, - "id": GetIdDatasourceSchema(true), - "is_enhanced_mode": datasourceSchema.BoolAttribute{ - Computed: true, - }, - "name": GetReadonlyNameDatasourceSchema(), - "password": datasourceSchema.StringAttribute{ - Description: "The password associated with this resource.", - Sensitive: true, - Computed: true, - Validators: []validator.String{ - stringvalidator.LengthAtLeast(1), - }, - }, - "package_acquisition_location_options": datasourceSchema.ListAttribute{ - Computed: true, - ElementType: types.StringType, - }, - "region": datasourceSchema.StringAttribute{ - Computed: true, - }, - "registry_path": datasourceSchema.StringAttribute{ - Computed: true, - }, - "secret_key": datasourceSchema.StringAttribute{ - Computed: true, - Sensitive: true, - }, - "space_id": GetSpaceIdDatasourceSchema("feeds", true), - "username": datasourceSchema.StringAttribute{ - Description: "The username associated with this resource.", - Sensitive: true, - Computed: true, - Validators: []validator.String{ - stringvalidator.LengthAtLeast(1), - }, - }, - "delete_unreleased_packages_after_days": datasourceSchema.Int64Attribute{ - Computed: true, - }, - "access_key": datasourceSchema.StringAttribute{ - Computed: true, - Description: "The AWS access key to use when authenticating against Amazon Web Services.", - }, - "api_version": datasourceSchema.StringAttribute{ - Computed: true, - }, - "download_attempts": datasourceSchema.Int64Attribute{ - Description: "The number of times a deployment should attempt to download a package from this feed before failing.", - Computed: true, - }, - "download_retry_backoff_seconds": datasourceSchema.Int64Attribute{ - Description: "The number of seconds to apply as a linear back off between download attempts.", - Computed: true, - }, - } -} - -type FeedsDataSourceModel struct { - ID types.String `tfsdk:"id"` - Feeds types.List `tfsdk:"feeds"` - FeedType types.String `tfsdk:"feed_type"` - IDs types.List `tfsdk:"ids"` - Name types.String `tfsdk:"name"` - PartialName types.String `tfsdk:"partial_name"` - Skip types.Int64 `tfsdk:"skip"` - Take types.Int64 `tfsdk:"take"` - SpaceID types.String `tfsdk:"space_id"` -} diff --git a/octopusdeploy_framework/schemas/feeds.go b/octopusdeploy_framework/schemas/feeds.go new file mode 100644 index 000000000..b0c9d775e --- /dev/null +++ b/octopusdeploy_framework/schemas/feeds.go @@ -0,0 +1,141 @@ +package schemas + +import ( + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +type FeedsSchema struct{} + +var _ EntitySchema = FeedsSchema{} + +func (f FeedsSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{} +} + +func (f FeedsSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{ + Description: "Provides information about existing feeds.", + Attributes: 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, + Validators: []validator.String{ + stringvalidator.OneOf( + "AwsElasticContainerRegistry", + "BuiltIn", + "Docker", + "GitHub", + "Helm", + "Maven", + "NuGet", + "OctopusProject"), + }, + }, + "ids": GetQueryIDsDatasourceSchema(), + "name": GetNameDatasourceSchema(false), + "partial_name": GetQueryPartialNameDatasourceSchema(), + "skip": GetQuerySkipDatasourceSchema(), + "take": GetQueryTakeDatasourceSchema(), + "space_id": GetSpaceIdDatasourceSchema("feeds", false), + + // response + "id": GetIdDatasourceSchema(true), + "feeds": datasourceSchema.ListNestedAttribute{ + Computed: true, + Optional: false, + NestedObject: datasourceSchema.NestedAttributeObject{ + Attributes: 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`.", + Computed: true, + Validators: []validator.String{ + stringvalidator.OneOf( + "AwsElasticContainerRegistry", + "BuiltIn", + "Docker", + "GitHub", + "Helm", + "Maven", + "NuGet", + "OctopusProject"), + }, + }, + "feed_uri": datasourceSchema.StringAttribute{ + Computed: true, + }, + "id": GetIdDatasourceSchema(true), + "is_enhanced_mode": datasourceSchema.BoolAttribute{ + Computed: true, + }, + "name": GetReadonlyNameDatasourceSchema(), + "password": datasourceSchema.StringAttribute{ + Description: "The password associated with this resource.", + Sensitive: true, + Computed: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + }, + "package_acquisition_location_options": datasourceSchema.ListAttribute{ + Computed: true, + ElementType: types.StringType, + }, + "region": datasourceSchema.StringAttribute{ + Computed: true, + }, + "registry_path": datasourceSchema.StringAttribute{ + Computed: true, + }, + "secret_key": datasourceSchema.StringAttribute{ + Computed: true, + Sensitive: true, + }, + "space_id": GetSpaceIdDatasourceSchema("feeds", true), + "username": datasourceSchema.StringAttribute{ + Description: "The username associated with this resource.", + Sensitive: true, + Computed: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + }, + "delete_unreleased_packages_after_days": datasourceSchema.Int64Attribute{ + Computed: true, + }, + "access_key": datasourceSchema.StringAttribute{ + Computed: true, + Description: "The AWS access key to use when authenticating against Amazon Web Services.", + }, + "api_version": datasourceSchema.StringAttribute{ + Computed: true, + }, + "download_attempts": datasourceSchema.Int64Attribute{ + Description: "The number of times a deployment should attempt to download a package from this feed before failing.", + Computed: true, + }, + "download_retry_backoff_seconds": datasourceSchema.Int64Attribute{ + Description: "The number of seconds to apply as a linear back off between download attempts.", + Computed: true, + }, + }, + }, + }, + }, + } +} + +type FeedsDataSourceModel struct { + ID types.String `tfsdk:"id"` + Feeds types.List `tfsdk:"feeds"` + FeedType types.String `tfsdk:"feed_type"` + IDs types.List `tfsdk:"ids"` + Name types.String `tfsdk:"name"` + PartialName types.String `tfsdk:"partial_name"` + Skip types.Int64 `tfsdk:"skip"` + Take types.Int64 `tfsdk:"take"` + SpaceID types.String `tfsdk:"space_id"` +} diff --git a/octopusdeploy_framework/schemas/gitCredential.go b/octopusdeploy_framework/schemas/git_credential.go similarity index 94% rename from octopusdeploy_framework/schemas/gitCredential.go rename to octopusdeploy_framework/schemas/git_credential.go index 1352a2ddc..43d57ea30 100644 --- a/octopusdeploy_framework/schemas/gitCredential.go +++ b/octopusdeploy_framework/schemas/git_credential.go @@ -13,7 +13,11 @@ const ( GitCredentialDatasourceName = "git_credentials" ) -func GetGitCredentialResourceSchema() resourceSchema.Schema { +type GitCredentialSchema struct{} + +var _ EntitySchema = GitCredentialSchema{} + +func (g GitCredentialSchema) GetResourceSchema() resourceSchema.Schema { return resourceSchema.Schema{ Description: "Manages a Git credential in Octopus Deploy.", Attributes: map[string]resourceSchema.Attribute{ @@ -42,7 +46,7 @@ func GetGitCredentialResourceSchema() resourceSchema.Schema { } } -func GetGitCredentialDataSourceSchema() datasourceSchema.Schema { +func (g GitCredentialSchema) GetDatasourceSchema() datasourceSchema.Schema { return datasourceSchema.Schema{ Description: "Use this data source to retrieve information about Git credentials in Octopus Deploy.", Attributes: map[string]datasourceSchema.Attribute{ diff --git a/octopusdeploy_framework/schemas/github_repository_feed.go b/octopusdeploy_framework/schemas/github_repository_feed.go index 71049f464..cb04cfcfb 100644 --- a/octopusdeploy_framework/schemas/github_repository_feed.go +++ b/octopusdeploy_framework/schemas/github_repository_feed.go @@ -1,27 +1,38 @@ package schemas import ( - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" ) const gitHubRepositoryFeedDescription = "github repository feed" -func GetGitHubRepositoryFeedResourceSchema() map[string]resourceSchema.Attribute { - return map[string]resourceSchema.Attribute{ - "download_attempts": util.GetDownloadAttemptsResourceSchema(), - "download_retry_backoff_seconds": util.GetDownloadRetryBackoffSecondsResourceSchema(), - "feed_uri": util.GetFeedUriResourceSchema(), - "id": util.GetIdResourceSchema(), - "name": util.GetNameResourceSchema(true), - "package_acquisition_location_options": util.GetPackageAcquisitionLocationOptionsResourceSchema(), - "password": util.GetPasswordResourceSchema(false), - "space_id": util.GetSpaceIdResourceSchema(gitHubRepositoryFeedDescription), - "username": util.GetUsernameResourceSchema(false), +type GitHubRepositoryFeedSchema struct{} + +var _ EntitySchema = GitHubRepositoryFeedSchema{} + +func (g GitHubRepositoryFeedSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Description: "This resource manages a GitHub repository feed in Octopus Deploy.", + Attributes: map[string]resourceSchema.Attribute{ + "download_attempts": GetDownloadAttemptsResourceSchema(), + "download_retry_backoff_seconds": GetDownloadRetryBackoffSecondsResourceSchema(), + "feed_uri": GetFeedUriResourceSchema(), + "id": GetIdResourceSchema(), + "name": GetNameResourceSchema(true), + "package_acquisition_location_options": GetPackageAcquisitionLocationOptionsResourceSchema(), + "password": GetPasswordResourceSchema(false), + "space_id": GetSpaceIdResourceSchema(gitHubRepositoryFeedDescription), + "username": GetUsernameResourceSchema(false), + }, } } +func (g GitHubRepositoryFeedSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{} +} + type GitHubRepositoryFeedTypeResourceModel struct { DownloadAttempts types.Int64 `tfsdk:"download_attempts"` DownloadRetryBackoffSeconds types.Int64 `tfsdk:"download_retry_backoff_seconds"` diff --git a/octopusdeploy_framework/schemas/helm_feed.go b/octopusdeploy_framework/schemas/helm_feed.go index 7e3072fee..1efbb4619 100644 --- a/octopusdeploy_framework/schemas/helm_feed.go +++ b/octopusdeploy_framework/schemas/helm_feed.go @@ -1,22 +1,33 @@ package schemas import ( - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" ) const helmFeedDescription = "helm feed" -func GetHelmFeedResourceSchema() map[string]resourceSchema.Attribute { - return map[string]resourceSchema.Attribute{ - "feed_uri": util.GetFeedUriResourceSchema(), - "id": util.GetIdResourceSchema(), - "name": util.GetNameResourceSchema(true), - "package_acquisition_location_options": util.GetPackageAcquisitionLocationOptionsResourceSchema(), - "password": util.GetPasswordResourceSchema(false), - "space_id": util.GetSpaceIdResourceSchema(helmFeedDescription), - "username": util.GetUsernameResourceSchema(false), +type HelmFeedSchema struct{} + +func (h HelmFeedSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{} +} + +var _ EntitySchema = HelmFeedSchema{} + +func (h HelmFeedSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Description: "This resource manages a Helm Feed in Octopus Deploy.", + Attributes: map[string]resourceSchema.Attribute{ + "feed_uri": GetFeedUriResourceSchema(), + "id": GetIdResourceSchema(), + "name": GetNameResourceSchema(true), + "package_acquisition_location_options": GetPackageAcquisitionLocationOptionsResourceSchema(), + "password": GetPasswordResourceSchema(false), + "space_id": GetSpaceIdResourceSchema(helmFeedDescription), + "username": GetUsernameResourceSchema(false), + }, } } diff --git a/octopusdeploy_framework/schemas/library_variable_set.go b/octopusdeploy_framework/schemas/library_variable_set.go index c449dc51f..4651f73e1 100644 --- a/octopusdeploy_framework/schemas/library_variable_set.go +++ b/octopusdeploy_framework/schemas/library_variable_set.go @@ -12,6 +12,10 @@ import ( types "github.com/hashicorp/terraform-plugin-framework/types" ) +type LibraryVariableSetSchema struct{} + +var _ EntitySchema = LibraryVariableSetSchema{} + type LibraryVariableSetResourceModel struct { Description types.String `tfsdk:"description"` Name types.String `tfsdk:"name"` @@ -23,7 +27,7 @@ type LibraryVariableSetResourceModel struct { ResourceModel } -func GetLibraryVariableSetDataSourceSchema() datasourceSchema.Schema { +func (l LibraryVariableSetSchema) GetDatasourceSchema() datasourceSchema.Schema { return datasourceSchema.Schema{ Description: "Provides information about existing library variable sets.", Attributes: map[string]datasourceSchema.Attribute{ @@ -33,41 +37,37 @@ func GetLibraryVariableSetDataSourceSchema() datasourceSchema.Schema { }, "id": GetIdDatasourceSchema(true), "space_id": GetSpaceIdDatasourceSchema("library variable set", false), - "ids": util.GetQueryIDsDatasourceSchema(), - "partial_name": util.GetQueryPartialNameDatasourceSchema(), - "skip": util.GetQuerySkipDatasourceSchema(), - "take": util.GetQueryTakeDatasourceSchema(), + "ids": GetQueryIDsDatasourceSchema(), + "partial_name": GetQueryPartialNameDatasourceSchema(), + "skip": GetQuerySkipDatasourceSchema(), + "take": GetQueryTakeDatasourceSchema(), "library_variable_sets": datasourceSchema.ListNestedAttribute{ Computed: true, Optional: false, NestedObject: datasourceSchema.NestedAttributeObject{ - Attributes: GetLibraryVariableSetObjectDatasourceSchema(), + Attributes: map[string]datasourceSchema.Attribute{ + "description": GetReadonlyDescriptionDatasourceSchema("library variable set"), + "id": GetIdDatasourceSchema(true), + "name": GetReadonlyNameDatasourceSchema(), + "space_id": GetSpaceIdDatasourceSchema("library variable set", true), + "template_ids": datasourceSchema.MapAttribute{ + ElementType: types.StringType, + Computed: true, + }, + "template": datasourceSchema.ListAttribute{ + Computed: true, + ElementType: types.ObjectType{AttrTypes: TemplateObjectType()}, + }, + "variable_set_id": datasourceSchema.StringAttribute{ + Computed: true, + }, + }, }, }, }, } } -func GetLibraryVariableSetObjectDatasourceSchema() map[string]datasourceSchema.Attribute { - return map[string]datasourceSchema.Attribute{ - "description": GetReadonlyDescriptionDatasourceSchema("library variable set"), - "id": GetIdDatasourceSchema(true), - "name": GetReadonlyNameDatasourceSchema(), - "space_id": GetSpaceIdDatasourceSchema("library variable set", true), - "template_ids": datasourceSchema.MapAttribute{ - ElementType: types.StringType, - Computed: true, - }, - "template": datasourceSchema.ListAttribute{ - Computed: true, - ElementType: types.ObjectType{AttrTypes: TemplateObjectType()}, - }, - "variable_set_id": datasourceSchema.StringAttribute{ - Computed: true, - }, - } -} - func GetLibraryVariableSetObjectType() map[string]attr.Type { return map[string]attr.Type{ "description": types.StringType, @@ -80,7 +80,7 @@ func GetLibraryVariableSetObjectType() map[string]attr.Type { } } -func GetLibraryVariableSetResourceSchema() resourceSchema.Schema { +func (l LibraryVariableSetSchema) GetResourceSchema() resourceSchema.Schema { return resourceSchema.Schema{ Attributes: map[string]resourceSchema.Attribute{ "description": GetDescriptionResourceSchema("library variable set"), @@ -100,11 +100,7 @@ func GetLibraryVariableSetResourceSchema() resourceSchema.Schema { }, Description: "This resource manages library variable sets in Octopus Deploy.", Blocks: map[string]resourceSchema.Block{ - "template": resourceSchema.ListNestedBlock{ - NestedObject: resourceSchema.NestedBlockObject{ - Attributes: GetActionTemplateParameterSchema(), - }, - }, + "template": GetActionTemplateParameterSchema(), }, } } diff --git a/octopusdeploy_framework/schemas/lifecycle.go b/octopusdeploy_framework/schemas/lifecycle.go index ff6941d3b..bdf4662e3 100644 --- a/octopusdeploy_framework/schemas/lifecycle.go +++ b/octopusdeploy_framework/schemas/lifecycle.go @@ -16,7 +16,11 @@ import ( "strings" ) -func GetResourceLifecycleSchema() resourceSchema.Schema { +var _ EntitySchema = LifecycleSchema{} + +type LifecycleSchema struct{} + +func (l LifecycleSchema) GetResourceSchema() resourceSchema.Schema { return resourceSchema.Schema{ Description: "This resource manages lifecycles in Octopus Deploy.", Attributes: map[string]resourceSchema.Attribute{ @@ -33,7 +37,7 @@ func GetResourceLifecycleSchema() resourceSchema.Schema { } } -func GetDatasourceLifecycleSchema() datasourceSchema.Schema { +func (l LifecycleSchema) GetDatasourceSchema() datasourceSchema.Schema { return datasourceSchema.Schema{ Description: "Provides information about existing lifecycles.", Attributes: map[string]datasourceSchema.Attribute{ diff --git a/octopusdeploy_framework/schemas/maven_feed.go b/octopusdeploy_framework/schemas/maven_feed.go index 9c01debc3..7178456a9 100644 --- a/octopusdeploy_framework/schemas/maven_feed.go +++ b/octopusdeploy_framework/schemas/maven_feed.go @@ -1,27 +1,38 @@ package schemas import ( - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" ) const mavenFeedDescription = "maven feed" -func GetMavenFeedResourceSchema() map[string]resourceSchema.Attribute { - return map[string]resourceSchema.Attribute{ - "download_attempts": util.GetDownloadAttemptsResourceSchema(), - "download_retry_backoff_seconds": util.GetDownloadRetryBackoffSecondsResourceSchema(), - "feed_uri": util.GetFeedUriResourceSchema(), - "id": util.GetIdResourceSchema(), - "name": util.GetNameResourceSchema(true), - "package_acquisition_location_options": util.GetPackageAcquisitionLocationOptionsResourceSchema(), - "password": util.GetPasswordResourceSchema(false), - "space_id": util.GetSpaceIdResourceSchema(mavenFeedDescription), - "username": util.GetUsernameResourceSchema(false), +type MavenFeedSchema struct{} + +func (m MavenFeedSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Description: "This resource manages a Maven feed in Octopus Deploy.", + Attributes: map[string]resourceSchema.Attribute{ + "download_attempts": GetDownloadAttemptsResourceSchema(), + "download_retry_backoff_seconds": GetDownloadRetryBackoffSecondsResourceSchema(), + "feed_uri": GetFeedUriResourceSchema(), + "id": GetIdResourceSchema(), + "name": GetNameResourceSchema(true), + "package_acquisition_location_options": GetPackageAcquisitionLocationOptionsResourceSchema(), + "password": GetPasswordResourceSchema(false), + "space_id": GetSpaceIdResourceSchema(mavenFeedDescription), + "username": GetUsernameResourceSchema(false), + }, } } +func (m MavenFeedSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{} +} + +var _ EntitySchema = MavenFeedSchema{} + type MavenFeedTypeResourceModel struct { DownloadAttempts types.Int64 `tfsdk:"download_attempts"` DownloadRetryBackoffSeconds types.Int64 `tfsdk:"download_retry_backoff_seconds"` diff --git a/octopusdeploy_framework/schemas/nuget_feed.go b/octopusdeploy_framework/schemas/nuget_feed.go index a744dafb1..5b4db44fd 100644 --- a/octopusdeploy_framework/schemas/nuget_feed.go +++ b/octopusdeploy_framework/schemas/nuget_feed.go @@ -1,7 +1,7 @@ package schemas import ( - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + 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/types" @@ -9,26 +9,37 @@ import ( const nugetFeedDescription = "nuget feed" -func GetNugetFeedResourceSchema() map[string]resourceSchema.Attribute { - return map[string]resourceSchema.Attribute{ - "download_attempts": util.GetDownloadAttemptsResourceSchema(), - "download_retry_backoff_seconds": util.GetDownloadRetryBackoffSecondsResourceSchema(), - "feed_uri": util.GetFeedUriResourceSchema(), - "id": util.GetIdResourceSchema(), - "is_enhanced_mode": resourceSchema.BoolAttribute{ - Computed: true, - Default: booldefault.StaticBool(true), - Description: "This will improve performance of the NuGet feed but may not be supported by some older feeds. Disable if the operation, Create Release does not return the latest version for a package.", - Optional: true, +type NugetFeedSchema struct{} + +var _ EntitySchema = NugetFeedSchema{} + +func (n NugetFeedSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Attributes: map[string]resourceSchema.Attribute{ + "download_attempts": GetDownloadAttemptsResourceSchema(), + "download_retry_backoff_seconds": GetDownloadRetryBackoffSecondsResourceSchema(), + "feed_uri": GetFeedUriResourceSchema(), + "id": GetIdResourceSchema(), + "is_enhanced_mode": resourceSchema.BoolAttribute{ + Computed: true, + Default: booldefault.StaticBool(true), + Description: "This will improve performance of the NuGet feed but may not be supported by some older feeds. Disable if the operation, Create Release does not return the latest version for a package.", + Optional: true, + }, + "name": GetNameResourceSchema(true), + "package_acquisition_location_options": GetPackageAcquisitionLocationOptionsResourceSchema(), + "password": GetPasswordResourceSchema(false), + "space_id": GetSpaceIdResourceSchema(nugetFeedDescription), + "username": GetUsernameResourceSchema(false), }, - "name": util.GetNameResourceSchema(true), - "package_acquisition_location_options": util.GetPackageAcquisitionLocationOptionsResourceSchema(), - "password": util.GetPasswordResourceSchema(false), - "space_id": util.GetSpaceIdResourceSchema(nugetFeedDescription), - "username": util.GetUsernameResourceSchema(false), + Description: "This resource manages a Nuget feed in Octopus Deploy.", } } +func (n NugetFeedSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{} +} + type NugetFeedTypeResourceModel struct { DownloadAttempts types.Int64 `tfsdk:"download_attempts"` DownloadRetryBackoffSeconds types.Int64 `tfsdk:"download_retry_backoff_seconds"` diff --git a/octopusdeploy_framework/schemas/project.go b/octopusdeploy_framework/schemas/project.go index 6ab43ea08..ac7898ab2 100644 --- a/octopusdeploy_framework/schemas/project.go +++ b/octopusdeploy_framework/schemas/project.go @@ -12,17 +12,21 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" ) +type ProjectSchema struct{} + +var _ EntitySchema = ProjectSchema{} + const ProjectResourceName = "project" const ProjectDataSourceName = "projects" -func GetProjectResourceSchema() resourceSchema.Schema { +func (p ProjectSchema) GetResourceSchema() resourceSchema.Schema { return resourceSchema.Schema{ Description: "This resource manages projects in Octopus Deploy.", Attributes: map[string]resourceSchema.Attribute{ - "id": util.GetIdResourceSchema(), - "space_id": util.GetSpaceIdResourceSchema(ProjectResourceName), - "name": util.GetNameResourceSchema(true), - "description": util.GetDescriptionResourceSchema(ProjectResourceName), + "id": GetIdResourceSchema(), + "space_id": GetSpaceIdResourceSchema(ProjectResourceName), + "name": GetNameResourceSchema(true), + "description": GetDescriptionResourceSchema(ProjectResourceName), "allow_deployments_to_no_targets": util.ResourceBool().Optional().Deprecated("This value is only valid for an associated connectivity policy and should not be specified here.").Build(), "auto_create_release": util.ResourceBool().Optional().Computed().PlanModifiers(boolplanmodifier.UseStateForUnknown()).Build(), "cloned_from_project_id": util.ResourceString().Optional().Description("The ID of the project this project was cloned from.").Build(), @@ -183,19 +187,19 @@ func GetProjectResourceSchema() resourceSchema.Schema { } } -func GetProjectDataSourceSchema() datasourceSchema.Schema { +func (p ProjectSchema) GetDatasourceSchema() datasourceSchema.Schema { return datasourceSchema.Schema{ Description: "Provides information about existing Octopus Deploy projects.", Attributes: map[string]datasourceSchema.Attribute{ - "id": util.ResourceString().Computed().Description("An auto-generated identifier that includes the timestamp when this data source was last modified.").Build(), + "id": util.DataSourceString().Computed().Description("An auto-generated identifier that includes the timestamp when this data source was last modified.").Build(), "cloned_from_project_id": util.DataSourceString().Optional().Description("A filter to search for cloned resources by a project ID.").Build(), - "ids": util.GetQueryIDsDatasourceSchema(), + "ids": GetQueryIDsDatasourceSchema(), "is_clone": util.DataSourceBool().Optional().Description("A filter to search for cloned resources.").Build(), "name": util.DataSourceString().Optional().Description("A filter to search by name").Build(), - "partial_name": util.GetQueryPartialNameDatasourceSchema(), - "skip": util.GetQuerySkipDatasourceSchema(), - "space_id": util.ResourceString().Optional().Description("A Space ID to filter by. Will revert what is specified on the provider if not set").Build(), - "take": util.GetQueryTakeDatasourceSchema(), + "partial_name": GetQueryPartialNameDatasourceSchema(), + "skip": GetQuerySkipDatasourceSchema(), + "space_id": util.DataSourceString().Optional().Description("A Space ID to filter by. Will revert what is specified on the provider if not set").Build(), + "take": GetQueryTakeDatasourceSchema(), "projects": getProjectsDataSourceAttribute(), }, } diff --git a/octopusdeploy_framework/schemas/project_group.go b/octopusdeploy_framework/schemas/project_group.go index a3731d9a9..9ad195bdf 100644 --- a/octopusdeploy_framework/schemas/project_group.go +++ b/octopusdeploy_framework/schemas/project_group.go @@ -1,7 +1,6 @@ package schemas import ( - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -9,21 +8,47 @@ import ( const projectGroupDescription = "project group" -func GetProjectGroupDatasourceSchema() map[string]datasourceSchema.Attribute { - return map[string]datasourceSchema.Attribute{ - "id": GetIdDatasourceSchema(true), - "space_id": GetSpaceIdDatasourceSchema(projectGroupDescription, true), - "name": GetReadonlyNameDatasourceSchema(), - "description": GetReadonlyDescriptionDatasourceSchema(projectGroupDescription), +type ProjectGroupSchema struct{} + +var _ EntitySchema = ProjectGroupSchema{} + +func (p ProjectGroupSchema) GetDatasourceSchema() datasourceSchema.Schema { + description := "project group" + return datasourceSchema.Schema{ + Attributes: map[string]datasourceSchema.Attribute{ + // request + "space_id": GetSpaceIdDatasourceSchema(description, false), + "ids": GetQueryIDsDatasourceSchema(), + "partial_name": GetQueryPartialNameDatasourceSchema(), + "skip": GetQuerySkipDatasourceSchema(), + "take": GetQueryTakeDatasourceSchema(), + + // response + "id": GetIdDatasourceSchema(true), + "project_groups": datasourceSchema.ListNestedAttribute{ + Computed: true, + Description: "A list of project groups that match the filter(s).", + NestedObject: datasourceSchema.NestedAttributeObject{ + Attributes: map[string]datasourceSchema.Attribute{ + "id": GetIdDatasourceSchema(true), + "space_id": GetSpaceIdDatasourceSchema(description, true), + "name": GetReadonlyNameDatasourceSchema(), + "description": GetDescriptionDatasourceSchema(projectGroupDescription), + }, + }, + }, + }, } } -func GetProjectGroupResourceSchema() map[string]resourceSchema.Attribute { - return map[string]resourceSchema.Attribute{ - "id": util.GetIdResourceSchema(), - "space_id": util.GetSpaceIdResourceSchema(projectGroupDescription), - "name": util.GetNameResourceSchema(true), - "description": util.GetDescriptionResourceSchema(projectGroupDescription), +func (p ProjectGroupSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Attributes: map[string]resourceSchema.Attribute{ + "id": GetIdResourceSchema(), + "space_id": GetSpaceIdResourceSchema(projectGroupDescription), + "name": GetNameResourceSchema(true), + "description": GetDescriptionResourceSchema(projectGroupDescription), + }, } } diff --git a/octopusdeploy_framework/schemas/runbook.go b/octopusdeploy_framework/schemas/runbook.go index 2bc493d94..084fa0570 100644 --- a/octopusdeploy_framework/schemas/runbook.go +++ b/octopusdeploy_framework/schemas/runbook.go @@ -3,6 +3,9 @@ package schemas import ( "context" "fmt" + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + + //datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "regexp" "strings" @@ -133,11 +136,19 @@ type RunbookConnectivityPolicyModel struct { TargetRoles types.List `tfsdk:"target_roles"` } -func GetRunbookResourceSchema() resourceSchema.Schema { +type RunbookSchema struct{} + +func (r RunbookSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{} +} + +var _ EntitySchema = RunbookSchema{} + +func (r RunbookSchema) GetResourceSchema() resourceSchema.Schema { return resourceSchema.Schema{ Description: util.GetResourceSchemaDescription(RunbookResourceDescription), Attributes: map[string]resourceSchema.Attribute{ - RunbookSchemaAttributeNames.ID: util.GetIdResourceSchema(), + RunbookSchemaAttributeNames.ID: GetIdResourceSchema(), RunbookSchemaAttributeNames.Name: resourceSchema.StringAttribute{ Description: "The name of the runbook in Octopus Deploy. This name must be unique.", Required: true, @@ -148,7 +159,7 @@ func GetRunbookResourceSchema() resourceSchema.Schema { ), }, }, - RunbookSchemaAttributeNames.Description: util.GetDescriptionResourceSchema(RunbookResourceDescription), + RunbookSchemaAttributeNames.Description: GetDescriptionResourceSchema(RunbookResourceDescription), RunbookSchemaAttributeNames.ProjectID: resourceSchema.StringAttribute{ Description: "The project that this runbook belongs to.", Required: true, @@ -167,7 +178,7 @@ func GetRunbookResourceSchema() resourceSchema.Schema { stringplanmodifier.UseStateForUnknown(), }, }, - RunbookSchemaAttributeNames.SpaceID: util.GetSpaceIdResourceSchema(RunbookResourceDescription), + RunbookSchemaAttributeNames.SpaceID: GetSpaceIdResourceSchema(RunbookResourceDescription), RunbookSchemaAttributeNames.MultiTenancyMode: resourceSchema.StringAttribute{ Description: fmt.Sprintf("The tenanted deployment mode of the runbook. Valid modes are %s", strings.Join(util.Map(tenantedDeploymentModes, func(item string) string { return fmt.Sprintf("`%s`", item) }), ", ")), Computed: true, diff --git a/octopusdeploy_framework/schemas/schema.go b/octopusdeploy_framework/schemas/schema.go index e67c11dc3..70652b5d6 100644 --- a/octopusdeploy_framework/schemas/schema.go +++ b/octopusdeploy_framework/schemas/schema.go @@ -2,12 +2,13 @@ package schemas import ( "fmt" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" - //"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" @@ -64,77 +65,60 @@ func GetReadonlyNameDatasourceSchema() datasourceSchema.Attribute { } } -func GetIdDatasourceSchema(isReadOnly bool) datasourceSchema.Attribute { +func GetNameDatasourceSchema(isRequired bool) datasourceSchema.Attribute { s := datasourceSchema.StringAttribute{ - Description: "The unique ID for this resource.", + Description: "The name of this resource.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, } - if isReadOnly { - s.Computed = true + if isRequired { + s.Required = 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 + ".", - } - - if isReadOnly { - s.Computed = true - } else { - s.Computed = true - s.Optional = true +func GetQueryNameDatasourceSchema() datasourceSchema.Attribute { + return datasourceSchema.StringAttribute{ + Description: "A filter search by exact name", + Optional: true, } - - return s } -func GetNameDatasourceWithMaxLengthSchema(isRequired bool, maxLength int) datasourceSchema.Attribute { +func GetIdDatasourceSchema(isReadOnly bool) datasourceSchema.Attribute { s := datasourceSchema.StringAttribute{ - Description: fmt.Sprintf("The name of this resource, no more than %d characters long", maxLength), - Validators: []validator.String{ - stringvalidator.LengthBetween(1, maxLength), - }, + Description: "The unique ID for this resource.", } - if isRequired { - s.Required = true + if isReadOnly { + s.Computed = true } else { + s.Computed = true s.Optional = true } return s } -func GetNameDatasourceSchema(isRequired bool) datasourceSchema.Attribute { +func GetSpaceIdDatasourceSchema(resourceDescription string, isReadOnly bool) datasourceSchema.Attribute { s := datasourceSchema.StringAttribute{ - Description: "The name of this resource.", - Validators: []validator.String{ - stringvalidator.LengthAtLeast(1), - }, + Description: "The space ID associated with this " + resourceDescription + ".", } - if isRequired { - s.Required = true + if isReadOnly { + s.Computed = true } else { + s.Computed = true s.Optional = true } return s } -func GetDescriptionDatasourceSchema(resourceDescription string) datasourceSchema.Attribute { - return datasourceSchema.StringAttribute{ - Description: "The description of this " + resourceDescription + ".", - Optional: true, - } -} - func GetReadonlyDescriptionDatasourceSchema(resourceDescription string) datasourceSchema.Attribute { return datasourceSchema.StringAttribute{ Description: "The description of this " + resourceDescription + ".", @@ -190,6 +174,21 @@ func GetDescriptionResourceSchema(resourceDescription string) resourceSchema.Att } } +func GetDescriptionDatasourceSchema(resourceDescription string) datasourceSchema.Attribute { + return datasourceSchema.StringAttribute{ + Description: "The description of this " + resourceDescription + ".", + Computed: true, + } +} + +func GetQueryDatasourceTags() datasourceSchema.Attribute { + return datasourceSchema.ListAttribute{ + Description: "A filter to search by a list of tags.", + ElementType: types.StringType, + Optional: true, + } +} + func GetSlugDatasourceSchema(resourceDescription string, isReadOnly bool) datasourceSchema.Attribute { s := datasourceSchema.StringAttribute{ Description: fmt.Sprintf("The unique slug of this %s", resourceDescription), @@ -206,7 +205,7 @@ func GetSlugDatasourceSchema(resourceDescription string, isReadOnly bool) dataso } func GetSlugResourceSchema(resourceDescription string) resourceSchema.Attribute { - return datasourceSchema.StringAttribute{ + return resourceSchema.StringAttribute{ Description: fmt.Sprintf("The unique slug of this %s", resourceDescription), Optional: true, Computed: true, @@ -221,6 +220,86 @@ func GetBooleanDatasourceAttribute(description string, isOptional bool) datasour } } +func GetSortOrderDatasourceSchema(resourceDescription string) datasourceSchema.Attribute { + return datasourceSchema.Int64Attribute{ + Description: fmt.Sprintf("The order number to sort an %s", resourceDescription), + Computed: true, + } +} + +func GetSortOrderResourceSchema(resourceDescription string) resourceSchema.Attribute { + return resourceSchema.Int64Attribute{ + Description: fmt.Sprintf("The order number to sort an %s.", resourceDescription), + Optional: true, + Computed: true, + } +} + +func GetPasswordResourceSchema(isRequired bool) resourceSchema.Attribute { + s := resourceSchema.StringAttribute{ + Description: "The password associated with this resource.", + Sensitive: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + } + + if isRequired { + s.Required = true + } else { + s.Optional = true + } + + return s +} + +func GetPackageAcquisitionLocationOptionsResourceSchema() resourceSchema.Attribute { + return resourceSchema.ListAttribute{ + Computed: true, + ElementType: types.StringType, + Optional: true, + PlanModifiers: []planmodifier.List{ + listplanmodifier.UseStateForUnknown(), + }, + } +} + +func GetDownloadAttemptsResourceSchema() resourceSchema.Attribute { + return resourceSchema.Int64Attribute{ + Default: int64default.StaticInt64(5), + Description: "The number of times a deployment should attempt to download a package from this feed before failing.", + Optional: true, + Computed: true, + } +} + +func GetUsernameResourceSchema(isRequired bool) resourceSchema.Attribute { + s := resourceSchema.StringAttribute{ + Description: "The username associated with this resource.", + Sensitive: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + } + + if isRequired { + s.Required = true + } else { + s.Optional = true + } + + return s +} + +func GetDownloadRetryBackoffSecondsResourceSchema() resourceSchema.Attribute { + return resourceSchema.Int64Attribute{ + Default: int64default.StaticInt64(10), + Description: "The number of seconds to apply as a linear back off between download attempts.", + Optional: true, + Computed: true, + } +} + func GetBooleanResourceAttribute(description string, defaultValue bool, isOptional bool) resourceSchema.Attribute { return resourceSchema.BoolAttribute{ Default: booldefault.StaticBool(defaultValue), @@ -230,17 +309,20 @@ func GetBooleanResourceAttribute(description string, defaultValue bool, isOption } } -func GetIds(ids types.List) []string { - var result = make([]string, 0, len(ids.Elements())) - for _, id := range ids.Elements() { - strVal, ok := id.(types.String) +func GetRequiredStringResourceSchema(description string) resourceSchema.StringAttribute { + return resourceSchema.StringAttribute{ + Required: true, + Description: description, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + } +} - if !ok || strVal.IsNull() || strVal.IsUnknown() { - continue - } - result = append(result, strVal.ValueString()) +func GetFeedUriResourceSchema() resourceSchema.Attribute { + return resourceSchema.StringAttribute{ + Required: true, } - return result } func GetNumber(val types.Int64) int { diff --git a/octopusdeploy_framework/schemas/schema_test.go b/octopusdeploy_framework/schemas/schema_test.go new file mode 100644 index 000000000..5b7361eec --- /dev/null +++ b/octopusdeploy_framework/schemas/schema_test.go @@ -0,0 +1,124 @@ +package schemas + +import ( + "fmt" + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/stretchr/testify/require" + "reflect" + "strings" + "testing" +) + +var testableSchemas = []EntitySchema{ + LifecycleSchema{}, + NugetFeedSchema{}, + ProjectSchema{}, + HelmFeedSchema{}, + DockerContainerRegistryFeedSchema{}, + EnvironmentSchema{}, + RunbookSchema{}, + GitCredentialSchema{}, + ArtifactoryGenericFeedSchema{}, + AwsElasticContainerRegistrySchema{}, + FeedsSchema{}, + GitHubRepositoryFeedSchema{}, + SpaceSchema{}, + SpacesSchema{}, + ScriptModuleSchema{}, + LibraryVariableSetSchema{}, + ActionTemplateParameterSchema{}, + MavenFeedSchema{}, + ProjectGroupSchema{}, + TagSchema{}, + UsernamePasswordAccountSchema{}, + VariableSchema{}, + TenantProjectVariableSchema{}, + TenantSchema{}, + TenantProjectsSchema{}, +} + +func TestDatasourceSchemaDefinitionIsUsingCorrectTypes(t *testing.T) { + for _, schema := range testableSchemas { + datasourceTest(t, schema) + } +} + +func TestResourceSchemaDefinitionIsUsingCorrectTypes(t *testing.T) { + for _, schema := range testableSchemas { + resourceTest(t, schema) + } +} + +func resourceTest(t *testing.T, schema EntitySchema) { + entitySchema := schema.GetResourceSchema() + schemaName := typeName(schema) + + checkResourceAttributes(t, schemaName, entitySchema.Attributes) + checkResourceBlocks(t, schemaName, entitySchema.Blocks) +} + +func checkResourceBlocks(t *testing.T, schemaName string, blocks map[string]resourceSchema.Block) { + for _, block := range blocks { + switch b := block.(type) { + case resourceSchema.ListNestedBlock: + checkResourceAttributes(t, schemaName, b.NestedObject.Attributes) + checkResourceBlocks(t, schemaName, b.NestedObject.Blocks) + case resourceSchema.SetNestedBlock: + checkResourceAttributes(t, schemaName, b.NestedObject.Attributes) + checkResourceBlocks(t, schemaName, b.NestedObject.Blocks) + case resourceSchema.SingleNestedBlock: + checkResourceAttributes(t, schemaName, b.Attributes) + checkResourceBlocks(t, schemaName, b.Blocks) + } + } +} + +func checkResourceAttributes(t *testing.T, schemaName string, attributes map[string]resourceSchema.Attribute) { + for name, attr := range attributes { + if !strings.HasSuffix(reflect.TypeOf(attr).PkgPath(), "resource/schema") { + require.Fail(t, fmt.Sprintf("%s in %s must be from the resource schema", name, schemaName)) + } + } +} + +func typeName(i interface{}) string { + return fmt.Sprintf("%T", i) +} + +func datasourceTest(t *testing.T, schema EntitySchema) { + dataSourceSchema := schema.GetDatasourceSchema() + schemaName := typeName(schema) + + checkDatasourceAttributes(t, schemaName, dataSourceSchema.Attributes) + checkDatasourceBlocks(t, schemaName, dataSourceSchema.Blocks) +} + +func checkDatasourceAttributes(t *testing.T, schemaName string, attributes map[string]datasourceSchema.Attribute) { + for name, attr := range attributes { + switch attrType := attr.(type) { + case datasourceSchema.ListNestedAttribute: + checkDatasourceAttributes(t, schemaName, attrType.NestedObject.Attributes) + default: + if !strings.HasSuffix(reflect.TypeOf(attr).PkgPath(), "datasource/schema") { + require.Fail(t, fmt.Sprintf("%s in %s must be from the data source schema", name, schemaName)) + } + } + } +} + +func checkDatasourceBlocks(t *testing.T, schemaName string, blocks map[string]datasourceSchema.Block) { + for _, block := range blocks { + switch b := block.(type) { + case datasourceSchema.ListNestedBlock: + checkDatasourceAttributes(t, schemaName, b.NestedObject.Attributes) + checkDatasourceBlocks(t, schemaName, b.NestedObject.Blocks) + case datasourceSchema.SetNestedBlock: + checkDatasourceAttributes(t, schemaName, b.NestedObject.Attributes) + checkDatasourceBlocks(t, schemaName, b.NestedObject.Blocks) + case datasourceSchema.SingleNestedBlock: + checkDatasourceAttributes(t, schemaName, b.Attributes) + checkDatasourceBlocks(t, schemaName, b.Blocks) + } + } +} diff --git a/octopusdeploy_framework/schemas/script_modules.go b/octopusdeploy_framework/schemas/script_modules.go index f74ab893b..b381a9e38 100644 --- a/octopusdeploy_framework/schemas/script_modules.go +++ b/octopusdeploy_framework/schemas/script_modules.go @@ -1,7 +1,6 @@ package schemas import ( - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" @@ -13,6 +12,10 @@ import ( "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/variables" ) +type ScriptModuleSchema struct{} + +var _ EntitySchema = ScriptModuleSchema{} + type ScriptModuleResourceModel struct { Description types.String `tfsdk:"description"` Name types.String `tfsdk:"name"` @@ -33,17 +36,17 @@ type ScriptModuleDataSourceModel struct { ScriptModules types.List `tfsdk:"script_modules"` } -func GetDatasourceScriptModuleSchema() datasourceSchema.Schema { +func (s ScriptModuleSchema) GetDatasourceSchema() datasourceSchema.Schema { description := "script module" return datasourceSchema.Schema{ Description: "Provides information about existing script modules.", Attributes: map[string]datasourceSchema.Attribute{ "id": GetIdDatasourceSchema(true), "space_id": GetSpaceIdDatasourceSchema(description, false), - "ids": util.GetQueryIDsDatasourceSchema(), - "partial_name": util.GetQueryPartialNameDatasourceSchema(), - "skip": util.GetQuerySkipDatasourceSchema(), - "take": util.GetQueryTakeDatasourceSchema(), + "ids": GetQueryIDsDatasourceSchema(), + "partial_name": GetQueryPartialNameDatasourceSchema(), + "skip": GetQuerySkipDatasourceSchema(), + "take": GetQueryTakeDatasourceSchema(), "script_modules": datasourceSchema.ListNestedAttribute{ Computed: true, NestedObject: datasourceSchema.NestedAttributeObject{ @@ -126,48 +129,47 @@ func ScriptModuleObjectType() map[string]attr.Type { } } -func GetScriptModuleSchemaBlock() map[string]resourceSchema.Block { - return map[string]resourceSchema.Block{ - "script": resourceSchema.ListNestedBlock{ - Description: "The script associated with this script module.", - NestedObject: resourceSchema.NestedBlockObject{ - Attributes: map[string]resourceSchema.Attribute{ - "body": resourceSchema.StringAttribute{ - Description: "The body of this script module.", - Required: true, - }, - "syntax": resourceSchema.StringAttribute{ - Description: "The syntax of the script. Valid types are `Bash`, `CSharp`, `FSharp`, `PowerShell`, or `Python`.", - Required: true, - Validators: []validator.String{ - stringvalidator.OneOfCaseInsensitive( - "Bash", - "CSharp", - "FSharp", - "PowerShell", - "Python"), +func (s ScriptModuleSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Attributes: map[string]resourceSchema.Attribute{ + "description": GetDescriptionResourceSchema("script module"), + "id": GetIdResourceSchema(), + "name": GetNameResourceSchema(true), + "space_id": GetSpaceIdResourceSchema("Script Module"), + "variable_set_id": resourceSchema.StringAttribute{ + Computed: true, + Description: "The variable set ID for this script module.", + Optional: true, + }, + }, + Blocks: map[string]resourceSchema.Block{ + "script": resourceSchema.ListNestedBlock{ + Description: "The script associated with this script module.", + NestedObject: resourceSchema.NestedBlockObject{ + Attributes: map[string]resourceSchema.Attribute{ + "body": resourceSchema.StringAttribute{ + Description: "The body of this script module.", + Required: true, + }, + "syntax": resourceSchema.StringAttribute{ + Description: "The syntax of the script. Valid types are `Bash`, `CSharp`, `FSharp`, `PowerShell`, or `Python`.", + Required: true, + Validators: []validator.String{ + stringvalidator.OneOfCaseInsensitive( + "Bash", + "CSharp", + "FSharp", + "PowerShell", + "Python"), + }, }, }, }, + Validators: []validator.List{ + listvalidator.SizeAtMost(1), + listvalidator.SizeAtLeast(1), + }, }, - Validators: []validator.List{ - listvalidator.SizeAtMost(1), - listvalidator.SizeAtLeast(1), - }, - }, - } -} - -func GetScriptModuleResourceSchema() map[string]resourceSchema.Attribute { - return map[string]resourceSchema.Attribute{ - "description": GetDescriptionResourceSchema("script module"), - "id": GetIdResourceSchema(), - "name": GetNameResourceSchema(true), - "space_id": GetSpaceIdResourceSchema("Script Module"), - "variable_set_id": resourceSchema.StringAttribute{ - Computed: true, - Description: "The variable set ID for this script module.", - Optional: true, }, } } diff --git a/octopusdeploy_framework/schemas/space.go b/octopusdeploy_framework/schemas/space.go index 46342961a..18962bd90 100644 --- a/octopusdeploy_framework/schemas/space.go +++ b/octopusdeploy_framework/schemas/space.go @@ -13,6 +13,10 @@ import ( const spaceDescription = "space" +type SpaceSchema struct{} + +var _ EntitySchema = SpaceSchema{} + type SpaceModel struct { Name types.String `tfsdk:"name"` Slug types.String `tfsdk:"slug"` @@ -25,101 +29,74 @@ type SpaceModel struct { ResourceModel } -func GetSpaceResourceSchema() map[string]resourceSchema.Attribute { - return map[string]resourceSchema.Attribute{ - "id": GetIdResourceSchema(), - "description": GetDescriptionResourceSchema(spaceDescription), - "name": GetNameResourceSchema(true), - "slug": GetSlugResourceSchema(spaceDescription), - "space_managers_teams": resourceSchema.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": resourceSchema.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": resourceSchema.BoolAttribute{ - Description: "Specifies the status of the task queue for this space.", - Optional: true, - Computed: true, - Default: booldefault.StaticBool(false), - }, - "is_default": resourceSchema.BoolAttribute{ - Description: "Specifies if this space is the default space in Octopus.", - Optional: true, - Computed: true, - Default: booldefault.StaticBool(false), - }, - } -} - -func GetSpacesDatasourceSchema() map[string]datasourceSchema.Attribute { - return map[string]datasourceSchema.Attribute{ - "id": GetIdDatasourceSchema(true), - "description": GetReadonlyDescriptionDatasourceSchema(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), +func (s SpaceSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Description: "This resource manages spaces in Octopus Deploy.", + Attributes: map[string]resourceSchema.Attribute{ + "id": GetIdResourceSchema(), + "description": GetDescriptionResourceSchema(spaceDescription), + "name": GetNameResourceSchema(true), + "slug": GetSlugResourceSchema(spaceDescription), + "space_managers_teams": resourceSchema.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": resourceSchema.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": resourceSchema.BoolAttribute{ + Description: "Specifies the status of the task queue for this space.", + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), + }, + "is_default": resourceSchema.BoolAttribute{ + Description: "Specifies if this space is the default space in Octopus.", + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), }, - 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.", - Computed: true, - }, - "space_managers_team_members": datasourceSchema.SetAttribute{ - ElementType: types.StringType, - Description: "A list of user IDs designated to be managers of this space.", - Computed: true, - }, - "is_task_queue_stopped": datasourceSchema.BoolAttribute{ - Description: "Specifies the status of the task queue for this space.", - Computed: true, - }, - "is_default": datasourceSchema.BoolAttribute{ - Description: "Specifies if this space is the default space in Octopus.", - Computed: true, }, } } -func GetSpaceDatasourceSchema() map[string]datasourceSchema.Attribute { - return map[string]datasourceSchema.Attribute{ - "id": GetIdDatasourceSchema(true), - "description": GetReadonlyDescriptionDatasourceSchema(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), +func (s SpaceSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{ + Description: "Provides information about an existing space.", + Attributes: map[string]datasourceSchema.Attribute{ + "id": GetIdDatasourceSchema(true), + "description": GetReadonlyDescriptionDatasourceSchema(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.", + Computed: true, + }, + "space_managers_team_members": datasourceSchema.SetAttribute{ + ElementType: types.StringType, + Description: "A list of user IDs designated to be managers of this space.", + Computed: true, + }, + "is_task_queue_stopped": datasourceSchema.BoolAttribute{ + Description: "Specifies the status of the task queue for this space.", + Computed: true, + }, + "is_default": datasourceSchema.BoolAttribute{ + Description: "Specifies if this space is the default space in Octopus.", + Computed: true, }, - Required: 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.", - Computed: true, - }, - "space_managers_team_members": datasourceSchema.SetAttribute{ - ElementType: types.StringType, - Description: "A list of user IDs designated to be managers of this space.", - Computed: true, - }, - "is_task_queue_stopped": datasourceSchema.BoolAttribute{ - Description: "Specifies the status of the task queue for this space.", - Computed: true, - }, - "is_default": datasourceSchema.BoolAttribute{ - Description: "Specifies if this space is the default space in Octopus.", - Computed: true, }, } } diff --git a/octopusdeploy_framework/schemas/spaces.go b/octopusdeploy_framework/schemas/spaces.go new file mode 100644 index 000000000..29fa1ce5a --- /dev/null +++ b/octopusdeploy_framework/schemas/spaces.go @@ -0,0 +1,36 @@ +package schemas + +import ( + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" +) + +type SpacesSchema struct{} + +var _ EntitySchema = SpacesSchema{} + +func (s SpacesSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{} +} + +func (s SpacesSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{ + Attributes: map[string]datasourceSchema.Attribute{ + // request + "ids": GetQueryIDsDatasourceSchema(), + "partial_name": GetQueryPartialNameDatasourceSchema(), + "skip": GetQuerySkipDatasourceSchema(), + "take": GetQueryTakeDatasourceSchema(), + + // response + "id": GetIdDatasourceSchema(true), + "spaces": datasourceSchema.ListNestedAttribute{ + Computed: true, + Optional: false, + NestedObject: datasourceSchema.NestedAttributeObject{ + Attributes: SpaceSchema{}.GetDatasourceSchema().Attributes, + }, + }, + }, + } +} diff --git a/octopusdeploy_framework/schemas/tag.go b/octopusdeploy_framework/schemas/tag.go index 55e2fb42d..3e0d6d3e8 100644 --- a/octopusdeploy_framework/schemas/tag.go +++ b/octopusdeploy_framework/schemas/tag.go @@ -3,13 +3,22 @@ package schemas import ( "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/tagsets" "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" ) const TagResourceName = "tag" -func GetTagResourceSchema() resourceSchema.Schema { +type TagSchema struct{} + +var _ EntitySchema = TagSchema{} + +func (t TagSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{} +} + +func (t TagSchema) GetResourceSchema() resourceSchema.Schema { return resourceSchema.Schema{ Description: "This resource manages tags in Octopus Deploy.", Attributes: map[string]resourceSchema.Attribute{ diff --git a/octopusdeploy_framework/schemas/tag_set.go b/octopusdeploy_framework/schemas/tag_set.go index 017ebf9af..322eff22d 100644 --- a/octopusdeploy_framework/schemas/tag_set.go +++ b/octopusdeploy_framework/schemas/tag_set.go @@ -12,7 +12,11 @@ import ( const TagSetDataSourceName = "tag_sets" const TagSetResourceName = "tag_set" -func GetTagSetResourceSchema() resourceSchema.Schema { +type TagSetSchema struct{} + +var _ EntitySchema = TagSetSchema{} + +func (t TagSetSchema) GetResourceSchema() resourceSchema.Schema { return resourceSchema.Schema{ Description: "This resource manages tag sets in Octopus Deploy.", Attributes: map[string]resourceSchema.Attribute{ @@ -46,7 +50,7 @@ func GetTagSetResourceSchema() resourceSchema.Schema { } } -func GetTagSetDataSourceSchema() datasourceSchema.Schema { +func (t TagSetSchema) GetDatasourceSchema() datasourceSchema.Schema { return datasourceSchema.Schema{ Description: "Provides information about existing tag sets.", Attributes: map[string]datasourceSchema.Attribute{ diff --git a/octopusdeploy_framework/schemas/tenant.go b/octopusdeploy_framework/schemas/tenant.go index a63b1f3a1..ac33f10c1 100644 --- a/octopusdeploy_framework/schemas/tenant.go +++ b/octopusdeploy_framework/schemas/tenant.go @@ -2,7 +2,6 @@ package schemas import ( "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/tenants" - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "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" @@ -37,6 +36,10 @@ type TenantsModel struct { Take types.Int64 `tfsdk:"take"` } +type TenantSchema struct{} + +var _ EntitySchema = TenantSchema{} + func TenantObjectType() map[string]attr.Type { return map[string]attr.Type{ "cloned_from_tenant_id": types.StringType, @@ -65,78 +68,80 @@ func FlattenTenant(tenant *tenants.Tenant) attr.Value { }) } -func GetTenantsDataSourceSchema() map[string]datasourceSchema.Attribute { - return map[string]datasourceSchema.Attribute{ - "cloned_from_tenant_id": datasourceSchema.StringAttribute{ - Description: "A filter to search for a cloned tenant by its ID.", - Optional: true, - }, - "id": GetIdDatasourceSchema(true), - "ids": util.GetQueryIDsDatasourceSchema(), - "is_clone": datasourceSchema.BoolAttribute{ - Description: "A filter to search for cloned resources.", - Optional: true, - }, - "name": datasourceSchema.StringAttribute{ - Description: "A filter to search by name.", - Optional: true, - }, - "partial_name": util.GetQueryPartialNameDatasourceSchema(), - "project_id": datasourceSchema.StringAttribute{ - Description: "A filter to search by a project ID.", - Optional: true, - }, - "skip": util.GetQuerySkipDatasourceSchema(), - "tags": util.GetQueryDatasourceTags(), - "space_id": GetSpaceIdDatasourceSchema("tenants", false), - "take": util.GetQueryTakeDatasourceSchema(), - "tenants": datasourceSchema.ListNestedAttribute{ - Computed: true, - Optional: false, - NestedObject: datasourceSchema.NestedAttributeObject{ - Attributes: GetTenantDataSourceSchema(), +func (t TenantSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{ + Description: "Provides information about existing tenants.", + Attributes: map[string]datasourceSchema.Attribute{ + "cloned_from_tenant_id": datasourceSchema.StringAttribute{ + Description: "A filter to search for a cloned tenant by its ID.", + Optional: true, + }, + "id": GetIdDatasourceSchema(true), + "ids": GetQueryIDsDatasourceSchema(), + "is_clone": datasourceSchema.BoolAttribute{ + Description: "A filter to search for cloned resources.", + Optional: true, + }, + "name": datasourceSchema.StringAttribute{ + Description: "A filter to search by name.", + Optional: true, + }, + "partial_name": GetQueryPartialNameDatasourceSchema(), + "project_id": datasourceSchema.StringAttribute{ + Description: "A filter to search by a project ID.", + Optional: true, + }, + "skip": GetQuerySkipDatasourceSchema(), + "tags": GetQueryDatasourceTags(), + "space_id": GetSpaceIdDatasourceSchema("tenants", false), + "take": GetQueryTakeDatasourceSchema(), + "tenants": datasourceSchema.ListNestedAttribute{ + Computed: true, + Optional: false, + NestedObject: datasourceSchema.NestedAttributeObject{ + Attributes: map[string]datasourceSchema.Attribute{ + "cloned_from_tenant_id": datasourceSchema.StringAttribute{ + Description: "The ID of the tenant from which this tenant was cloned.", + Computed: true, + }, + "description": GetDescriptionDatasourceSchema("tenants"), + "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, + }, + }, + }, }, }, } } -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.", - Computed: true, - }, - "description": util.GetDescriptionDatasourceSchema("tenants"), - "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, - }, - } -} - -func GetTenantResourceSchema() map[string]resourceSchema.Attribute { - return map[string]resourceSchema.Attribute{ - "cloned_from_tenant_id": resourceSchema.StringAttribute{ - Description: "The ID of the tenant from which this tenant was cloned.", - Optional: true, - Computed: true, - Default: stringdefault.StaticString(""), - }, - "description": util.GetDescriptionResourceSchema("tenant"), - "id": util.GetIdResourceSchema(), - "name": util.GetNameResourceSchema(true), - "space_id": util.GetSpaceIdResourceSchema("tenant"), - "tenant_tags": resourceSchema.ListAttribute{ - Description: "A list of tenant tags associated with this resource.", - ElementType: types.StringType, - Optional: true, - Computed: true, - PlanModifiers: []planmodifier.List{ - listplanmodifier.UseStateForUnknown(), +func (t TenantSchema) GetResourceSchema() resourceSchema.Schema { + return resourceSchema.Schema{ + Description: "This resource manages tenants in Octopus Deploy.", + Attributes: map[string]resourceSchema.Attribute{ + "cloned_from_tenant_id": resourceSchema.StringAttribute{ + Description: "The ID of the tenant from which this tenant was cloned.", + Optional: true, + Computed: true, + Default: stringdefault.StaticString(""), + }, + "description": GetDescriptionResourceSchema("tenant"), + "id": GetIdResourceSchema(), + "name": GetNameResourceSchema(true), + "space_id": GetSpaceIdResourceSchema("tenant"), + "tenant_tags": resourceSchema.ListAttribute{ + Description: "A list of tenant tags associated with this resource.", + ElementType: types.StringType, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.List{ + listplanmodifier.UseStateForUnknown(), + }, }, }, } diff --git a/octopusdeploy_framework/schemas/tenant_common_variable.go b/octopusdeploy_framework/schemas/tenant_common_variable.go index 0795f0c2e..2c2eb542a 100644 --- a/octopusdeploy_framework/schemas/tenant_common_variable.go +++ b/octopusdeploy_framework/schemas/tenant_common_variable.go @@ -1,7 +1,6 @@ package schemas import ( - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-framework/resource/schema" ) @@ -14,11 +13,11 @@ func GetTenantCommonVariableResourceSchema() schema.Schema { return schema.Schema{ Description: "Manages a tenant common variable in Octopus Deploy.", Attributes: map[string]schema.Attribute{ - "id": util.GetIdResourceSchema(), - "space_id": util.GetSpaceIdResourceSchema(TenantCommonVariableResourceDescription), - "tenant_id": util.GetRequiredStringResourceSchema("The ID of the tenant."), - "library_variable_set_id": util.GetRequiredStringResourceSchema("The ID of the library variable set."), - "template_id": util.GetRequiredStringResourceSchema("The ID of the variable template."), + "id": GetIdResourceSchema(), + "space_id": GetSpaceIdResourceSchema(TenantCommonVariableResourceDescription), + "tenant_id": GetRequiredStringResourceSchema("The ID of the tenant."), + "library_variable_set_id": GetRequiredStringResourceSchema("The ID of the library variable set."), + "template_id": GetRequiredStringResourceSchema("The ID of the variable template."), "value": schema.StringAttribute{ Optional: true, Description: "The value of the variable.", diff --git a/octopusdeploy_framework/schemas/tenant_project_variable.go b/octopusdeploy_framework/schemas/tenant_project_variable.go index 4e681a99e..5ee72ce86 100644 --- a/octopusdeploy_framework/schemas/tenant_project_variable.go +++ b/octopusdeploy_framework/schemas/tenant_project_variable.go @@ -2,8 +2,10 @@ package schemas import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" ) const ( @@ -11,7 +13,46 @@ const ( TenantProjectVariableResourceName = "tenant_project_variable" ) -func GetTenantProjectVariableResourceSchema() schema.Schema { +type TenantProjectVariableSchema struct{} + +var _ EntitySchema = TenantProjectVariableSchema{} + +func (t TenantProjectVariableSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{ + Description: "Provides information about existing tenants.", + Attributes: map[string]datasourceSchema.Attribute{ + "tenant_ids": GetQueryIDsDatasourceSchema(), + "project_ids": GetQueryIDsDatasourceSchema(), + "environment_ids": GetQueryIDsDatasourceSchema(), + "space_id": GetSpaceIdDatasourceSchema("tenant projects", false), + "tenant_projects": datasourceSchema.ListNestedAttribute{ + Computed: true, + Optional: false, + Description: "A list of related tenants, projects and environments that match the filter(s).", + NestedObject: datasourceSchema.NestedAttributeObject{ + Attributes: map[string]datasourceSchema.Attribute{ + "id": GetIdDatasourceSchema(true), + "tenant_id": datasourceSchema.StringAttribute{ + Description: "The tenant ID associated with this tenant.", + Computed: true, + }, + "project_id": datasourceSchema.StringAttribute{ + Description: "The project ID associated with this tenant.", + Computed: true, + }, + "environment_ids": datasourceSchema.ListAttribute{ + Description: "The environment IDs associated with this tenant.", + ElementType: types.StringType, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (t TenantProjectVariableSchema) GetResourceSchema() schema.Schema { return schema.Schema{ Description: "Manages a tenant project variable in Octopus Deploy.", Attributes: map[string]schema.Attribute{ diff --git a/octopusdeploy_framework/schemas/tenant_projects.go b/octopusdeploy_framework/schemas/tenant_projects.go index f5410c9b0..c5f2effb6 100644 --- a/octopusdeploy_framework/schemas/tenant_projects.go +++ b/octopusdeploy_framework/schemas/tenant_projects.go @@ -3,7 +3,6 @@ package schemas import ( "fmt" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/tenants" - "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "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" @@ -29,7 +28,11 @@ type TenantProjectResourceModel struct { ResourceModel } -func GetTenantProjectsDataSourceSchema() datasourceSchema.Schema { +type TenantProjectsSchema struct{} + +var _ EntitySchema = TenantProjectsSchema{} + +func (t TenantProjectsSchema) GetDatasourceSchema() datasourceSchema.Schema { return datasourceSchema.Schema{ Description: "Provides information about existing tenants.", Attributes: map[string]datasourceSchema.Attribute{ @@ -64,10 +67,10 @@ func GetTenantProjectsDataSourceSchema() datasourceSchema.Schema { } } -func GetTenantProjectsResourceSchema() resourceSchema.Schema { +func (t TenantProjectsSchema) GetResourceSchema() resourceSchema.Schema { return resourceSchema.Schema{ Attributes: map[string]resourceSchema.Attribute{ - "id": util.GetIdResourceSchema(), + "id": GetIdResourceSchema(), "tenant_id": resourceSchema.StringAttribute{ Description: "The tenant ID associated with this tenant.", Required: true, diff --git a/octopusdeploy_framework/schemas/username_password_account.go b/octopusdeploy_framework/schemas/username_password_account.go index c5bff07fc..38b922f51 100644 --- a/octopusdeploy_framework/schemas/username_password_account.go +++ b/octopusdeploy_framework/schemas/username_password_account.go @@ -2,12 +2,21 @@ package schemas import ( "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" + datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" ) -func GetUsernamePasswordAccountResourceSchema() schema.Schema { +type UsernamePasswordAccountSchema struct{} + +var _ EntitySchema = UsernamePasswordAccountSchema{} + +func (u UsernamePasswordAccountSchema) GetDatasourceSchema() datasourceSchema.Schema { + return datasourceSchema.Schema{} +} + +func (u UsernamePasswordAccountSchema) GetResourceSchema() schema.Schema { return schema.Schema{ Description: "This resource manages username-password accounts in Octopus Deploy.", Attributes: map[string]schema.Attribute{ diff --git a/octopusdeploy_framework/schemas/variable.go b/octopusdeploy_framework/schemas/variable.go index 36d38366f..c41d6a8e0 100644 --- a/octopusdeploy_framework/schemas/variable.go +++ b/octopusdeploy_framework/schemas/variable.go @@ -91,7 +91,11 @@ var VariableTypes = []string{ VariableTypeNames.WorkerPool, } -func GetVariableDatasourceSchema() datasourceSchema.Schema { +type VariableSchema struct{} + +var _ EntitySchema = VariableSchema{} + +func (v VariableSchema) GetDatasourceSchema() datasourceSchema.Schema { return datasourceSchema.Schema{ Description: util.GetDataSourceDescription(VariablesDataSourceDescription), Attributes: map[string]datasourceSchema.Attribute{ @@ -104,7 +108,7 @@ func GetVariableDatasourceSchema() datasourceSchema.Schema { Required: true, Description: "Owner ID for the variable to find.", }, - SchemaAttributeNames.SpaceID: util.GetQuerySpaceIDDatasourceSchema(), + SchemaAttributeNames.SpaceID: GetSpaceIdDatasourceSchema(VariableResourceDescription, false), //response SchemaAttributeNames.ID: datasourceSchema.StringAttribute{ @@ -140,7 +144,7 @@ func GetVariableDatasourceSchema() datasourceSchema.Schema { } } -func GetVariableResourceSchema() resourceSchema.Schema { +func (v VariableSchema) GetResourceSchema() resourceSchema.Schema { return resourceSchema.Schema{ Description: util.GetResourceSchemaDescription(VariableResourceDescription), Attributes: map[string]resourceSchema.Attribute{ diff --git a/octopusdeploy_framework/schemas/variable_prompt_options.go b/octopusdeploy_framework/schemas/variable_prompt_options.go index d25ecc30b..4f64c61c7 100644 --- a/octopusdeploy_framework/schemas/variable_prompt_options.go +++ b/octopusdeploy_framework/schemas/variable_prompt_options.go @@ -197,7 +197,7 @@ func getVariablePromptDatasourceSchema() datasourceSchema.ListNestedAttribute { Computed: true, NestedObject: datasourceSchema.NestedAttributeObject{ Attributes: map[string]datasourceSchema.Attribute{ - SchemaAttributeNames.Description: util.GetDescriptionDatasourceSchema("variable prompt option"), + SchemaAttributeNames.Description: GetDescriptionDatasourceSchema("variable prompt option"), VariableSchemaAttributeNames.DisplaySettings: getDisplaySettingsDatasourceSchema(), VariableSchemaAttributeNames.IsRequired: datasourceSchema.BoolAttribute{ Computed: true, @@ -255,7 +255,7 @@ func getVariablePromptResourceSchema() resourceSchema.ListNestedBlock { return resourceSchema.ListNestedBlock{ NestedObject: resourceSchema.NestedBlockObject{ Attributes: map[string]resourceSchema.Attribute{ - SchemaAttributeNames.Description: util.GetDescriptionResourceSchema("variable prompt option"), + SchemaAttributeNames.Description: GetDescriptionResourceSchema("variable prompt option"), VariableSchemaAttributeNames.IsRequired: resourceSchema.BoolAttribute{ Optional: true, }, diff --git a/octopusdeploy_framework/util/schema.go b/octopusdeploy_framework/util/schema.go deleted file mode 100644 index 26856a9da..000000000 --- a/octopusdeploy_framework/util/schema.go +++ /dev/null @@ -1,312 +0,0 @@ -package util - -import ( - "fmt" - - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" - - 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/int64default" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" - - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -func GetQueryIDsDatasourceSchema() datasourceSchema.Attribute { - return datasourceSchema.ListAttribute{ - Description: "A filter to search by a list of IDs.", - ElementType: types.StringType, - Optional: true, - } -} - -func GetQuerySpaceIDDatasourceSchema() datasourceSchema.Attribute { - return datasourceSchema.StringAttribute{ - Description: "A Space ID to filter by. Will revert what is specified on the provider if not set.", - Optional: true, - } -} - -func GetQueryNameDatasourceSchema() datasourceSchema.Attribute { - return datasourceSchema.StringAttribute{ - Description: "A filter search by exact name", - Optional: true, - } -} - -func GetQueryPartialNameDatasourceSchema() datasourceSchema.Attribute { - return datasourceSchema.StringAttribute{ - Description: "A filter to search by a partial name.", - Optional: true, - } -} - -func GetQuerySkipDatasourceSchema() datasourceSchema.Attribute { - return datasourceSchema.Int64Attribute{ - Description: "A filter to specify the number of items to skip in the response.", - Optional: true, - } -} - -func GetQueryTakeDatasourceSchema() datasourceSchema.Attribute { - return datasourceSchema.Int64Attribute{ - Description: "A filter to specify the number of items to take (or return) in the response.", - 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), - Validators: []validator.String{ - stringvalidator.LengthBetween(1, maxLength), - }, - } - - if isRequired { - s.Required = true - } else { - s.Optional = true - } - - return s -} - -func GetNameDatasourceSchema(isRequired bool) datasourceSchema.Attribute { - s := datasourceSchema.StringAttribute{ - Description: "The name of this resource.", - Validators: []validator.String{ - stringvalidator.LengthAtLeast(1), - }, - } - - if isRequired { - s.Required = true - } else { - s.Optional = true - } - - return s -} - -func GetDescriptionDatasourceSchema(resourceDescription string) datasourceSchema.Attribute { - return datasourceSchema.StringAttribute{ - Description: "The description of this " + resourceDescription + ".", - Computed: true, - } -} - -func GetQueryDatasourceTags() datasourceSchema.Attribute { - return datasourceSchema.ListAttribute{ - Description: "A filter to search by a list of tags.", - ElementType: types.StringType, - Optional: true, - } -} - -func GetIdResourceSchema() resourceSchema.Attribute { - return resourceSchema.StringAttribute{ - Description: "The unique ID for this resource.", - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - } -} - -func GetSpaceIdResourceSchema(resourceDescription string) resourceSchema.Attribute { - return resourceSchema.StringAttribute{ - Description: "The space ID associated with this " + resourceDescription + ".", - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - } -} - -func GetNameResourceSchema(isRequired bool) resourceSchema.Attribute { - s := resourceSchema.StringAttribute{ - Description: "The name of this resource.", - Validators: []validator.String{ - stringvalidator.LengthAtLeast(1), - }, - } - - if isRequired { - s.Required = true - } else { - s.Optional = true - } - - return s -} - -func GetDescriptionResourceSchema(resourceDescription string) resourceSchema.Attribute { - return resourceSchema.StringAttribute{ - Description: "The description of this " + resourceDescription + ".", - Optional: true, - Computed: true, - Default: stringdefault.StaticString(""), - } -} - -func GetSlugDatasourceSchema(resourceDescription string, isReadOnly bool) datasourceSchema.Attribute { - s := datasourceSchema.StringAttribute{ - Description: fmt.Sprintf("The unique slug of this %s", resourceDescription), - } - - if isReadOnly { - s.Computed = true - } else { - s.Optional = true - s.Computed = true - } - - return s -} - -func GetSlugResourceSchema(resourceDescription string) resourceSchema.Attribute { - return resourceSchema.StringAttribute{ - Description: fmt.Sprintf("The unique slug of this %s", resourceDescription), - Computed: true, - } -} - -func GetSortOrderDataSourceSchema(resourceDescription string) resourceSchema.Attribute { - return resourceSchema.Int64Attribute{ - Description: fmt.Sprintf("The order number to sort an %s", resourceDescription), - Computed: true, - } -} - -func GetSortOrderResourceSchema(resourceDescription string) resourceSchema.Attribute { - return resourceSchema.Int64Attribute{ - Description: fmt.Sprintf("The order number to sort an %s.", resourceDescription), - Optional: true, - Computed: true, - } -} - -func GetPasswordResourceSchema(isRequired bool) resourceSchema.Attribute { - s := resourceSchema.StringAttribute{ - Description: "The password associated with this resource.", - Sensitive: true, - Validators: []validator.String{ - stringvalidator.LengthAtLeast(1), - }, - } - - if isRequired { - s.Required = true - } else { - s.Optional = true - } - - return s -} - -func GetPasswordDataSourceSchema(isRequired bool) datasourceSchema.Attribute { - s := datasourceSchema.StringAttribute{ - Description: "The password associated with this resource.", - Sensitive: true, - Validators: []validator.String{ - stringvalidator.LengthAtLeast(1), - }, - } - - if isRequired { - s.Required = true - } else { - s.Optional = true - } - - return s -} - -func GetUsernameResourceSchema(isRequired bool) resourceSchema.Attribute { - s := &resourceSchema.StringAttribute{ - Description: "The username associated with this resource.", - Sensitive: true, - Validators: []validator.String{ - stringvalidator.LengthAtLeast(1), - }, - } - - if isRequired { - s.Required = true - } else { - s.Optional = true - } - - return s -} - -func GetRequiredStringResourceSchema(description string) resourceSchema.StringAttribute { - return resourceSchema.StringAttribute{ - Required: true, - Description: description, - Validators: []validator.String{ - stringvalidator.LengthAtLeast(1), - }, - } -} -func GetIds(ids types.List) []string { - var result = make([]string, 0, len(ids.Elements())) - for _, id := range ids.Elements() { - if str, ok := id.(types.String); ok { - result = append(result, str.ValueString()) - } - } - return result -} - -func GetNumber(val types.Int64) int { - v := 0 - if !val.IsNull() { - v = int(val.ValueInt64()) - } - - return v -} - -func GetDownloadAttemptsResourceSchema() resourceSchema.Attribute { - return resourceSchema.Int64Attribute{ - Default: int64default.StaticInt64(5), - Description: "The number of times a deployment should attempt to download a package from this feed before failing.", - Optional: true, - Computed: true, - } -} - -func GetDownloadRetryBackoffSecondsResourceSchema() resourceSchema.Attribute { - return resourceSchema.Int64Attribute{ - Default: int64default.StaticInt64(10), - Description: "The number of seconds to apply as a linear back off between download attempts.", - Optional: true, - Computed: true, - } -} - -func GetPackageAcquisitionLocationOptionsResourceSchema() resourceSchema.Attribute { - return resourceSchema.ListAttribute{ - Computed: true, - ElementType: types.StringType, - Optional: true, - PlanModifiers: []planmodifier.List{ - listplanmodifier.UseStateForUnknown(), - }, - } -} - -func GetFeedUriResourceSchema() resourceSchema.Attribute { - return resourceSchema.StringAttribute{ - Required: true, - } -} diff --git a/octopusdeploy_framework/util/util.go b/octopusdeploy_framework/util/util.go index e0c87bdea..42ae11dd1 100644 --- a/octopusdeploy_framework/util/util.go +++ b/octopusdeploy_framework/util/util.go @@ -100,3 +100,25 @@ func Map[T, V any](items []T, fn func(T) V) []V { } return result } + +func GetIds(ids types.List) []string { + var result = make([]string, 0, len(ids.Elements())) + for _, id := range ids.Elements() { + strVal, ok := id.(types.String) + + if !ok || strVal.IsNull() || strVal.IsUnknown() { + continue + } + result = append(result, strVal.ValueString()) + } + return result +} + +func GetNumber(val types.Int64) int { + v := 0 + if !val.IsNull() { + v = int(val.ValueInt64()) + } + + return v +}