Skip to content

Commit

Permalink
fix(aiven_project): account_id -> parent_id transition (#1872)
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov authored Oct 18, 2024
1 parent c856ada commit cbbb469
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ nav_order: 1
<!-- Always keep the following header in place: -->
<!-- ## [MAJOR.MINOR.PATCH] - YYYY-MM-DD -->

## [MAJOR.MINOR.PATCH] - YYYY-MM-DD

- Fix `aiven_project`: can't migrate from `account_id` (deprecated) to `parent_id`

## [4.27.0] - 2024-10-09

- Remove `aiven_thanos` from beta resources
Expand Down
11 changes: 2 additions & 9 deletions internal/sdkprovider/service/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,16 @@ var aivenProjectSchema = map[string]*schema.Schema{
"account_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: userconfig.Desc("Link a project to an existing account using its account ID. This field is deprecated. Use `parent_id` instead.").Referenced().Build(),
Deprecated: "Use parent_id instead. This field will be removed in the next major release.",
DiffSuppressFunc: func(_, _, _ string, d *schema.ResourceData) bool {
_, ok := d.GetOk("parent_id")
return ok
},
},
"parent_id": {
Type: schema.TypeString,
Optional: true,
Description: userconfig.Desc(
"Link a project to an [organization, organizational unit,](https://aiven.io/docs/platform/concepts/orgs-units-projects) or account by using its ID.",
).Referenced().Build(),
DiffSuppressFunc: func(_, _, _ string, d *schema.ResourceData) bool {
_, ok := d.GetOk("account_id")
return ok
},
},
"copy_from_project": {
Type: schema.TypeString,
Expand Down Expand Up @@ -438,7 +431,7 @@ func setProjectTerraformProperties(
client *aiven.Client,
project *aiven.Project,
) diag.Diagnostics {
if stateID, ok := d.GetOk("parent_id"); ok {
if stateID := d.Get("parent_id"); stateID != "" {
idToSet, err := schemautil.DetermineMixedOrganizationConstraintIDToStore(
ctx,
client,
Expand Down
11 changes: 10 additions & 1 deletion internal/sdkprovider/service/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,27 @@ func TestAccAivenProject_accounts(t *testing.T) {
resourceName := "aiven_project.foo"
rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)

config := testAccProjectResourceAccounts(rName)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
ProtoV6ProviderFactories: acc.TestProtoV6ProviderFactories,
CheckDestroy: testAccCheckAivenProjectResourceDestroy,
Steps: []resource.TestStep{
{
Config: testAccProjectResourceAccounts(rName),
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckAivenProjectAttributes("data.aiven_project.project", "account_id"),
resource.TestCheckResourceAttr(resourceName, "project", fmt.Sprintf("test-acc-pr-%s", rName)),
),
},
{
// Tests account_id (deprecated) -> parent_id migration
Config: regexp.MustCompile(`account_id\s+=`).ReplaceAllString(config, "parent_id ="),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "account_id"), // it is computed and should be set
resource.TestCheckResourceAttrSet(resourceName, "parent_id"),
),
},
},
})
}
Expand Down

0 comments on commit cbbb469

Please sign in to comment.