Skip to content

Commit 582de52

Browse files
committed
resource/gitlab_repository_file: Add execute_filemode attribute
I've recently implemented the `execute_filemode` flag to the Repository Files API. This change set makes it available in the provider, too :) Closes #981
1 parent bf8b820 commit 582de52

File tree

6 files changed

+17
-0
lines changed

6 files changed

+17
-0
lines changed

docs/data-sources/repository_file.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ data "gitlab_repository_file" "example" {
4343
- `content` (String) File content. If the content is not yet base64 encoded, it will be encoded automatically. No other encoding is currently supported, because of a [GitLab API bug](https://gitlab.com/gitlab-org/gitlab/-/issues/342430).
4444
- `content_sha256` (String) File content sha256 digest.
4545
- `encoding` (String) The file content encoding.
46+
- `execute_filemode` (Boolean) Enables or disables the execute flag on the file. **Note**: requires GitLab 14.10 or newer.
4647
- `file_name` (String) The filename.
4748
- `last_commit_id` (String) The last known commit id.
4849
- `size` (Number) The file size.

docs/resources/repository_file.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ resource "gitlab_repository_file" "readme" {
7575

7676
- `author_email` (String) Email of the commit author.
7777
- `author_name` (String) Name of the commit author.
78+
- `execute_filemode` (Boolean) Enables or disables the execute flag on the file. **Note**: requires GitLab 14.10 or newer.
7879
- `id` (String) The ID of this resource.
7980
- `start_branch` (String) Name of the branch to start the new commit from.
8081
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

internal/provider/data_source_gitlab_repository_file_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func testAccDataSourceGitlabRepositoryFile(src, n string) resource.TestCheckFunc
4040
"size",
4141
"encoding",
4242
"content",
43+
"execute_filemode",
4344
"ref",
4445
"blob_id",
4546
"commit_id",
@@ -64,6 +65,7 @@ resource "gitlab_repository_file" "foo" {
6465
branch = "main"
6566
content = base64encode("Meow goes the cat")
6667
commit_message = "feat: Meow"
68+
execute_filemode = true
6769
}
6870
6971
data "gitlab_repository_file" "foo" {

internal/provider/resource_gitlab_repository_file.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ func resourceGitlabRepositoryFileCreate(ctx context.Context, d *schema.ResourceD
126126
if startBranch, ok := d.GetOk("start_branch"); ok {
127127
options.StartBranch = gitlab.String(startBranch.(string))
128128
}
129+
if executeFilemode, ok := d.GetOk("execute_filemode"); ok {
130+
options.ExecuteFilemode = gitlab.Bool(executeFilemode.(bool))
131+
}
129132

130133
err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
131134
repositoryFile, _, err := client.RepositoryFiles.CreateFile(project, filePath, options, gitlab.WithContext(ctx))
@@ -227,6 +230,9 @@ func resourceGitlabRepositoryFileUpdate(ctx context.Context, d *schema.ResourceD
227230
if startBranch, ok := d.GetOk("start_branch"); ok {
228231
updateOptions.StartBranch = gitlab.String(startBranch.(string))
229232
}
233+
if executeFilemode, ok := d.GetOk("execute_filemode"); ok {
234+
updateOptions.ExecuteFilemode = gitlab.Bool(executeFilemode.(bool))
235+
}
230236

231237
err = resource.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
232238
// NOTE: we also re-read the file to obtain an eventually changed `LastCommitID` for which we needed the refresh

internal/provider/resource_gitlab_repository_file_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ resource "gitlab_repository_file" "this" {
366366
author_email = "[email protected]"
367367
author_name = "Meow Meowington"
368368
commit_message = "feature: change launch codes"
369+
execute_filemode = true
369370
}
370371
`, projectID)
371372
}

internal/provider/schema_gitlab_repository_file.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func gitlabRepositoryFileGetSchema() map[string]*schema.Schema {
4949
Type: schema.TypeString,
5050
Computed: true,
5151
},
52+
"execute_filemode": {
53+
Description: "Enables or disables the execute flag on the file. **Note**: requires GitLab 14.10 or newer.",
54+
Type: schema.TypeBool,
55+
Optional: true,
56+
},
5257
"blob_id": {
5358
Description: "The blob id.",
5459
Type: schema.TypeString,
@@ -76,6 +81,7 @@ func gitlabRepositoryFileToStateMap(project string, repositoryFile *gitlab.File)
7681
stateMap["encoding"] = repositoryFile.Encoding
7782
stateMap["content"] = repositoryFile.Content
7883
stateMap["content_sha256"] = repositoryFile.SHA256
84+
stateMap["execute_filemode"] = repositoryFile.ExecuteFilemode
7985
stateMap["ref"] = repositoryFile.Ref
8086
stateMap["blob_id"] = repositoryFile.BlobID
8187
stateMap["commit_id"] = repositoryFile.CommitID

0 commit comments

Comments
 (0)