Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the sensitive attribute on outputs (#55) #56

Merged
merged 1 commit into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tfconfig/load_hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ func LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics {
o.Description = description
}

if attr, defined := content.Attributes["sensitive"]; defined {
var sensitive bool
valDiags := gohcl.DecodeExpression(attr.Expr, nil, &sensitive)
diags = append(diags, valDiags...)
o.Sensitive = sensitive
}

case "provider":

content, _, contentDiags := block.Body.PartialContent(providerConfigSchema)
Expand Down
2 changes: 2 additions & 0 deletions tfconfig/load_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func loadModuleLegacyHCL(fs FS, dir string) (*Module, Diagnostics) {
outputs = outputs.Children()
type OutputBlock struct {
Description string
Sensitive bool
}

for _, item := range outputs.Items {
Expand All @@ -144,6 +145,7 @@ func loadModuleLegacyHCL(fs FS, dir string) (*Module, Diagnostics) {
o := &Output{
Name: name,
Description: block.Description,
Sensitive: block.Sensitive,
Pos: sourcePosLegacyHCL(item.Pos(), filename),
}
if _, exists := mod.Outputs[name]; exists {
Expand Down
8 changes: 4 additions & 4 deletions tfconfig/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package tfconfig

// Output represents a single output from a Terraform module.
type Output struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`

Pos SourcePos `json:"pos"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
Pos SourcePos `json:"pos"`
}
3 changes: 3 additions & 0 deletions tfconfig/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ var outputSchema = &hcl.BodySchema{
{
Name: "description",
},
{
Name: "sensitive",
},
},
}

Expand Down
13 changes: 11 additions & 2 deletions tfconfig/testdata/basics-json/basics-json.out.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
"filename": "testdata/basics-json/basics.tf.json",
"line": 14
}
},
"C": {
"name": "C",
"description": "C is sensitive B",
"sensitive": true,
"pos": {
"filename": "testdata/basics-json/basics.tf.json",
"line": 18
}
}
},
"managed_resources": {
Expand All @@ -51,7 +60,7 @@
},
"pos": {
"filename": "testdata/basics-json/basics.tf.json",
"line": 21
"line": 26
}
},
"null_resource.B": {
Expand All @@ -63,7 +72,7 @@
},
"pos": {
"filename": "testdata/basics-json/basics.tf.json",
"line": 22
"line": 27
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions tfconfig/testdata/basics-json/basics.tf.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"B": {
"description": "I am B",
"value": "${var.A}"
},
"C": {
"description": "C is sensitive B",
"value": "${var.B}",
"sensitive": true
}
},
"resource": {
Expand Down
39 changes: 35 additions & 4 deletions tfconfig/testdata/basics/basics.out.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,41 @@
"filename": "testdata/basics/basics.tf",
"line": 5
}
},
"C": {
"name": "C",
"description": "The C variable",
"default": null,
"required": true,
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 9
}
}
},
"outputs": {
"A": {
"name": "A",
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 9
"line": 13
}
},
"B": {
"name": "B",
"description": "I am B",
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 13
"line": 17
}
},
"C": {
"name": "C",
"description": "C is sensitive",
"sensitive": true,
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 23
}
}
},
Expand All @@ -51,7 +70,7 @@
},
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 18
"line": 29
}
},
"null_resource.B": {
Expand All @@ -63,7 +82,19 @@
},
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 19
"line": 30
}
},
"null_resource.C": {
"mode": "managed",
"type": "null_resource",
"name": "C",
"provider": {
"name": "null"
},
"pos": {
"filename": "testdata/basics/basics.tf",
"line": 31
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions tfconfig/testdata/basics/basics.out.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ Provider Requirements:
## Input Variables
* `A` (default `"A default"`)
* `B` (required): The B variable
* `C` (required): The C variable

## Output Values
* `A`
* `B`: I am B
* `C`: C is sensitive

## Managed Resources
* `null_resource.A` from `null`
* `null_resource.B` from `null`
* `null_resource.C` from `null`

12 changes: 12 additions & 0 deletions tfconfig/testdata/basics/basics.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@ variable "B" {
description = "The B variable"
}

variable "C" {
description = "The C variable"
}

output "A" {
value = "${var.A}"
}

output "B" {
description = "I am B"
value = "${var.A}"
sensitive = false
}

output "C" {
description = "C is sensitive"
value = "${var.C}"
sensitive = true
}

resource "null_resource" "A" {}
resource "null_resource" "B" {}
resource "null_resource" "C" {}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"foo": {
"name": "foo",
"description": "foo description",
"sensitive": true,
"pos": {
"filename": "testdata/legacy-block-labels/legacy-block-labels.tf",
"line": 35
Expand All @@ -46,7 +47,7 @@
},
"pos": {
"filename": "testdata/legacy-block-labels/legacy-block-labels.tf",
"line": 40
"line": 41
}
}
},
Expand All @@ -60,7 +61,7 @@
},
"pos": {
"filename": "testdata/legacy-block-labels/legacy-block-labels.tf",
"line": 45
"line": 46
}
}
},
Expand All @@ -71,7 +72,7 @@
"version": "1.2.3",
"pos": {
"filename": "testdata/legacy-block-labels/legacy-block-labels.tf",
"line": 49
"line": 50
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ variable foo {

output foo {
description = "foo description"
sensitive = true
ignored = 1
}

Expand Down
25 changes: 17 additions & 8 deletions tfconfig/testdata/type-errors/type-errors.out.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
{
"severity": "error",
"summary": "Unsuitable value type",
"detail": "Unsuitable value: string required",
"detail": "Unsuitable value: a bool is required",
"pos": {
"filename": "testdata/type-errors/type-errors.tf",
"line": 11
"line": 8
}
},
{
Expand All @@ -43,7 +43,16 @@
"detail": "Unsuitable value: string required",
"pos": {
"filename": "testdata/type-errors/type-errors.tf",
"line": 16
"line": 13
}
},
{
"severity": "error",
"summary": "Unsuitable value type",
"detail": "Unsuitable value: string required",
"pos": {
"filename": "testdata/type-errors/type-errors.tf",
"line": 17
}
},
{
Expand All @@ -52,7 +61,7 @@
"detail": "Provider argument requires a provider name followed by an optional alias, like \"aws.foo\".",
"pos": {
"filename": "testdata/type-errors/type-errors.tf",
"line": 20
"line": 21
}
},
{
Expand All @@ -61,7 +70,7 @@
"detail": "Unsuitable value: string required",
"pos": {
"filename": "testdata/type-errors/type-errors.tf",
"line": 24
"line": 25
}
},
{
Expand All @@ -70,7 +79,7 @@
"detail": "Unsuitable value: string required",
"pos": {
"filename": "testdata/type-errors/type-errors.tf",
"line": 26
"line": 27
}
}
],
Expand Down Expand Up @@ -109,7 +118,7 @@
},
"pos": {
"filename": "testdata/type-errors/type-errors.tf",
"line": 19
"line": 20
}
}
},
Expand All @@ -120,7 +129,7 @@
"source": "",
"pos": {
"filename": "testdata/type-errors/type-errors.tf",
"line": 10
"line": 11
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions tfconfig/testdata/type-errors/type-errors.out.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Unsuitable value: string required

## Error: Unsuitable value type

(at `testdata/type-errors/type-errors.tf` line 11)
(at `testdata/type-errors/type-errors.tf` line 8)

Unsuitable value: string required
Unsuitable value: a bool is required

## Error: Unsuitable value type

Expand All @@ -45,25 +45,31 @@ Unsuitable value: string required

## Error: Unsuitable value type

(at `testdata/type-errors/type-errors.tf` line 16)
(at `testdata/type-errors/type-errors.tf` line 13)

Unsuitable value: string required

## Error: Unsuitable value type

(at `testdata/type-errors/type-errors.tf` line 17)

Unsuitable value: string required

## Error: Invalid provider reference

(at `testdata/type-errors/type-errors.tf` line 20)
(at `testdata/type-errors/type-errors.tf` line 21)

Provider argument requires a provider name followed by an optional alias, like "aws.foo".

## Error: Unsuitable value type

(at `testdata/type-errors/type-errors.tf` line 24)
(at `testdata/type-errors/type-errors.tf` line 25)

Unsuitable value: string required

## Error: Unsuitable value type

(at `testdata/type-errors/type-errors.tf` line 26)
(at `testdata/type-errors/type-errors.tf` line 27)

Unsuitable value: string required

1 change: 1 addition & 0 deletions tfconfig/testdata/type-errors/type-errors.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ variable "foo" {

output "foo" {
description = ["blah"]
sensitive = "blah"
}

module "foo" {
Expand Down