Skip to content

Commit ea6de45

Browse files
authored
Merge pull request #510 from Bobonium/fix_deploy_token_expiry
fix deploy_token expiration
2 parents f36b1e7 + 7f614c2 commit ea6de45

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

docs/resources/deploy_token.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The following arguments are supported:
4141

4242
* `username` - (Optional, string) A username for the deploy token. Default is `gitlab+deploy-token-{n}`.
4343

44-
* `expires_at` - (Optional, string) Time the token will expire it, RFC3339 format.
44+
* `expires_at` - (Optional, string) Time the token will expire it, RFC3339 format. Will not expire per default.
4545

4646
* `scopes` - (Required, set of strings) Valid values: `read_repository`, `read_registry`.
4747

gitlab/resource_gitlab_deploy_token.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ func resourceGitlabDeployTokenCreate(d *schema.ResourceData, meta interface{}) e
7272
project, isProject := d.GetOk("project")
7373
group, isGroup := d.GetOk("group")
7474

75-
var expiresAt time.Time
75+
var expiresAt *time.Time
7676
var err error
7777

7878
if exp, ok := d.GetOk("expires_at"); ok {
79-
expiresAt, err = time.Parse(time.RFC3339, exp.(string))
79+
parsedExpiresAt, err := time.Parse(time.RFC3339, exp.(string))
80+
expiresAt = &parsedExpiresAt
8081
if err != nil {
8182
return fmt.Errorf("Invalid expires_at date: %v", err)
8283
}
@@ -90,7 +91,7 @@ func resourceGitlabDeployTokenCreate(d *schema.ResourceData, meta interface{}) e
9091
options := &gitlab.CreateProjectDeployTokenOptions{
9192
Name: gitlab.String(d.Get("name").(string)),
9293
Username: gitlab.String(d.Get("username").(string)),
93-
ExpiresAt: gitlab.Time(expiresAt),
94+
ExpiresAt: expiresAt,
9495
Scopes: *scopes,
9596
}
9697

@@ -102,7 +103,7 @@ func resourceGitlabDeployTokenCreate(d *schema.ResourceData, meta interface{}) e
102103
options := &gitlab.CreateGroupDeployTokenOptions{
103104
Name: gitlab.String(d.Get("name").(string)),
104105
Username: gitlab.String(d.Get("username").(string)),
105-
ExpiresAt: gitlab.Time(expiresAt),
106+
ExpiresAt: expiresAt,
106107
Scopes: *scopes,
107108
}
108109

@@ -151,7 +152,10 @@ func resourceGitlabDeployTokenRead(d *schema.ResourceData, meta interface{}) err
151152
if token.ID == deployTokenID {
152153
d.Set("name", token.Name)
153154
d.Set("username", token.Username)
154-
d.Set("expires_at", token.ExpiresAt.Format(time.RFC3339))
155+
156+
if token.ExpiresAt != nil {
157+
d.Set("expires_at", token.ExpiresAt)
158+
}
155159

156160
for _, scope := range token.Scopes {
157161
if scope == "read_repository" {

0 commit comments

Comments
 (0)