in internal/provider/resource_gitlab_project_access_token.go [86:219]
func (r *gitlabProjectAccessTokenResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: `The ` + "`" + `gitlab_project_access_token` + "`" + ` resource allows to manage the lifecycle of a project access token.
~> 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/project_access_tokens/#automatic-reuse-detection) it's possible that a new Project 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/project_access_tokens/)`,
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "The ID of the project access token.",
Computed: true,
},
"project": schema.StringAttribute{
MarkdownDescription: "The ID or full path of the project.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplace(),
},
Required: true,
},
"name": schema.StringAttribute{
MarkdownDescription: "The name of the project access token.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplace(),
},
Required: true,
},
"description": schema.StringAttribute{
MarkdownDescription: "The description of the project access token.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplace(),
},
Optional: true,
Computed: true,
},
"scopes": schema.SetAttribute{
MarkdownDescription: fmt.Sprintf("The scopes of the project access token. valid values are: %s", utils.RenderValueListForDocs(api.ValidProjectAccessTokenScopes)),
Required: true,
ElementType: types.StringType,
PlanModifiers: []planmodifier.Set{
setplanmodifier.RequiresReplace(),
setplanmodifier.UseStateForUnknown(),
},
Validators: []validator.Set{
setvalidator.ValueStringsAre(
stringvalidator.OneOfCaseInsensitive(api.ValidProjectAccessTokenScopes...),
),
},
},
"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.ExactlyOneOf(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 project 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,
},
"user_id": schema.Int64Attribute{
MarkdownDescription: "The user_id associated to the token.",
Computed: true,
},
"access_level": schema.StringAttribute{
MarkdownDescription: fmt.Sprintf("The access level for the project access token. Valid values are: %s. Default is `%s`.", utils.RenderValueListForDocs(api.ValidProjectAccessLevelNames), api.AccessLevelValueToName[gitlab.MaintainerPermissions]),
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplace(),
},
Default: stringdefault.StaticString(
api.AccessLevelValueToName[gitlab.MaintainerPermissions],
),
Computed: true,
Optional: 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.ExactlyOneOf(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),
},
},
},
},
},
}
}