Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/resources/service_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ resource "doppler_service_token" "backend_ci_token" {
### Optional

- `access` (String) The access level (read or read/write)
- `expire_at` (String) The expiration time of the token as an RFC3339 timestamp (e.g. `2026-12-31T23:59:59Z`). If omitted, the token never expires.

### Read-Only

Expand Down
5 changes: 4 additions & 1 deletion doppler/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,13 +1177,16 @@ func (client APIClient) GetServiceTokens(ctx context.Context, project string, co
return result.ServiceTokens, nil
}

func (client APIClient) CreateServiceToken(ctx context.Context, project string, config string, access string, name string) (*ServiceToken, error) {
func (client APIClient) CreateServiceToken(ctx context.Context, project string, config string, access string, name string, expireAt string) (*ServiceToken, error) {
payload := map[string]interface{}{
"project": project,
"config": config,
"access": access,
"name": name,
}
if expireAt != "" {
payload["expire_at"] = expireAt
}
body, err := json.Marshal(payload)
if err != nil {
return nil, &APIError{Err: err, Message: "Unable to serialize service token"}
Expand Down
1 change: 1 addition & 0 deletions doppler/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ type ServiceToken struct {
Access string `json:"access"`
Key string `json:"key"`
CreatedAt string `json:"created_at"`
ExpiresAt string `json:"expires_at,omitempty"`
}

type ServiceTokenResponse struct {
Expand Down
10 changes: 9 additions & 1 deletion doppler/resource_service_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ func resourceServiceToken() *schema.Resource {
ValidateFunc: validation.StringInSlice([]string{"read", "read/write"}, false),
ForceNew: true,
},
"expire_at": {
Description: "The expiration time of the token as an RFC3339 timestamp (e.g. `2026-12-31T23:59:59Z`). If omitted, the token never expires.",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.IsRFC3339Time,
},
"key": {
Description: "The key for the Doppler service token",
Type: schema.TypeString,
Expand All @@ -60,8 +67,9 @@ func resourceServiceTokenCreate(ctx context.Context, d *schema.ResourceData, m i
config := d.Get("config").(string)
access := d.Get("access").(string)
name := d.Get("name").(string)
expireAt := d.Get("expire_at").(string)

token, err := client.CreateServiceToken(ctx, project, config, access, name)
token, err := client.CreateServiceToken(ctx, project, config, access, name, expireAt)
if err != nil {
return diag.FromErr(err)
}
Expand Down