in internal/provider/resource_gitlab_group_access_token.go [80:213]
func (r *gitlabGroupAccessTokenResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: `The ` + "`gitlab_group_access_token`" + ` resource allows to manage the lifecycle of a group 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/group_access_tokens/#automatic-reuse-detection) it's possible that a new Group Access Token will immediately be revoked. Check if an old process using the old token is running if this happens.
**Upstream API**: [GitLab REST API](https://docs.gitlab.com/api/group_access_tokens/)`,
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "The ID of the group access token.",
Computed: true,
},
"group": schema.StringAttribute{
MarkdownDescription: "The ID or full path of the group.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplace(),
},
Required: true,
},
"name": schema.StringAttribute{
MarkdownDescription: "The name of the group access token.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplace(),
},
Required: true,
},
"description": schema.StringAttribute{
MarkdownDescription: "The description of the group access token.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplace(),
},
Computed: true,
Optional: true,
},
"scopes": schema.SetAttribute{
MarkdownDescription: fmt.Sprintf("The scopes of the group access token. Valid values are: %s", utils.RenderValueListForDocs(api.ValidGroupAccessTokenScopes)),
Required: true,
ElementType: types.StringType,
PlanModifiers: []planmodifier.Set{
setplanmodifier.RequiresReplace(),
setplanmodifier.UseStateForUnknown(),
},
Validators: []validator.Set{
setvalidator.ValueStringsAre(
stringvalidator.OneOfCaseInsensitive(api.ValidGroupAccessTokenScopes...),
),
},
},
"expires_at": schema.StringAttribute{
MarkdownDescription: "When the token will expire, YYYY-MM-DD format.",
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 group 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 group 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),
},
},
},
},
},
}
}