diff --git a/CHANGELOG.md b/CHANGELOG.md index 70da4a2af..f1ef0e524 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ nav_order: 1 +## [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 diff --git a/internal/sdkprovider/service/project/project.go b/internal/sdkprovider/service/project/project.go index d2372408c..cce4798e8 100644 --- a/internal/sdkprovider/service/project/project.go +++ b/internal/sdkprovider/service/project/project.go @@ -30,12 +30,9 @@ 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, @@ -43,10 +40,6 @@ var aivenProjectSchema = map[string]*schema.Schema{ 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, @@ -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, diff --git a/internal/sdkprovider/service/project/project_test.go b/internal/sdkprovider/service/project/project_test.go index 158595fd9..407ed7903 100644 --- a/internal/sdkprovider/service/project/project_test.go +++ b/internal/sdkprovider/service/project/project_test.go @@ -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"), + ), + }, }, }) }