Skip to content

Commit

Permalink
Merge pull request #67 from kylecarbs/master
Browse files Browse the repository at this point in the history
Parse the sensitive key for input variables
  • Loading branch information
alisdair authored Nov 15, 2021
2 parents 09f3484 + 5d41bab commit 49ab3af
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 2 deletions.
7 changes: 7 additions & 0 deletions tfconfig/load_hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ func LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics {
v.Required = true
}

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

case "output":

content, _, contentDiags := block.Body.PartialContent(outputSchema)
Expand Down
3 changes: 3 additions & 0 deletions tfconfig/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ var variableSchema = &hcl.BodySchema{
{
Name: "default",
},
{
Name: "sensitive",
},
},
}

Expand Down
44 changes: 44 additions & 0 deletions tfconfig/testdata/variable-sensitive/variable-sensitive.out.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"path": "testdata/variable-sensitive",
"required_providers": {
"null": {}
},
"variables": {
"A": {
"name": "A",
"default": "A default",
"required": false,
"pos": {
"filename": "testdata/variable-sensitive/variable-sensitive.tf",
"line": 1
}
},
"B": {
"name": "B",
"default": "B default",
"required": false,
"sensitive": true,
"pos": {
"filename": "testdata/variable-sensitive/variable-sensitive.tf",
"line": 5
}
}
},
"outputs": {},
"managed_resources": {
"null_resource.A": {
"mode": "managed",
"type": "null_resource",
"name": "A",
"provider": {
"name": "null"
},
"pos": {
"filename": "testdata/variable-sensitive/variable-sensitive.tf",
"line": 10
}
}
},
"data_resources": {},
"module_calls": {}
}
13 changes: 13 additions & 0 deletions tfconfig/testdata/variable-sensitive/variable-sensitive.out.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

# Module `testdata/variable-sensitive`

Provider Requirements:
* **null:** (any version)

## Input Variables
* `A` (default `"A default"`)
* `B` (default `"B default"`)

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

10 changes: 10 additions & 0 deletions tfconfig/testdata/variable-sensitive/variable-sensitive.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "A" {
default = "A default"
}

variable "B" {
default = "B default"
sensitive = true
}

resource "null_resource" "A" {}
5 changes: 3 additions & 2 deletions tfconfig/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ type Variable struct {
// the native Go type system. The conversion from the value given in
// configuration may be slightly lossy. Only values that can be
// serialized by json.Marshal will be included here.
Default interface{} `json:"default"`
Required bool `json:"required"`
Default interface{} `json:"default"`
Required bool `json:"required"`
Sensitive bool `json:"sensitive,omitempty"`

Pos SourcePos `json:"pos"`
}

0 comments on commit 49ab3af

Please sign in to comment.