Skip to content

Commit 6c8e7ad

Browse files
committed
Add shell_sensitive_script data source and resource (scottwinkler#111)
1 parent ef2552d commit 6c8e7ad

File tree

7 files changed

+101
-9
lines changed

7 files changed

+101
-9
lines changed

shell/data_source_shell_script.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/rs/xid"
88
)
99

10-
func dataSourceShellScript() *schema.Resource {
10+
func dataSourceShellScript(sensitive_output bool) *schema.Resource {
1111
return &schema.Resource{
1212
Read: dataSourceShellScriptRead,
1313

@@ -52,6 +52,7 @@ func dataSourceShellScript() *schema.Resource {
5252
Type: schema.TypeMap,
5353
Computed: true,
5454
Elem: schema.TypeString,
55+
Sensitive: sensitive_output,
5556
},
5657
},
5758
}

shell/provider.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ func Provider() terraform.ResourceProvider {
3838
},
3939

4040
DataSourcesMap: map[string]*schema.Resource{
41-
"shell_script": dataSourceShellScript(),
41+
"shell_script": dataSourceShellScript(false),
42+
"shell_sensitive_script": dataSourceShellScript(true),
4243
},
4344

4445
ResourcesMap: map[string]*schema.Resource{
45-
"shell_script": resourceShellScript(),
46+
"shell_script": resourceShellScript(false),
47+
"shell_sensitive_script": resourceShellScript(true),
4648
},
4749
ConfigureFunc: providerConfigure,
4850
}

shell/provider_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestProvider_impl(t *testing.T) {
3333
func TestProvider_HasChildResources(t *testing.T) {
3434
expectedResources := []string{
3535
"shell_script",
36+
"shell_sensitive_script",
3637
}
3738

3839
resources := testAccProvider.ResourcesMap
@@ -47,6 +48,7 @@ func TestProvider_HasChildResources(t *testing.T) {
4748
func TestProvider_HasChildDataSources(t *testing.T) {
4849
expectedDataSources := []string{
4950
"shell_script",
51+
"shell_sensitive_script",
5052
}
5153

5254
dataSources := testAccProvider.DataSourcesMap

shell/resource_shell_script.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/rs/xid"
1111
)
1212

13-
func resourceShellScript() *schema.Resource {
13+
func resourceShellScript(sensitive_output bool) *schema.Resource {
1414
return &schema.Resource{
1515
Create: resourceShellScriptCreate,
1616
Delete: resourceShellScriptDelete,
@@ -78,6 +78,7 @@ func resourceShellScript() *schema.Resource {
7878
Type: schema.TypeMap,
7979
Computed: true,
8080
Elem: schema.TypeString,
81+
Sensitive: sensitive_output,
8182
},
8283
"dirty": {
8384
Type: schema.TypeBool,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
layout: "shell"
3+
page_title: "Shell: shell_sensitive_script"
4+
sidebar_current: "docs-shell-data-source"
5+
description: |-
6+
Shell script custom data source
7+
---
8+
9+
# shell_script
10+
11+
The `shell_sensitive_script` data shares the same interface as the `shell_script` data, but its output is sensitive. As a result, the output will not be exposed in the logs.
12+
13+
14+
## Example Usage
15+
16+
```hcl
17+
variable "token" {
18+
type = string
19+
}
20+
21+
data "shell_sensitive_script" "secret" {
22+
lifecycle_commands {
23+
read = <<-EOF
24+
set -e
25+
secret=$(curl "https://example.com/secret" -H "Authorization: Basic $TOKEN")
26+
jq --null-input --arg secret "$secret" '{"value": $secret}'
27+
EOF
28+
}
29+
sensitive_environment = {
30+
TOKEN = var.token
31+
}
32+
}
33+
34+
output "secret" {
35+
value = data.shell_sensitive_script.secret.output["value"]
36+
sensitive = true
37+
}
38+
```
39+
40+
## Attributes Reference
41+
42+
* `output` - A map of outputs
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
layout: "shell"
3+
page_title: "Shell: shell_sensitive_script"
4+
sidebar_current: "docs-shell-resource"
5+
description: |-
6+
Shell script custom resource
7+
---
8+
9+
# shell_script
10+
11+
The `shell_sensitive_script` resource shares the same interface as the `shell_script` resource, but its output is sensitive. As a result, the output will not be exposed in the logs.
12+
13+
## Example Usage
14+
15+
```hcl
16+
resource "shell_sensitive_script" "special_secret" {
17+
lifecycle_commands {
18+
create = <<EOF
19+
set -e
20+
secret=$(openssl rand -hex 32)
21+
jq --null-input --arg secret "$secret" '{"value": $secret}'
22+
EOF
23+
delete = <<EOF
24+
# nothing
25+
EOF
26+
}
27+
}
28+
output "special_secret" {
29+
value = shell_sensitive_script.special_secret.output["value"]
30+
sensitive = true
31+
}
32+
```
33+
34+
## Argument Reference
35+
36+
The following arguments are supported:
37+
38+
* `output` - A map of outputs

website/shell.erb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,37 @@
55
<li<%= sidebar_current("docs-home") %>>
66
<a href="/docs/providers/index.html">All Providers</a>
77
</li>
8-
8+
99
<li<%= sidebar_current("docs-shell-index") %>>
1010
<a href="/docs/providers/shell/index.html">Shell Provider</a>
1111
</li>
12-
12+
1313
<li<%= sidebar_current("docs-shell-datasource") %>>
1414
<a href="#">Data Sources</a>
1515
<ul class="nav nav-visible">
1616
<li<%= sidebar_current("docs-shell-datasource") %>>
1717
<a href="/docs/providers/shell/d/shell_script_data_source.html">shell_script</a>
1818
</li>
19+
<li<%= sidebar_current("docs-shell-datasource") %>>
20+
<a href="/docs/providers/shell/d/shell_sensitive_script_data_source.html">shell_script</a>
21+
</li>
1922
</ul>
2023
</li>
21-
24+
2225
<li<%= sidebar_current("docs-shell-resource") %>>
2326
<a href="#">Resources</a>
2427
<ul class="nav nav-visible">
2528
<li<%= sidebar_current("docs-shell-resource") %>>
2629
<a href="/docs/providers/shell/r/shell_script_resource.html">shell_script</a>
2730
</li>
31+
<li<%= sidebar_current("docs-shell-resource") %>>
32+
<a href="/docs/providers/shell/r/shell_sensitive_script_resource.html">shell_script</a>
33+
</li>
2834
</ul>
2935
</li>
3036
</ul>
3137
</div>
3238
<% end %>
33-
39+
3440
<%= yield %>
35-
<% end %>
41+
<% end %>

0 commit comments

Comments
 (0)