From eaf4994b526834dad77ddf3ed6da875cdc92ae59 Mon Sep 17 00:00:00 2001 From: Grace Rehn Date: Wed, 20 Nov 2024 11:30:41 +1000 Subject: [PATCH] feat: Add ability to disable tenants --- docs/data-sources/tenants.md | 2 ++ docs/resources/tenant.md | 1 + go.mod | 2 +- go.sum | 4 +-- octopusdeploy_framework/datasource_tenants.go | 1 + octopusdeploy_framework/resource_tenant.go | 2 ++ octopusdeploy_framework/schemas/tenant.go | 25 ++++++++++++++++--- 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/docs/data-sources/tenants.md b/docs/data-sources/tenants.md index c95b3b896..0149bdd7c 100644 --- a/docs/data-sources/tenants.md +++ b/docs/data-sources/tenants.md @@ -20,6 +20,7 @@ Provides information about existing tenants. - `cloned_from_tenant_id` (String) A filter to search for a cloned tenant by its ID. - `ids` (List of String) A filter to search by a list of IDs. - `is_clone` (Boolean) A filter to search for cloned resources. +- `is_disabled` (Boolean) A filter to search by the disabled status of a resource. - `name` (String) A filter to search by name. - `partial_name` (String) A filter to search by a partial name. - `project_id` (String) A filter to search by a project ID. @@ -41,6 +42,7 @@ Read-Only: - `cloned_from_tenant_id` (String) The ID of the tenant from which this tenant was cloned. - `description` (String) The description of this tenants. - `id` (String) The unique ID for this resource. +- `is_disabled` (Boolean) the disabled status of this tenant. - `name` (String) The name of this resource. - `space_id` (String) The space ID associated with this tenant. - `tenant_tags` (Set of String) A list of tenant tags associated with this resource. diff --git a/docs/resources/tenant.md b/docs/resources/tenant.md index 02fb8feb7..733859606 100644 --- a/docs/resources/tenant.md +++ b/docs/resources/tenant.md @@ -20,6 +20,7 @@ This resource manages tenants in Octopus Deploy. - `cloned_from_tenant_id` (String) The ID of the tenant from which this tenant was cloned. - `description` (String) The description of this tenant. +- `is_disabled` (Boolean) The disabled status of this tenant. - `space_id` (String) The space ID associated with this tenant. - `tenant_tags` (Set of String) A list of tenant tags associated with this resource. diff --git a/go.mod b/go.mod index 8dcc68c27..ff7823dbe 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy go 1.21 require ( - github.com/OctopusDeploy/go-octopusdeploy/v2 v2.55.0 + github.com/OctopusDeploy/go-octopusdeploy/v2 v2.58.0 github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240729041805-46db6fb717b4 github.com/google/uuid v1.6.0 github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637 diff --git a/go.sum b/go.sum index 7a39471c6..b82d84bb9 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,8 @@ github.com/Microsoft/hcsshim v0.12.4 h1:Ev7YUMHAHoWNm+aDSPzc5W9s6E2jyL1szpVDJeZ/ github.com/Microsoft/hcsshim v0.12.4/go.mod h1:Iyl1WVpZzr+UkzjekHZbV8o5Z9ZkxNGx6CtY2Qg/JVQ= github.com/OctopusDeploy/go-octodiff v1.0.0 h1:U+ORg6azniwwYo+O44giOw6TiD5USk8S4VDhOQ0Ven0= github.com/OctopusDeploy/go-octodiff v1.0.0/go.mod h1:Mze0+EkOWTgTmi8++fyUc6r0aLZT7qD9gX+31t8MmIU= -github.com/OctopusDeploy/go-octopusdeploy/v2 v2.55.0 h1:kX6qRRy8AgbqTiYdenqVNe69pGhntwJGEgJx9rtn9/8= -github.com/OctopusDeploy/go-octopusdeploy/v2 v2.55.0/go.mod h1:ggvOXzMnq+w0pLg6C9zdjz6YBaHfO3B3tqmmB7JQdaw= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.58.0 h1:vWw3dS4bEghzXnnGzoDD3Wm434MqNIwD2g73XeJebW0= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.58.0/go.mod h1:ggvOXzMnq+w0pLg6C9zdjz6YBaHfO3B3tqmmB7JQdaw= github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240729041805-46db6fb717b4 h1:QfbVf0bOIRMp/WHAWsuVDB7KHoWnRsGbvDuOf2ua7k4= github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240729041805-46db6fb717b4/go.mod h1:Oq9KbiRNDBB5jFmrwnrgLX0urIqR/1ptY18TzkqXm7M= github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg= diff --git a/octopusdeploy_framework/datasource_tenants.go b/octopusdeploy_framework/datasource_tenants.go index d7bcf71da..ec8cf6e1f 100644 --- a/octopusdeploy_framework/datasource_tenants.go +++ b/octopusdeploy_framework/datasource_tenants.go @@ -42,6 +42,7 @@ func (b *tenantsDataSource) Read(ctx context.Context, req datasource.ReadRequest ClonedFromTenantID: data.ClonedFromTenantId.ValueString(), IDs: util.ExpandStringList(data.IDs), IsClone: data.IsClone.ValueBool(), + IsDisabled: data.IsDisabled.ValueBool(), Name: data.Name.ValueString(), PartialName: data.PartialName.ValueString(), ProjectID: data.ProjectId.ValueString(), diff --git a/octopusdeploy_framework/resource_tenant.go b/octopusdeploy_framework/resource_tenant.go index 3fa5c5103..73bfc5c42 100644 --- a/octopusdeploy_framework/resource_tenant.go +++ b/octopusdeploy_framework/resource_tenant.go @@ -151,6 +151,7 @@ func mapStateToTenant(ctx context.Context, data *schemas.TenantModel) (*tenants. tenant.ID = data.ID.ValueString() tenant.ClonedFromTenantID = data.ClonedFromTenantId.ValueString() tenant.Description = data.Description.ValueString() + tenant.IsDisabled = data.IsDisabled.ValueBool() tenant.SpaceID = data.SpaceID.ValueString() convertedTenantTags, diags := util.SetToStringArray(ctx, data.TenantTags) @@ -167,6 +168,7 @@ func mapTenantToState(ctx context.Context, data *schemas.TenantModel, tenant *te data.ID = types.StringValue(tenant.ID) data.ClonedFromTenantId = types.StringValue(tenant.ClonedFromTenantID) data.Description = types.StringValue(tenant.Description) + data.IsDisabled = types.BoolValue(tenant.IsDisabled) data.SpaceID = types.StringValue(tenant.SpaceID) data.Name = types.StringValue(tenant.Name) diff --git a/octopusdeploy_framework/schemas/tenant.go b/octopusdeploy_framework/schemas/tenant.go index 5b0c9f695..ad34cc5a1 100644 --- a/octopusdeploy_framework/schemas/tenant.go +++ b/octopusdeploy_framework/schemas/tenant.go @@ -14,6 +14,7 @@ import ( type TenantModel struct { ClonedFromTenantId types.String `tfsdk:"cloned_from_tenant_id"` Description types.String `tfsdk:"description"` + IsDisabled types.Bool `tfsdk:"is_disabled"` Name types.String `tfsdk:"name"` SpaceID types.String `tfsdk:"space_id"` TenantTags types.Set `tfsdk:"tenant_tags"` @@ -26,6 +27,7 @@ type TenantsModel struct { ID types.String `tfsdk:"id"` IDs types.List `tfsdk:"ids"` IsClone types.Bool `tfsdk:"is_clone"` + IsDisabled types.Bool `tfsdk:"is_disabled"` Name types.String `tfsdk:"name"` PartialName types.String `tfsdk:"partial_name"` ProjectId types.String `tfsdk:"project_id"` @@ -45,6 +47,7 @@ func TenantObjectType() map[string]attr.Type { "cloned_from_tenant_id": types.StringType, "description": types.StringType, "id": types.StringType, + "is_disabled": types.BoolType, "name": types.StringType, "space_id": types.StringType, "tenant_tags": types.SetType{ElemType: types.StringType}, @@ -62,6 +65,7 @@ func FlattenTenant(tenant *tenants.Tenant) attr.Value { "cloned_from_tenant_id": types.StringValue(tenant.ClonedFromTenantID), "description": types.StringValue(tenant.Description), "id": types.StringValue(tenant.GetID()), + "is_disabled": types.BoolValue(tenant.IsDisabled), "name": types.StringValue(tenant.Name), "space_id": types.StringValue(tenant.SpaceID), "tenant_tags": tenantTagsSet, @@ -82,6 +86,10 @@ func (t TenantSchema) GetDatasourceSchema() datasourceSchema.Schema { Description: "A filter to search for cloned resources.", Optional: true, }, + "is_disabled": datasourceSchema.BoolAttribute{ + Description: "A filter to search by the disabled status of a resource.", + Optional: true, + }, "name": datasourceSchema.StringAttribute{ Description: "A filter to search by name.", Optional: true, @@ -106,8 +114,12 @@ func (t TenantSchema) GetDatasourceSchema() datasourceSchema.Schema { }, "description": GetDescriptionDatasourceSchema("tenants"), "id": GetIdDatasourceSchema(true), - "name": GetReadonlyNameDatasourceSchema(), - "space_id": GetSpaceIdDatasourceSchema("tenant", true), + "is_disabled": datasourceSchema.BoolAttribute{ + Description: "Specifies whether or not the tenant is disabled.", + Computed: true, + }, + "name": GetReadonlyNameDatasourceSchema(), + "space_id": GetSpaceIdDatasourceSchema("tenant", true), "tenant_tags": datasourceSchema.SetAttribute{ Computed: true, Description: "A list of tenant tags associated with this resource.", @@ -132,8 +144,13 @@ func (t TenantSchema) GetResourceSchema() resourceSchema.Schema { }, "description": GetDescriptionResourceSchema("tenant"), "id": GetIdResourceSchema(), - "name": GetNameResourceSchema(true), - "space_id": GetSpaceIdResourceSchema("tenant"), + "is_disabled": datasourceSchema.BoolAttribute{ + Description: "Specifies whether or not the tenant is disabled.", + Optional: true, + Computed: true, + }, + "name": GetNameResourceSchema(true), + "space_id": GetSpaceIdResourceSchema("tenant"), "tenant_tags": resourceSchema.SetAttribute{ Description: "A list of tenant tags associated with this resource.", ElementType: types.StringType,