-
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
- Loading branch information
1 parent
c906303
commit 9a0a042
Showing
6 changed files
with
117 additions
and
18 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 |
---|---|---|
|
@@ -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,72 @@ 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", "datasource"}[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} | ||
} | ||
|
||
// EntityType is a function that sets the entityType field. | ||
func (db *DescriptionBuilder) EntityType(t EntityType) *DescriptionBuilder { | ||
db.entityType = t | ||
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 +130,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 +204,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