diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e69c1432..c93a29042 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ nav_order: 1 +## [4.31.1] - 2024-12-23 + +- Validate whether the `aiven_project.billing_group` field has changed before calling admin API + ## [4.31.0] - 2024-12-18 - Add `alloydbomni` BETA resource and datasource diff --git a/internal/sdkprovider/service/project/project.go b/internal/sdkprovider/service/project/project.go index 833a3340b..4feadb75d 100644 --- a/internal/sdkprovider/service/project/project.go +++ b/internal/sdkprovider/service/project/project.go @@ -314,11 +314,21 @@ func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, m interf return diag.FromErr(err) } - if billingGroupID, ok := d.GetOk("billing_group"); ok { + // Assigns the project to the billing group if it is not already assigned. + // The endpoints used in resourceProjectAssignToBillingGroup require admin privileges. + // So to make this resource manageable by non-admin users, we need to check if the billing group is already valid + // by making a simple comparison. + // The billing_group is either set in the config file or received by resourceProjectRead from ProjectGET, + // in which it is required https://api.aiven.io/doc/#tag/Project/operation/ProjectGet + // therefore, it is safe to assume that it is always set. + // ProjectUpdate also always returns the billing group. + // Hence, we can compare remote and local values. + billingGroupID := d.Get("billing_group").(string) + if billingGroupID != project.BillingGroupId { dia := resourceProjectAssignToBillingGroup( ctx, d.Get("project").(string), - billingGroupID.(string), + billingGroupID, client, d, )