-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(userconfig/desc): add entity and availability types (#1648)
- Loading branch information
1 parent
c906303
commit 3acf177
Showing
10 changed files
with
146 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,18 @@ | |
page_title: "aiven_organization_application_user Resource - terraform-provider-aiven" | ||
subcategory: "" | ||
description: |- | ||
Creates and manages an organization application user. Application users can be used for programmatic access to the platform. This features is in the limited availability stage. Contact [email protected] to try this feature. | ||
This resource is in beta and may change without notice. To use this resource, | ||
set the PROVIDER_AIVEN_ENABLE_BETA environment variable to true. | ||
Creates and manages an organization application user. Application users can be used for programmatic access to the platform. | ||
This resource is in the limited availability stage and may change without notice. | ||
To enable this feature, contact the sales team mailto:[email protected]. After it's enabled, set | ||
the PROVIDER_AIVEN_ENABLE_BETA environment variable to use the resource. | ||
--- | ||
|
||
# aiven_organization_application_user (Resource) | ||
|
||
Creates and manages an organization application user. Application users can be used for programmatic access to the platform. This features is in the limited availability stage. Contact [email protected] to try this feature. | ||
|
||
**This resource is in beta and may change without notice.** To use this resource, | ||
set the `PROVIDER_AIVEN_ENABLE_BETA` environment variable to true. | ||
Creates and manages an organization application user. Application users can be used for programmatic access to the platform. | ||
**This resource is in the limited availability stage and may change without notice.** | ||
To enable this feature, contact the [sales team](mailto:[email protected]). After it's enabled, set | ||
the `PROVIDER_AIVEN_ENABLE_BETA` environment variable to use the resource. | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
|
||
"github.com/aiven/terraform-provider-aiven/internal/plugin/errmsg" | ||
"github.com/aiven/terraform-provider-aiven/internal/plugin/util" | ||
"github.com/aiven/terraform-provider-aiven/internal/schemautil/userconfig" | ||
) | ||
|
||
var ( | ||
|
@@ -78,7 +79,13 @@ func (r *organizationApplicationUser) Schema( | |
resp *resource.SchemaResponse, | ||
) { | ||
resp.Schema = util.GeneralizeSchema(ctx, schema.Schema{ | ||
Description: util.BetaDescription("Creates and manages an organization application user. Application users can be used for programmatic access to the platform. This features is in the limited availability stage. Contact [email protected] to try this feature."), | ||
Description: userconfig. | ||
Desc( | ||
"Creates and manages an organization application user. Application users can be used for " + | ||
"programmatic access to the platform.", | ||
). | ||
AvailabilityType(userconfig.Limited). | ||
Build(), | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Description: "Compound identifier of the organization application user.", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,23 +5,77 @@ import ( | |
"strings" | ||
) | ||
|
||
// EntityType is a type that represents the type of an entity. | ||
type EntityType int | ||
|
||
const ( | ||
// Resource is a constant that represents the resource entity type. | ||
Resource EntityType = iota | ||
// DataSource is a constant that represents the data source entity type. | ||
DataSource | ||
) | ||
|
||
// String is a function that returns the string representation of the entity type. | ||
func (et EntityType) String() string { | ||
return [...]string{"resource", "data source"}[et] | ||
} | ||
|
||
// AvailabilityType is a type that represents the availability type of an entity. | ||
type AvailabilityType int | ||
|
||
const ( | ||
// Beta is a constant that represents the beta availability type. | ||
Beta AvailabilityType = iota + 1 | ||
// Limited is a constant that represents the limited availability type. | ||
Limited | ||
) | ||
|
||
// DescriptionBuilder is a helper to build complex descriptions in a consistent way. | ||
type DescriptionBuilder struct { | ||
base string | ||
// entityType is the type of the entity that the description is for. | ||
entityType EntityType | ||
// base is the base of the description. | ||
base string | ||
// availabilityType is the availability type of the entity that the description is for. | ||
availabilityType AvailabilityType | ||
// withForcedFirstLetterCapitalization is a flag that indicates if the first letter should be capitalized. | ||
withForcedFirstLetterCapitalization bool | ||
withPossibleValues []any | ||
withRequiredWith []string | ||
withMaxLen int | ||
withDefaultValue any | ||
withUseReference bool | ||
withForceNew bool | ||
// withPossibleValues is a flag that indicates if the possible values should be included. | ||
withPossibleValues []any | ||
// withRequiredWith is a flag that indicates if the required with should be included. | ||
withRequiredWith []string | ||
// withMaxLen is a flag that indicates if the maximum length should be included. | ||
withMaxLen int | ||
// withDefaultValue is a flag that indicates if the default value should be included. | ||
withDefaultValue any | ||
// withUseReference is a flag that indicates if the reference should be used. | ||
withUseReference bool | ||
// withForceNew is a flag that indicates if the force new should be included. | ||
withForceNew bool | ||
} | ||
|
||
// Desc is a function that creates a new DescriptionBuilder. | ||
func Desc(base string) *DescriptionBuilder { | ||
return &DescriptionBuilder{base: base} | ||
} | ||
|
||
// MarkAsDataSource is a function that marks the entity whose description is being built as a data source. | ||
// | ||
// All entities are considered resources by default, so this function is only needed when the entity is a data source. | ||
// | ||
// If you want to mark the entity as a resource, you don't need to call any additional functions, and you can proceed | ||
// further with the description building. | ||
func (db *DescriptionBuilder) MarkAsDataSource() *DescriptionBuilder { | ||
db.entityType = DataSource | ||
return db | ||
} | ||
|
||
// AvailabilityType is a function that sets the availabilityType field. | ||
func (db *DescriptionBuilder) AvailabilityType(t AvailabilityType) *DescriptionBuilder { | ||
db.availabilityType = t | ||
return db | ||
} | ||
|
||
// ForceFirstLetterCapitalization is a function that sets the withForcedFirstLetterCapitalization flag. | ||
func (db *DescriptionBuilder) ForceFirstLetterCapitalization() *DescriptionBuilder { | ||
db.withForcedFirstLetterCapitalization = true | ||
|
@@ -81,6 +135,31 @@ func (db *DescriptionBuilder) Build() string { | |
builder.WriteString(".") | ||
} | ||
|
||
if db.availabilityType != 0 { | ||
builder.WriteRune(' ') | ||
|
||
const availabilityCommonPart = ` | ||
**This %[1]s is in the %[2]s stage and may change without notice.** %[3]s | ||
the ` + "`PROVIDER_AIVEN_ENABLE_BETA`" + ` environment variable to use the %[1]s.` | ||
|
||
switch db.availabilityType { | ||
case Beta: | ||
builder.WriteString(fmt.Sprintf( | ||
availabilityCommonPart, | ||
db.entityType.String(), | ||
"beta", | ||
"Set", | ||
)) | ||
case Limited: | ||
builder.WriteString(fmt.Sprintf( | ||
availabilityCommonPart, | ||
db.entityType.String(), | ||
"limited availability", | ||
"\nTo enable this feature, contact the [sales team](mailto:[email protected]). After it's enabled, set", | ||
)) | ||
} | ||
} | ||
|
||
if db.withPossibleValues != nil { | ||
builder.WriteRune(' ') | ||
builder.WriteString("The possible values are ") | ||
|
@@ -130,7 +209,9 @@ func (db *DescriptionBuilder) Build() string { | |
|
||
if db.withForceNew { | ||
builder.WriteRune(' ') | ||
builder.WriteString("Changing this property forces recreation of the resource.") | ||
builder.WriteString(fmt.Sprintf( | ||
"Changing this property forces recreation of the %s.", db.entityType.String(), | ||
)) | ||
} | ||
|
||
return builder.String() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters