Skip to content

Commit

Permalink
refactor(project|billing_group): replaced client-v2 with avngen
Browse files Browse the repository at this point in the history
  • Loading branch information
vmyroslav committed Feb 5, 2025
1 parent d17b833 commit 641c5be
Show file tree
Hide file tree
Showing 12 changed files with 684 additions and 342 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23

require (
github.com/aiven/aiven-go-client/v2 v2.34.0
github.com/aiven/go-client-codegen v0.81.0
github.com/aiven/go-client-codegen v0.84.0
github.com/avast/retry-go v3.0.0+incompatible
github.com/dave/jennifer v1.7.1
github.com/docker/go-units v0.5.0
Expand All @@ -18,7 +18,6 @@ require (
github.com/hashicorp/terraform-plugin-mux v0.18.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/rs/zerolog v1.33.0
github.com/samber/lo v1.49.0
github.com/stoewer/go-strcase v1.3.0
github.com/stretchr/testify v1.10.0
Expand All @@ -38,6 +37,7 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/aiven/aiven-go-client/v2 v2.34.0 h1:Iq3GZVoqrAPb4XcA3pJVL8MpRtiXep+LY
github.com/aiven/aiven-go-client/v2 v2.34.0/go.mod h1:qXBgER0dtjJa1V3l7kzpizuAGjFCkgahhHL5OpoM2ZM=
github.com/aiven/go-api-schemas v1.112.0 h1:Ab7mrYS84CS2G1YAnfeH8qecvjKMN6pTl3oHlCH6gV8=
github.com/aiven/go-api-schemas v1.112.0/go.mod h1:z7dGvufm6If4gOdVr7dWTuFZmll9FOZr5Z5CSxGpebA=
github.com/aiven/go-client-codegen v0.81.0 h1:TyAsYnmInX5n1JdcfzAYXRsgCCLLtt6tKxMSXtOkVHM=
github.com/aiven/go-client-codegen v0.81.0/go.mod h1:QKN/GgLMGWd6+gPEucXlZPi5vC3C6RpD3UeBRQOLI1Y=
github.com/aiven/go-client-codegen v0.84.0 h1:xJ9aw7WTlcKHBiHEiDLvZ+qzoGCEpdRq5B9fU9JJ7Tk=
github.com/aiven/go-client-codegen v0.84.0/go.mod h1:QKN/GgLMGWd6+gPEucXlZPi5vC3C6RpD3UeBRQOLI1Y=
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
Expand Down
6 changes: 6 additions & 0 deletions internal/plugin/util/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"math/big"
"os"

"golang.org/x/exp/constraints"
)
Expand Down Expand Up @@ -34,3 +35,8 @@ func First[T any, U any](a T, _ U) T {
func ToBigFloat[T constraints.Integer | constraints.Float](v T) *big.Float {
return big.NewFloat(float64(v))
}

// IsAcceptanceTestEnvironment checks if code is running in Terraform acceptance test environment
func IsAcceptanceTestEnvironment() bool {
return os.Getenv("TF_ACC") != ""
}
29 changes: 2 additions & 27 deletions internal/sdkprovider/service/organization/organizational_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/aiven/terraform-provider-aiven/internal/common"
"github.com/aiven/terraform-provider-aiven/internal/schemautil"
"github.com/aiven/terraform-provider-aiven/internal/sdkprovider/service/project"
)

var aivenOrganizationalUnitSchema = map[string]*schema.Schema{
Expand Down Expand Up @@ -94,7 +95,7 @@ func resourceOrganizationalUnitRead(ctx context.Context, d *schema.ResourceData,
}

if stateID, ok := d.GetOk("parent_id"); ok {
idToSet, err := determineMixedOrganizationConstraintIDToStore(
idToSet, err := project.DetermineMixedOrganizationConstraintIDToStore(
ctx,
client,
stateID.(string),
Expand All @@ -120,32 +121,6 @@ func resourceOrganizationalUnitRead(ctx context.Context, d *schema.ResourceData,
return nil
}

func determineMixedOrganizationConstraintIDToStore(
ctx context.Context,
client avngen.Client,
stateID string,
accountID string,
) (string, error) {
if len(accountID) == 0 {
return "", nil
}

if !schemautil.IsOrganizationID(stateID) {
return accountID, nil
}

r, err := client.AccountGet(ctx, accountID)
if err != nil {
return "", err
}

if len(r.OrganizationId) == 0 {
return accountID, nil
}

return r.OrganizationId, nil
}

func resourceOrganizationalUnitUpdate(ctx context.Context, d *schema.ResourceData, client avngen.Client) error {
var name = d.Get("name").(string)

Expand Down
Loading

0 comments on commit 641c5be

Please sign in to comment.