Skip to content

Commit 13bdf24

Browse files
oarbusilantoli
andauthored
fix: Adds new attribute results and deprecates resource_policies for mongodbatlas_resource_policies data source (#2740)
* new attribute results and deprecate resource_policies * changelog entry * change test to check new attribute * fix changelog * changelog fix * fix docs * Update .changelog/2740.txt Co-authored-by: Leo Antoli <[email protected]> * migration test * skip mig test until next version * fix comment --------- Co-authored-by: Leo Antoli <[email protected]>
1 parent 8417717 commit 13bdf24

File tree

9 files changed

+71
-9
lines changed

9 files changed

+71
-9
lines changed

.changelog/2740.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
data-source/mongodbatlas_resource_policies: Adds `results` attribute
3+
```
4+
5+
```release-note:note
6+
data-source/mongodbatlas_resource_policies: Deprecates `resource_policies` attribute
7+
```

docs/data-sources/resource_policies.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ data "mongodbatlas_resource_policies" "this" {
8484
8585
8686
output "policy_ids" {
87-
value = { for policy in data.mongodbatlas_resource_policies.this.resource_policies : policy.name => policy.id }
87+
value = { for policy in data.mongodbatlas_resource_policies.this.results : policy.name => policy.id }
8888
}
8989
```
9090

@@ -97,7 +97,8 @@ output "policy_ids" {
9797

9898
### Read-Only
9999

100-
- `resource_policies` (Attributes List) (see [below for nested schema](#nestedatt--resource_policies))
100+
- `resource_policies` (Attributes List, Deprecated) (see [below for nested schema](#nestedatt--resource_policies))
101+
- `results` (Attributes List) (see [below for nested schema](#nestedatt--results))
101102

102103
<a id="nestedatt--resource_policies"></a>
103104
### Nested Schema for `resource_policies`
@@ -140,3 +141,46 @@ Read-Only:
140141
- `body` (String) A string that defines the permissions for the policy. The syntax used is the Cedar Policy language.
141142
- `id` (String) Unique 24-hexadecimal character string that identifies the policy.
142143

144+
145+
146+
<a id="nestedatt--results"></a>
147+
### Nested Schema for `results`
148+
149+
Read-Only:
150+
151+
- `created_by_user` (Attributes) The user that last updated the Atlas resource policy. (see [below for nested schema](#nestedatt--results--created_by_user))
152+
- `created_date` (String) Date and time in UTC when the Atlas resource policy was created.
153+
- `id` (String) Unique 24-hexadecimal digit string that identifies an Atlas resource policy.
154+
- `last_updated_by_user` (Attributes) The user that last updated the Atlas resource policy. (see [below for nested schema](#nestedatt--results--last_updated_by_user))
155+
- `last_updated_date` (String) Date and time in UTC when the Atlas resource policy was last updated.
156+
- `name` (String) Human-readable label that describes the Atlas resource policy.
157+
- `org_id` (String) Unique 24-hexadecimal digit string that identifies the organization that contains your projects. Use the [/orgs](#tag/Organizations/operation/listOrganizations) endpoint to retrieve all organizations to which the authenticated user has access.
158+
- `policies` (Attributes List) List of policies that make up the Atlas resource policy. (see [below for nested schema](#nestedatt--results--policies))
159+
- `version` (String) A string that identifies the version of the Atlas resource policy.
160+
161+
<a id="nestedatt--results--created_by_user"></a>
162+
### Nested Schema for `results.created_by_user`
163+
164+
Read-Only:
165+
166+
- `id` (String) Unique 24-hexadecimal character string that identifies a user.
167+
- `name` (String) Human-readable label that describes a user.
168+
169+
170+
<a id="nestedatt--results--last_updated_by_user"></a>
171+
### Nested Schema for `results.last_updated_by_user`
172+
173+
Read-Only:
174+
175+
- `id` (String) Unique 24-hexadecimal character string that identifies a user.
176+
- `name` (String) Human-readable label that describes a user.
177+
178+
179+
<a id="nestedatt--results--policies"></a>
180+
### Nested Schema for `results.policies`
181+
182+
Read-Only:
183+
184+
- `body` (String) A string that defines the permissions for the policy. The syntax used is the Cedar Policy language.
185+
- `id` (String) Unique 24-hexadecimal character string that identifies the policy.
186+

docs/data-sources/resource_policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ data "mongodbatlas_resource_policies" "this" {
8484
8585
8686
output "policy_ids" {
87-
value = { for policy in data.mongodbatlas_resource_policies.this.resource_policies : policy.name => policy.id }
87+
value = { for policy in data.mongodbatlas_resource_policies.this.results : policy.name => policy.id }
8888
}
8989
```
9090

docs/resources/resource_policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ data "mongodbatlas_resource_policies" "this" {
8686
8787
8888
output "policy_ids" {
89-
value = { for policy in data.mongodbatlas_resource_policies.this.resource_policies : policy.name => policy.id }
89+
value = { for policy in data.mongodbatlas_resource_policies.this.results : policy.name => policy.id }
9090
}
9191
```
9292

examples/mongodbatlas_resource_policy/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ data "mongodbatlas_resource_policies" "this" {
7474

7575

7676
output "policy_ids" {
77-
value = { for policy in data.mongodbatlas_resource_policies.this.resource_policies : policy.name => policy.id }
77+
value = { for policy in data.mongodbatlas_resource_policies.this.results : policy.name => policy.id }
7878
}

internal/service/resourcepolicy/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func NewTFModelDSP(ctx context.Context, orgID string, input []admin.ApiAtlasReso
8282
}
8383
return &TFModelDSP{
8484
ResourcePolicies: tfModels,
85+
Results: tfModels,
8586
OrgID: types.StringValue(orgID),
8687
}, *diags
8788
}

internal/service/resourcepolicy/plural_data_source_schema.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package resourcepolicy
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/hashicorp/terraform-plugin-framework/types"
8+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant"
79

810
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
911
)
@@ -18,6 +20,13 @@ func DataSourcePluralSchema(ctx context.Context) schema.Schema {
1820
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies the organization that contains your projects. Use the [/orgs](#tag/Organizations/operation/listOrganizations) endpoint to retrieve all organizations to which the authenticated user has access.",
1921
},
2022
"resource_policies": schema.ListNestedAttribute{
23+
DeprecationMessage: fmt.Sprintf(constant.DeprecationParamWithReplacement, "`results`"),
24+
NestedObject: schema.NestedAttributeObject{
25+
Attributes: dsAttributes,
26+
},
27+
Computed: true,
28+
},
29+
"results": schema.ListNestedAttribute{
2130
NestedObject: schema.NestedAttributeObject{
2231
Attributes: dsAttributes,
2332
},
@@ -30,4 +39,5 @@ func DataSourcePluralSchema(ctx context.Context) schema.Schema {
3039
type TFModelDSP struct {
3140
OrgID types.String `tfsdk:"org_id"`
3241
ResourcePolicies []TFModel `tfsdk:"resource_policies"`
42+
Results []TFModel `tfsdk:"results"`
3343
}

internal/service/resourcepolicy/resource_migration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ import (
77
)
88

99
func TestMigResourcePolicy_basic(t *testing.T) {
10-
mig.SkipIfVersionBelow(t, "1.21.0") // this feature was introduced in provider version 1.21.0
10+
mig.SkipIfVersionBelow(t, "1.22.0") // this feature was introduced in provider version 1.21.0, plural data source schema was changed in 1.22.0
1111
mig.CreateAndRunTestNonParallel(t, basicTestCase(t))
1212
}

internal/service/resourcepolicy/resource_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ func checksResourcePolicy(orgID, name string, policyCount int) resource.TestChec
158158
"version",
159159
}
160160
pluralMap := map[string]string{
161-
"org_id": orgID,
162-
"resource_policies.#": "1",
161+
"org_id": orgID,
162+
"results.#": "1",
163163
}
164164
checks := []resource.TestCheckFunc{checkExists()}
165165
checks = acc.AddAttrChecks(dataSourcePluralID, checks, pluralMap)
166166
for i := 0; i < policyCount; i++ {
167167
checks = acc.AddAttrSetChecks(resourceID, checks, fmt.Sprintf("policies.%d.body", i), fmt.Sprintf("policies.%d.id", i))
168168
checks = acc.AddAttrSetChecks(dataSourceID, checks, fmt.Sprintf("policies.%d.body", i), fmt.Sprintf("policies.%d.id", i))
169-
checks = acc.AddAttrSetChecks(dataSourcePluralID, checks, fmt.Sprintf("resource_policies.0.policies.%d.body", i), fmt.Sprintf("resource_policies.0.policies.%d.id", i))
169+
checks = acc.AddAttrSetChecks(dataSourcePluralID, checks, fmt.Sprintf("results.0.policies.%d.body", i), fmt.Sprintf("results.0.policies.%d.id", i))
170170
}
171171
// cannot use dataSourcePluralID as it doesn't have the `results` attribute
172172
return acc.CheckRSAndDS(resourceID, &dataSourceID, nil, attrSet, attrMap, resource.ComposeAggregateTestCheckFunc(checks...))

0 commit comments

Comments
 (0)