Skip to content

Commit

Permalink
feat(organization): application user tokens support
Browse files Browse the repository at this point in the history
  • Loading branch information
Serpentiel committed Jan 10, 2024
1 parent 14f218e commit f24ad74
Show file tree
Hide file tree
Showing 10 changed files with 577 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ nav_order: 1
## [MAJOR.MINOR.PATCH] - YYYY-MM-DD

- Add organization application users support
- Add organization application user tokens support
- Configure "insufficient broker" error retries timeout

## [4.12.1] - 2024-01-05
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/aiven/terraform-provider-aiven
go 1.21

require (
github.com/aiven/aiven-go-client/v2 v2.9.0
github.com/aiven/aiven-go-client/v2 v2.10.0
github.com/avast/retry-go v3.0.0+incompatible
github.com/dave/jennifer v1.7.0
github.com/docker/go-units v0.5.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7l
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/aiven/aiven-go-client/v2 v2.9.0 h1:LpfilLbahoCzDglh77jbwD5L8sJI3p7BvuZ/NXZoA8w=
github.com/aiven/aiven-go-client/v2 v2.9.0/go.mod h1:x0xhzxWEKAwKv0xY5FvECiI6tesWshcPHvjwl0B/1SU=
github.com/aiven/aiven-go-client/v2 v2.10.0 h1:18Wc0oPWK6qM7Qi/vbh0rb0bnaomLWAs6fgwwbghbig=
github.com/aiven/aiven-go-client/v2 v2.10.0/go.mod h1:x0xhzxWEKAwKv0xY5FvECiI6tesWshcPHvjwl0B/1SU=
github.com/aiven/go-api-schemas v1.52.0 h1:kCv4kNHGX2EvyKjoNWTfr9vIY6K5nNBn+A8h0bLWAjQ=
github.com/aiven/go-api-schemas v1.52.0/go.mod h1:/bPxBUHza/2Aeer6hIIdB++GxKiw9K1KCBtRa2rtZ5I=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down
10 changes: 10 additions & 0 deletions internal/plugin/errmsg/errmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const (
// SummaryErrorDeletingResource is the error summary for when a resource cannot be deleted.
SummaryErrorDeletingResource = "Error Deleting Resource"

// SummaryErrorImportingResource is the error summary for when a resource cannot be imported.
SummaryErrorImportingResource = "Error Importing Resource"

// SummaryDuplicateFoundByName is the error summary for when a duplicate resource is found by name.
SummaryDuplicateFoundByName = "Duplicate Found By Name"

Expand Down Expand Up @@ -86,6 +89,10 @@ var (
// DetailErrorDeletingResource is the detailed error message for when a resource cannot be deleted.
DetailErrorDeletingResource = "An unexpected error occurred while deleting the resource (%s): %s."

// DetailErrorImportingResourceNotSupported is the detailed error message for when a resource cannot be imported
// because it is not supported.
DetailErrorImportingResourceNotSupported = "Importing the resource (%s) is not supported."

// DetailDuplicateFoundByName is the detailed error message for when a duplicate resource is found by name.
DetailDuplicateFoundByName = "Multiple resources with the same name (%s) were found. Please use the ID to " +
"uniquely identify the resource."
Expand All @@ -108,4 +115,7 @@ var (

// AivenResourceNotFound is the error message for when an Aiven resource cannot be found.
AivenResourceNotFound = "aiven resource %s with compound ID %s not found"

// UnableToSetValueFrom is the error message for when a Set cannot be created from a value.
UnableToSetValueFrom = "unable to set value from %v"
)
1 change: 1 addition & 0 deletions internal/plugin/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (p *AivenProvider) Resources(context.Context) []func() resource.Resource {
organization.NewOrganizationUserGroupMembersResource,
organization.NewOrganizationGroupProjectResource,
organization.NewOrganizationApplicationUser,
organization.NewOrganizationApplicationUserToken,
}

resources = append(resources, betaResources...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ func TestAccOrganizationApplicationUserResourceDataSource(t *testing.T) {

deps.IsBeta(true)

name := "aiven_organization_application_user.foo"
names := []string{
"aiven_organization_application_user.foo",
"aiven_organization_application_user_token.foo",
}

dname := "data.aiven_organization_application_user.foo"

suffix := acctest.RandStringFromCharSet(acc.DefaultRandomSuffixLength, acctest.CharSetAlphaNum)
Expand All @@ -41,19 +45,19 @@ resource "aiven_organization_application_user" "foo" {
`, acc.DefaultResourceNamePrefix, suffix, deps.OrganizationName()),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
name,
names[0],
"name",
fmt.Sprintf("%s-org-appuser-%s", acc.DefaultResourceNamePrefix, suffix),
),
resource.TestCheckResourceAttrSet(name, "id"),
resource.TestCheckResourceAttrSet(names[0], "id"),
),
},
{
ResourceName: name,
ResourceName: names[0],
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: func(state *terraform.State) (string, error) {
rs, err := acc.ResourceFromState(state, name)
rs, err := acc.ResourceFromState(state, names[0])
if err != nil {
return "", err
}
Expand All @@ -76,7 +80,7 @@ resource "aiven_organization_application_user" "foo" {
`, acc.DefaultResourceNamePrefix, suffix, deps.OrganizationName()),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
name,
names[0],
"name",
fmt.Sprintf("%s-org-appuser-%s-1", acc.DefaultResourceNamePrefix, suffix),
),
Expand Down Expand Up @@ -106,6 +110,33 @@ data "aiven_organization_application_user" "foo" {
),
),
},
{
Config: fmt.Sprintf(`
data "aiven_organization" "foo" {
name = "%[3]s"
}
resource "aiven_organization_application_user" "foo" {
organization_id = data.aiven_organization.foo.id
name = "%[1]s-org-appuser-%[2]s-1"
}
resource "aiven_organization_application_user_token" "foo" {
organization_id = aiven_organization_application_user.foo.organization_id
user_id = aiven_organization_application_user.foo.user_id
description = "Terraform acceptance tests"
max_age_seconds = 3600
extend_when_used = true
scopes = ["user:read"]
}
`, acc.DefaultResourceNamePrefix, suffix, deps.OrganizationName()),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(names[1], "description", "Terraform acceptance tests"),
resource.TestCheckResourceAttr(names[1], "max_age_seconds", "3600"),
resource.TestCheckResourceAttr(names[1], "extend_when_used", "true"),
resource.TestCheckResourceAttr(names[1], "scopes.#", "1"),
),
},
},
})
}
Loading

0 comments on commit f24ad74

Please sign in to comment.