in internal/provider/resource_gitlab_personal_access_token.go [76:197]
func (r *gitlabPersonalAccessTokenResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: `The ` + "`" + `gitlab_personal_access_token` + "`" + ` resource allows to manage the lifecycle of a personal access token.
-> This resource requires administration privileges.
~> Use of the ` + "`timestamp()`" + ` function with expires_at will cause the resource to be re-created with every apply, it's recommended to use ` + "`plantimestamp()`" + ` or a static value instead.
~> Observability scopes are in beta and may not work on all instances. See more details in [the documentation](https://docs.gitlab.com/operations/tracing/)
~> Use ` + "`rotation_configuration`" + ` to automatically rotate tokens instead of using ` + "`timestamp()`" + ` as timestamp will cause changes with every plan. ` + "`terraform apply`" + ` must still be run to rotate the token.
~> Due to [Automatic reuse detection](https://docs.gitlab.com/api/personal_access_tokens/#automatic-reuse-detection) it's possible that a new Personal Access Token will immediately be revoked. Check if an old process using the old token is running if this happens.
**Upstream API**: [GitLab API docs](https://docs.gitlab.com/api/personal_access_tokens/)`,
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "The ID of the personal access token.",
Computed: true,
},
"user_id": schema.Int64Attribute{
MarkdownDescription: "The ID of the user.",
PlanModifiers: []planmodifier.Int64{
int64planmodifier.UseStateForUnknown(),
int64planmodifier.RequiresReplace(),
},
Required: true,
},
"name": schema.StringAttribute{
MarkdownDescription: "The name of the personal access token.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplace(),
},
Required: true,
},
"description": schema.StringAttribute{
MarkdownDescription: "The description of the personal access token.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplace(),
},
Optional: true,
Computed: true,
},
"scopes": schema.SetAttribute{
MarkdownDescription: fmt.Sprintf("The scopes of the personal access token. valid values are: %s", utils.RenderValueListForDocs(api.ValidPersonalAccessTokenScopes)),
Required: true,
ElementType: types.StringType,
PlanModifiers: []planmodifier.Set{
setplanmodifier.RequiresReplace(),
setplanmodifier.UseStateForUnknown(),
},
Validators: []validator.Set{
setvalidator.ValueStringsAre(
stringvalidator.OneOfCaseInsensitive(api.ValidPersonalAccessTokenScopes...),
),
},
},
"expires_at": schema.StringAttribute{
MarkdownDescription: "When the token will expire, YYYY-MM-DD format. Is automatically set when `rotation_configuration` is used.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
stringvalidator.ConflictsWith(path.MatchRoot("rotation_configuration")),
},
Optional: true,
Computed: true,
},
"created_at": schema.StringAttribute{
MarkdownDescription: "Time the token has been created, RFC3339 format.",
Computed: true,
},
"token": schema.StringAttribute{
MarkdownDescription: "The token of the personal access token. **Note**: the token is not available for imported resources.",
Computed: true,
Sensitive: true,
},
"active": schema.BoolAttribute{
MarkdownDescription: "True if the token is active.",
Computed: true,
},
"revoked": schema.BoolAttribute{
MarkdownDescription: "True if the token is revoked.",
Computed: true,
},
"rotation_configuration": schema.SingleNestedAttribute{
MarkdownDescription: "The configuration for when to rotate a token automatically. Will not rotate a token until `terraform apply` is run.",
Optional: true,
Validators: []validator.Object{
objectvalidator.ConflictsWith(path.MatchRoot("expires_at")),
},
// Rotation attributes
Attributes: map[string]schema.Attribute{
"expiration_days": schema.Int64Attribute{
MarkdownDescription: "The duration (in days) the new token should be valid for.",
Required: true,
PlanModifiers: []planmodifier.Int64{
int64planmodifier.UseStateForUnknown(),
},
Validators: []validator.Int64{
int64validator.AtLeast(1),
},
},
"rotate_before_days": schema.Int64Attribute{
MarkdownDescription: "The duration (in days) before the expiration when the token should be rotated. As an example, if set to 7 days, the token will rotate 7 days before the expiration date, but only when `terraform apply` is run in that timeframe.",
Required: true,
PlanModifiers: []planmodifier.Int64{
int64planmodifier.UseStateForUnknown(),
},
Validators: []validator.Int64{
int64validator.AtLeast(1),
},
},
},
},
},
}
}