Skip to content

Commit 966f9cd

Browse files
alewandoapparentlymart
authored andcommitted
local_file: sensitive_content argument
Sometimes local_file is used to generate files containing sensitive content. This new alternative argument, which can be used in place of content, will prevent such sensitive content from being displayed in diff output. It conflicts with the existing "content" argument, and so users must choose either one or the other.
1 parent 5d6a151 commit 966f9cd

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

local/resource_local_file.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@ func resourceLocalFile() *schema.Resource {
1818

1919
Schema: map[string]*schema.Schema{
2020
"content": {
21-
Type: schema.TypeString,
22-
Required: true,
23-
ForceNew: true,
21+
Type: schema.TypeString,
22+
Optional: true,
23+
ForceNew: true,
24+
ConflictsWith: []string{"sensitive_content"},
25+
},
26+
"sensitive_content": {
27+
Type: schema.TypeString,
28+
Optional: true,
29+
ForceNew: true,
30+
Sensitive: true,
31+
ConflictsWith: []string{"content"},
2432
},
2533
"filename": {
2634
Type: schema.TypeString,
@@ -57,8 +65,19 @@ func resourceLocalFileRead(d *schema.ResourceData, _ interface{}) error {
5765
return nil
5866
}
5967

68+
func resourceLocalFileContent(d *schema.ResourceData) string {
69+
content := d.Get("content")
70+
sensitiveContent, sensitiveSpecified := d.GetOk("sensitive_content")
71+
useContent := content.(string)
72+
if sensitiveSpecified {
73+
useContent = sensitiveContent.(string)
74+
}
75+
76+
return useContent
77+
}
78+
6079
func resourceLocalFileCreate(d *schema.ResourceData, _ interface{}) error {
61-
content := d.Get("content").(string)
80+
content := resourceLocalFileContent(d)
6281
destination := d.Get("filename").(string)
6382

6483
destinationDir := path.Dir(destination)

local/resource_local_file_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ func TestLocalFile_Basic(t *testing.T) {
2323
`resource "local_file" "file" {
2424
content = "This is some content"
2525
filename = "local_file"
26+
}`,
27+
},
28+
{
29+
"local_file",
30+
"This is some sensitive content",
31+
`resource "local_file" "file" {
32+
sensitive_content = "This is some sensitive content"
33+
filename = "local_file"
2634
}`,
2735
},
2836
}

website/docs/r/file.html.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ resource "local_file" "foo" {
2929

3030
The following arguments are supported:
3131

32-
* `content` - (Required) The content of file to create.
32+
* `content` - (Optional) The content of file to create. Conflicts with `sensitive_content`.
33+
34+
* `sensitive_content` - (Optional) The content of file to create. Will not be displayed in diffs. Conflicts with `content`.
3335

3436
* `filename` - (Required) The path of the file to create.
3537

0 commit comments

Comments
 (0)