Skip to content

Commit 03e5e57

Browse files
Make dedicated data sources for each retention type
1 parent 32b429a commit 03e5e57

14 files changed

+336
-204
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "octopusdeploy_space_default_lifecycle_release_retention_policy Data Source - terraform-provider-octopusdeploy"
4+
subcategory: ""
5+
description: |-
6+
Manages a space's default retention policy for how releases are retained.
7+
---
8+
9+
# octopusdeploy_space_default_lifecycle_release_retention_policy (Data Source)
10+
11+
Manages a space's default retention policy for how releases are retained.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `space_id` (String) The ID of the space.
21+
22+
### Read-Only
23+
24+
- `id` (String) The ID of the retention policy.
25+
- `quantity_to_keep` (Number) The number of days/releases to keep.
26+
- `strategy` (String) How retention will be set. Valid strategies are `Forever`, and `Count`.
27+
- `strategy = "Forever"`, is used if releases should never be deleted.
28+
- `strategy = "Count"`, is used if a specific number of days/releases should be kept.
29+
- `unit` (String) The unit of quantity to keep. Valid Units are `Days` or `Items`
30+
31+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "octopusdeploy_space_default_lifecycle_tentacle_retention_policy Data Source - terraform-provider-octopusdeploy"
4+
subcategory: ""
5+
description: |-
6+
Manages a space's default retention policy for how files on tentacles are retained.
7+
---
8+
9+
# octopusdeploy_space_default_lifecycle_tentacle_retention_policy (Data Source)
10+
11+
Manages a space's default retention policy for how files on tentacles are retained.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `space_id` (String) The ID of the space.
21+
22+
### Read-Only
23+
24+
- `id` (String) The ID of the retention policy.
25+
- `quantity_to_keep` (Number) The number of days/releases to keep files on tentacles.
26+
- `strategy` (String) How retention will be set. Valid strategies are `Forever`, and `Count`.
27+
- `strategy = "Forever"`, is used if files on tentacles should never be deleted.
28+
- `strategy = "Count"`, is used if a specific number of days/releases files on tentacles should be kept for.
29+
- `unit` (String) The unit of quantity to keep. Valid Units are `Days` or `Items`
30+
31+

docs/data-sources/space_default_retention_policy.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

docs/resources/space_default_lifecycle_release_retention_policy.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
page_title: "octopusdeploy_space_default_lifecycle_release_retention_policy Resource - terraform-provider-octopusdeploy"
44
subcategory: ""
55
description: |-
6-
Manages a space's default lifecycle release retention policy.
6+
Manages a space's default retention policy for how releases are retained.
77
---
88

99
# octopusdeploy_space_default_lifecycle_release_retention_policy (Resource)
1010

11-
Manages a space's default lifecycle release retention policy.
11+
Manages a space's default retention policy for how releases are retained.
1212

1313

1414

@@ -17,13 +17,15 @@ Manages a space's default lifecycle release retention policy.
1717

1818
### Required
1919

20-
- `strategy` (String) The strategy for the retention policy.
20+
- `space_id` (String) The ID of the space.
21+
- `strategy` (String) How retention will be set. Valid strategies are `Forever`, and `Count`.
22+
- `strategy = "Forever"`, is used if releases should never be deleted.
23+
- `strategy = "Count"`, is used if a specific number of days/releases should be kept.
2124

2225
### Optional
2326

24-
- `quantity_to_keep` (Number) The quantity of items to keep.
25-
- `space_id` (String) The space ID associated with this space default retention policy.
26-
- `unit` (String) The unit of time for the retention policy.
27+
- `quantity_to_keep` (Number) The number of days/releases to keep.
28+
- `unit` (String) The unit of quantity to keep. Valid Units are `Days` or `Items`.
2729

2830
### Read-Only
2931

docs/resources/space_default_lifecycle_tentacle_retention_policy.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
page_title: "octopusdeploy_space_default_lifecycle_tentacle_retention_policy Resource - terraform-provider-octopusdeploy"
44
subcategory: ""
55
description: |-
6-
Manages a space's default lifecycle tentacle retention policy.
6+
Manages a space's default retention policy for how files on tentacles are retained.
77
---
88

99
# octopusdeploy_space_default_lifecycle_tentacle_retention_policy (Resource)
1010

11-
Manages a space's default lifecycle tentacle retention policy.
11+
Manages a space's default retention policy for how files on tentacles are retained.
1212

1313

1414

@@ -17,13 +17,15 @@ Manages a space's default lifecycle tentacle retention policy.
1717

1818
### Required
1919

20-
- `strategy` (String) The strategy for the retention policy.
20+
- `space_id` (String) The ID of the space.
21+
- `strategy` (String) How retention will be set. Valid strategies are `Forever`, and `Count`.
22+
- `strategy = "Forever"`, is used if files on tentacles should never be deleted.
23+
- `strategy = "Count"`, is used if a specific number of days/releases files on tentacles should be kept for.
2124

2225
### Optional
2326

24-
- `quantity_to_keep` (Number) The quantity of items to keep.
25-
- `space_id` (String) The space ID associated with this space default retention policy.
26-
- `unit` (String) The unit of time for the retention policy.
27+
- `quantity_to_keep` (Number) The number of days/releases to keep files on tentacles.
28+
- `unit` (String) The unit of quantity to keep. Valid Units are `Days` or `Items`.
2729

2830
### Read-Only
2931

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package octopusdeploy_framework
2+
3+
import (
4+
"context"
5+
6+
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/retention"
7+
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
8+
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
9+
"github.com/hashicorp/terraform-plugin-framework/datasource"
10+
"github.com/hashicorp/terraform-plugin-framework/types"
11+
)
12+
13+
type spaceDefaultLifecycleReleaseRetentionPoliciesDataSource struct {
14+
*Config
15+
}
16+
17+
func NewSpaceDefaultLifecycleReleaseRetentionPoliciesDataSource() datasource.DataSource {
18+
return &spaceDefaultLifecycleReleaseRetentionPoliciesDataSource{}
19+
}
20+
21+
// Metadata implements datasource.DataSource.
22+
func (s *spaceDefaultLifecycleReleaseRetentionPoliciesDataSource) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) {
23+
resp.TypeName = util.GetTypeName("space_default_lifecycle_release_retention_policy")
24+
}
25+
26+
func (s *spaceDefaultLifecycleReleaseRetentionPoliciesDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
27+
s.Config = DataSourceConfiguration(req, resp)
28+
}
29+
30+
// Read implements datasource.DataSource.
31+
func (s *spaceDefaultLifecycleReleaseRetentionPoliciesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
32+
var data schemas.SpaceDefaultLifecycleReleaseRetentionPoliciesDataSourceModel
33+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
34+
if resp.Diagnostics.HasError() {
35+
return
36+
}
37+
38+
query := retention.SpaceDefaultRetentionPolicyQuery{
39+
SpaceID: data.SpaceID.ValueString(),
40+
RetentionType: retention.LifecycleReleaseRetentionType,
41+
}
42+
43+
util.DatasourceReading(ctx, "space_default_lifecycle_release_retention_policy", query)
44+
existingPolicy, err := retention.Get(s.Client, query)
45+
if err != nil {
46+
resp.Diagnostics.AddError("unable to load space default lifecycle release retention policies", err.Error())
47+
return
48+
}
49+
50+
updateLifecycleReleasePolicyDatasourceModelFromResource(&data, existingPolicy)
51+
resp.Diagnostics.Append(resp.State.Set(ctx, data)...)
52+
}
53+
54+
// Schema implements datasource.DataSource.
55+
func (s *spaceDefaultLifecycleReleaseRetentionPoliciesDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
56+
resp.Schema = schemas.SpaceDefaultLifecycleReleaseRetentionPolicySchema{}.GetDatasourceSchema()
57+
}
58+
59+
func updateLifecycleReleasePolicyDatasourceModelFromResource(data *schemas.SpaceDefaultLifecycleReleaseRetentionPoliciesDataSourceModel, resource *retention.SpaceDefaultRetentionPolicyResource) {
60+
data.ID = types.StringValue(resource.GetID())
61+
data.Strategy = types.StringValue(resource.Strategy)
62+
data.QuantityToKeep = util.Ternary(resource.QuantityToKeep == 0, types.Int64Null(), types.Int64Value(int64(resource.QuantityToKeep)))
63+
data.Unit = util.Ternary(resource.Unit == "", types.StringNull(), types.StringValue(resource.Unit))
64+
}

octopusdeploy_framework/datasource_space_default_retention_policies_test.go renamed to octopusdeploy_framework/datasource_space_default_lifecycle_release_retention_policies_test.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,27 @@ import (
99
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1010
)
1111

12-
func TestAccDataSourceSpaceDefaultRetentionPolicy(t *testing.T) {
12+
func TestAccDataSourceSpaceDefaultLifecycleReleaseRetentionPolicy(t *testing.T) {
1313
spaceName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
14-
retentionType := "LifecycleRelease"
15-
resourceName := "data.octopusdeploy_space_default_retention_policy.space_default_retention_policy_test"
14+
resourceName := "data.octopusdeploy_space_default_lifecycle_release_retention_policy.policy_test"
1615

1716
resource.Test(t, resource.TestCase{
1817
PreCheck: func() { TestAccPreCheck(t) },
1918
ProtoV6ProviderFactories: ProtoV6ProviderFactories(),
2019
Steps: []resource.TestStep{
2120
{
22-
Config: testAccDataSourceSpaceDefaultRetentionPolicyConfig(spaceName, retentionType),
21+
Config: testAccDataSourceSpaceDefaultLifecycleReleaseRetentionPolicyConfig(spaceName),
2322
Check: resource.ComposeTestCheckFunc(
2423
resource.TestCheckResourceAttrSet(resourceName, "id"),
2524
resource.TestCheckResourceAttrSet(resourceName, "space_id"),
26-
resource.TestCheckResourceAttr(resourceName, "retention_type", retentionType),
2725
resource.TestCheckResourceAttrSet(resourceName, "strategy"),
2826
),
2927
},
3028
},
3129
})
3230
}
3331

34-
func testAccDataSourceSpaceDefaultRetentionPolicyConfig(spaceName, retention_type string) string {
32+
func testAccDataSourceSpaceDefaultLifecycleReleaseRetentionPolicyConfig(spaceName string) string {
3533
return fmt.Sprintf(`
3634
resource "octopusdeploy_space" "octopus_project_space_test" {
3735
name = "%s"
@@ -41,9 +39,8 @@ resource "octopusdeploy_space" "octopus_project_space_test" {
4139
space_managers_teams = ["teams-administrators"]
4240
}
4341
44-
data "octopusdeploy_space_default_retention_policy" "space_default_retention_policy_test" {
42+
data "octopusdeploy_space_default_lifecycle_release_retention_policy" "policy_test" {
4543
space_id = octopusdeploy_space.octopus_project_space_test.id
46-
retention_type = "%s"
4744
}
48-
`, spaceName, retention_type)
45+
`, spaceName)
4946
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package octopusdeploy_framework
2+
3+
import (
4+
"context"
5+
6+
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/retention"
7+
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
8+
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
9+
"github.com/hashicorp/terraform-plugin-framework/datasource"
10+
"github.com/hashicorp/terraform-plugin-framework/types"
11+
)
12+
13+
type spaceDefaultLifecycleTentacleRetentionPoliciesDataSource struct {
14+
*Config
15+
}
16+
17+
func NewSpaceDefaultLifecycleTentacleRetentionPoliciesDataSource() datasource.DataSource {
18+
return &spaceDefaultLifecycleTentacleRetentionPoliciesDataSource{}
19+
}
20+
21+
// Metadata implements datasource.DataSource.
22+
func (s *spaceDefaultLifecycleTentacleRetentionPoliciesDataSource) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) {
23+
resp.TypeName = util.GetTypeName("space_default_lifecycle_tentacle_retention_policy")
24+
}
25+
26+
func (s *spaceDefaultLifecycleTentacleRetentionPoliciesDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
27+
s.Config = DataSourceConfiguration(req, resp)
28+
}
29+
30+
// Read implements datasource.DataSource.
31+
func (s *spaceDefaultLifecycleTentacleRetentionPoliciesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
32+
var data schemas.SpaceDefaultLifecycleTentacleRetentionPoliciesDataSourceModel
33+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
34+
if resp.Diagnostics.HasError() {
35+
return
36+
}
37+
38+
query := retention.SpaceDefaultRetentionPolicyQuery{
39+
SpaceID: data.SpaceID.ValueString(),
40+
RetentionType: retention.LifecycleTentacleRetentionType,
41+
}
42+
43+
util.DatasourceReading(ctx, "space_default_lifecycle_tentacle_retention_policy", query)
44+
existingPolicy, err := retention.Get(s.Client, query)
45+
if err != nil {
46+
resp.Diagnostics.AddError("unable to load space default lifecycle tentacle retention policies", err.Error())
47+
return
48+
}
49+
50+
updateLifecycleTentaclePolicyDatasourceModelFromResource(&data, existingPolicy)
51+
resp.Diagnostics.Append(resp.State.Set(ctx, data)...)
52+
}
53+
54+
// Schema implements datasource.DataSource.
55+
func (s *spaceDefaultLifecycleTentacleRetentionPoliciesDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
56+
resp.Schema = schemas.SpaceDefaultLifecycleTentacleRetentionPolicySchema{}.GetDatasourceSchema()
57+
}
58+
59+
func updateLifecycleTentaclePolicyDatasourceModelFromResource(data *schemas.SpaceDefaultLifecycleTentacleRetentionPoliciesDataSourceModel, resource *retention.SpaceDefaultRetentionPolicyResource) {
60+
data.ID = types.StringValue(resource.GetID())
61+
data.Strategy = types.StringValue(resource.Strategy)
62+
data.QuantityToKeep = util.Ternary(resource.QuantityToKeep == 0, types.Int64Null(), types.Int64Value(int64(resource.QuantityToKeep)))
63+
data.Unit = util.Ternary(resource.Unit == "", types.StringNull(), types.StringValue(resource.Unit))
64+
}

0 commit comments

Comments
 (0)