Skip to content

Commit

Permalink
feat(organization_vpc): added organization_vpc and peering connection…
Browse files Browse the repository at this point in the history
…s resources
  • Loading branch information
vmyroslav committed Feb 6, 2025
1 parent 429d440 commit 45e70c5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 50 deletions.
51 changes: 26 additions & 25 deletions internal/sdkprovider/service/project/billing_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ var aivenBillingGroupSchema = map[string]*schema.Schema{
Description: "Additional information to include on your invoice (for example, a reference number).",
},
"billing_emails": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
DiffSuppressFunc: schemautil.EmptyObjectNoChangeDiffSuppressFunc,
Description: "Email address of billing contacts. Invoices and other payment notifications are emailed to all billing contacts.",
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
//DiffSuppressFunc: schemautil.EmptyObjectNoChangeDiffSuppressFunc,
Description: "Email address of billing contacts. Invoices and other payment notifications are emailed to all billing contacts.",
},
"company": {
Type: schema.TypeString,
Expand All @@ -74,11 +74,9 @@ var aivenBillingGroupSchema = map[string]*schema.Schema{
Description: "Your company name.",
},
"address_lines": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
//DiffSuppressFunc: schemautil.EmptyObjectNoChangeDiffSuppressFunc,
//Computed: true,
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Description: "Address lines 1 and 2. For example, street, PO box, or building.",
},
"country_code": {
Expand Down Expand Up @@ -266,19 +264,6 @@ func resourceBillingGroupRead(ctx context.Context, d *schema.ResourceData, clien
}

func resourceBillingGroupUpdate(ctx context.Context, d *schema.ResourceData, client avngen.Client) error {
var billingEmails *[]billinggroup.BillingEmailIn

if emails := contactEmailListForAPI(
d,
"billing_emails",
true,
func(email string) billinggroup.BillingEmailIn {
return billinggroup.BillingEmailIn{Email: email}
},
); len(emails) > 0 {
billingEmails = &emails
}

cardID, err := getLongCardID(ctx, client, d.Get("card_id").(string))
if err != nil {
return fmt.Errorf("error getting card id: %w", err)
Expand All @@ -296,7 +281,6 @@ func resourceBillingGroupUpdate(ctx context.Context, d *schema.ResourceData, cli
list := schemautil.FlattenToString(v.(*schema.Set).List())
return &list
}
// If the field is not set in config at all, return empty array to clear it
emptyList := make([]string, 0)

return &emptyList
Expand All @@ -307,7 +291,24 @@ func resourceBillingGroupUpdate(ctx context.Context, d *schema.ResourceData, cli
}
return ""
}(),
BillingEmails: billingEmails,
BillingEmails: func() *[]billinggroup.BillingEmailIn {
var billingEmails = make([]billinggroup.BillingEmailIn, 0)

_, ok := d.GetOk("billing_emails")
if ok {
billingEmails = contactEmailListForAPI(
d,
"billing_emails",
true,
func(email string) billinggroup.BillingEmailIn {
return billinggroup.BillingEmailIn{Email: email}
},
)
}

return &billingEmails

}(),
BillingExtraText: util.NilIfZero(d.Get("billing_extra_text").(string)),
BillingGroupName: util.NilIfZero(d.Get("name").(string)),
CardId: cardID,
Expand Down
47 changes: 23 additions & 24 deletions internal/sdkprovider/service/project/billing_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,54 +41,53 @@ func TestAccAivenBillingGroup_basic(t *testing.T) {
),
},
{
// Test importing billing group
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
// Test updating billing group
Config: testAccBillingGroupResourceUpdated(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("test-acc-bg-%s", rName)),
resource.TestCheckResourceAttr(resourceName, "billing_currency", "EUR"),
resource.TestCheckResourceAttr(resourceName, "billing_extra_text", "updated reference number 456"),
resource.TestCheckResourceAttr(resourceName, "company", "Updated Company Ltd"),
resource.TestCheckResourceAttr(resourceName, "address_lines.#", "2"),
resource.TestCheckResourceAttr(resourceName, "address_lines.#", "3"),
resource.TestCheckTypeSetElemAttr(resourceName, "address_lines.*", "456 Updated Street"),
resource.TestCheckTypeSetElemAttr(resourceName, "address_lines.*", "Suite 8"),
resource.TestCheckTypeSetElemAttr(resourceName, "address_lines.*", "Main Avenue"),
resource.TestCheckResourceAttr(resourceName, "country_code", "FI"),
resource.TestCheckResourceAttr(resourceName, "city", "Updated City"),
resource.TestCheckResourceAttr(resourceName, "zip_code", "54321"),
resource.TestCheckResourceAttr(resourceName, "state", "Updated State"),
resource.TestCheckResourceAttr(resourceName, "vat_id", "UPDATED-VAT-456"),
resource.TestCheckResourceAttr(resourceName, "billing_emails.#", "3"),
resource.TestCheckResourceAttr(resourceName, "billing_emails.#", "2"),
resource.TestCheckTypeSetElemAttr(resourceName, "billing_emails.*", "ivan.savciuc+test2@aiven.fi"),
resource.TestCheckTypeSetElemAttr(resourceName, "billing_emails.*", "ivan.savciuc+test3@aiven.fi"),
),
},
{
// Test removing optional set fields
Config: testAccBillingGroupResourceOptionalFieldsRemoved(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("test-acc-bg-%s", rName)),
resource.TestCheckResourceAttr(resourceName, "billing_emails.#", "0"),
resource.TestCheckNoResourceAttr(resourceName, "billing_currency"),
resource.TestCheckNoResourceAttr(resourceName, "billing_extra_text"),
resource.TestCheckNoResourceAttr(resourceName, "company"),
resource.TestCheckResourceAttr(resourceName, "address_lines.#", "0"),
resource.TestCheckNoResourceAttr(resourceName, "country_code"),
resource.TestCheckNoResourceAttr(resourceName, "city"),
resource.TestCheckNoResourceAttr(resourceName, "zip_code"),
resource.TestCheckNoResourceAttr(resourceName, "state"),
resource.TestCheckNoResourceAttr(resourceName, "vat_id"),
resource.TestCheckNoResourceAttr(resourceName, "card_id"),
),
},
//{
// Config: testCopyBillingGroupFromExistingOne(rName),
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr("aiven_billing_group.bar2", "name", fmt.Sprintf("copy-test-acc-bg-%s", rName)),
// resource.TestCheckResourceAttr("aiven_billing_group.bar", "billing_currency", "EUR"),
// resource.TestCheckResourceAttr("aiven_billing_group.bar2", "billing_currency", "EUR"),
// resource.TestCheckResourceAttr("aiven_billing_group.bar2", "city", "Helsinki"),
// resource.TestCheckResourceAttr("aiven_billing_group.bar2", "company", "Aiven Oy"),
// resource.TestCheckResourceAttr("aiven_billing_group.bar2", "vat_id", "abc"),
// ),
//},
{
Config: testCopyBillingGroupFromExistingOne(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("aiven_billing_group.bar2", "name", fmt.Sprintf("copy-test-acc-bg-%s", rName)),
resource.TestCheckResourceAttr("aiven_billing_group.bar", "billing_currency", "EUR"),
resource.TestCheckResourceAttr("aiven_billing_group.bar2", "billing_currency", "EUR"),
resource.TestCheckResourceAttr("aiven_billing_group.bar2", "city", "Helsinki"),
resource.TestCheckResourceAttr("aiven_billing_group.bar2", "company", "Aiven Oy"),
resource.TestCheckResourceAttr("aiven_billing_group.bar2", "vat_id", "abc"),
),
},
},
})
}
Expand Down Expand Up @@ -185,11 +184,11 @@ resource "aiven_organization" "foo" {
resource "aiven_billing_group" "foo" {
name = "test-acc-bg-%[1]s"
billing_emails = ["ivan.savciuc+test1@aiven.fi", "ivan.savciuc+test2@aiven.fi", "ivan.savciuc+test3@aiven.fi"]
billing_emails = ["ivan.savciuc+test2@aiven.fi", "ivan.savciuc+test3@aiven.fi"]
billing_currency = "EUR"
billing_extra_text = "updated reference number 456"
company = "Updated Company Ltd"
address_lines = ["456 Updated Street", "Suite 8"]
address_lines = ["456 Updated Street", "Suite 8", "Main Avenue"]
country_code = "FI"
city = "Updated City"
zip_code = "54321"
Expand Down
1 change: 0 additions & 1 deletion internal/sdkprovider/service/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ func resourceProjectRead(ctx context.Context, d *schema.ResourceData, client avn

pr := resp.(*project.ProjectGetOut)

//TODO: finish this part
if stateID := d.Get("parent_id"); stateID != "" {
idToSet, err := DetermineMixedOrganizationConstraintIDToStore(
ctx,
Expand Down

0 comments on commit 45e70c5

Please sign in to comment.