Skip to content

Commit f717f4b

Browse files
committed
resource/gitlab_project_access_token: Add importer
Refs: #36
1 parent b2f3390 commit f717f4b

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

docs/resources/project_access_token.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ resource "gitlab_project_variable" "example" {
5050
- **active** (Boolean) True if the token is active.
5151
- **created_at** (String) Time the token has been created, RFC3339 format.
5252
- **revoked** (Boolean) True if the token is revoked.
53-
- **token** (String, Sensitive) The secret token. This is only populated when creating a new project access token.
53+
- **token** (String, Sensitive) The secret token. **Note**: the token is not available for imported resources.
5454
- **user_id** (Number) The user_id associated to the token.
5555

56+
## Import
5657

58+
Import is supported using the following syntax:
59+
60+
```shell
61+
# A GitLab Project Access Token can be imported using a key composed of `<project-id>:<token-id>`, e.g.
62+
terraform import gitlab_project_access_token.example "12345:1"
63+
64+
# NOTE: the `token` resource attribute is not available for imported resources as this information cannot be read from the GitLab API.
65+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# A GitLab Project Access Token can be imported using a key composed of `<project-id>:<token-id>`, e.g.
2+
terraform import gitlab_project_access_token.example "12345:1"
3+
4+
# NOTE: the `token` resource attribute is not available for imported resources as this information cannot be read from the GitLab API.

internal/provider/resource_gitlab_project_access_token.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
)
1515

1616
var _ = registerResource("gitlab_project_access_token", func() *schema.Resource {
17-
// lintignore: XR002 // TODO: Resolve this tfproviderlint issue
1817
return &schema.Resource{
1918
Description: `The ` + "`" + `gitlab_project_access_token` + "`" + ` resource allows to manage the lifecycle of a project access token.
2019
@@ -23,6 +22,9 @@ var _ = registerResource("gitlab_project_access_token", func() *schema.Resource
2322
CreateContext: resourceGitlabProjectAccessTokenCreate,
2423
ReadContext: resourceGitlabProjectAccessTokenRead,
2524
DeleteContext: resourceGitlabProjectAccessTokenDelete,
25+
Importer: &schema.ResourceImporter{
26+
StateContext: schema.ImportStatePassthroughContext,
27+
},
2628

2729
Schema: map[string]*schema.Schema{
2830
"project": {
@@ -63,7 +65,7 @@ var _ = registerResource("gitlab_project_access_token", func() *schema.Resource
6365
ForceNew: true,
6466
},
6567
"token": {
66-
Description: "The secret token. This is only populated when creating a new project access token.",
68+
Description: "The secret token. **Note**: the token is not available for imported resources.",
6769
Type: schema.TypeString,
6870
Computed: true,
6971
Sensitive: true,

internal/provider/resource_gitlab_project_access_token_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ func TestAccGitlabProjectAccessToken_basic(t *testing.T) {
7373
}),
7474
),
7575
},
76+
// Verify import
77+
{
78+
ResourceName: "gitlab_project_access_token.bar",
79+
ImportState: true,
80+
ImportStateVerify: true,
81+
ImportStateVerifyIgnore: []string{
82+
// the token is only known during creating. We explicitly mention this limitation in the docs.
83+
"token",
84+
},
85+
},
7686
//Destroy Project Access Token
7787
{
7888
Config: testAccGitlabProjectAccessTokenDestroyToken(rInt),

0 commit comments

Comments
 (0)