Skip to content

Commit

Permalink
Set IsSensitive in variable schema (#55)
Browse files Browse the repository at this point in the history
So that terraform-ls can return information about whether a variable
value is sensitive.
  • Loading branch information
beandrad authored Jun 9, 2021
1 parent f204156 commit 8f28989
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 30 deletions.
1 change: 1 addition & 0 deletions schema/convert_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func convertAttributesFromJson(attributes map[string]*tfjson.SchemaAttribute) ma
IsComputed: attr.Computed,
IsOptional: attr.Optional,
IsRequired: attr.Required,
IsSensitive: attr.Sensitive,
Expr: exprConstraintsFromAttribute(attr),
}
}
Expand Down
6 changes: 4 additions & 2 deletions schema/schema_merge_v012_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Value: "The generated random string.",
Kind: lang.PlainTextKind,
},
IsComputed: true,
IsComputed: true,
IsSensitive: true,
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
Expand Down Expand Up @@ -1004,7 +1005,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Value: "The generated random string.",
Kind: lang.PlainTextKind,
},
IsComputed: true,
IsComputed: true,
IsSensitive: true,
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
Expand Down
78 changes: 52 additions & 26 deletions schema/schema_merge_v013_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
Value: "Credentials for accessing the Grafana API.",
Kind: lang.PlainTextKind,
},
IsRequired: true,
IsRequired: true,
IsSensitive: true,
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
Expand Down Expand Up @@ -140,7 +141,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
schema.TraversalExpr{OfType: cty.Map(cty.String)},
schema.LiteralTypeExpr{Type: cty.Map(cty.String)},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"type": {
Expr: schema.ExprConstraints{
Expand Down Expand Up @@ -392,56 +394,64 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"basic_auth_password": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"password": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"private_key": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"secret_key": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"tls_ca_cert": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"tls_client_cert": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"tls_client_key": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
},
},
Expand All @@ -467,7 +477,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"basic_auth_username": {
Expr: schema.ExprConstraints{
Expand Down Expand Up @@ -510,7 +521,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"type": {
Expr: schema.ExprConstraints{
Expand Down Expand Up @@ -706,7 +718,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsRequired: true,
IsRequired: true,
IsSensitive: true,
},
},
},
Expand Down Expand Up @@ -755,7 +768,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
schema.TraversalExpr{OfType: cty.Map(cty.String)},
schema.LiteralTypeExpr{Type: cty.Map(cty.String)},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"type": {
Expr: schema.ExprConstraints{
Expand Down Expand Up @@ -1007,56 +1021,64 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"basic_auth_password": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"password": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"private_key": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"secret_key": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"tls_ca_cert": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"tls_client_cert": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"tls_client_key": {
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
},
},
Expand All @@ -1082,7 +1104,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"basic_auth_username": {
Expr: schema.ExprConstraints{
Expand Down Expand Up @@ -1125,7 +1148,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsOptional: true,
IsOptional: true,
IsSensitive: true,
},
"type": {
Expr: schema.ExprConstraints{
Expand Down Expand Up @@ -1321,7 +1345,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
IsRequired: true,
IsRequired: true,
IsSensitive: true,
},
},
},
Expand Down Expand Up @@ -1696,7 +1721,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
Value: "The generated random string.",
Kind: lang.MarkdownKind,
},
IsComputed: true,
IsComputed: true,
IsSensitive: true,
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
Expand Down
3 changes: 2 additions & 1 deletion schema/variable_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ func SchemaForVariables(vars map[string]module.Variable) (*schema.BodySchema, er
Value: v.Description,
Kind: lang.PlainTextKind,
},
Expr: schema.ExprConstraints{schema.LiteralTypeExpr{Type: v.Type}},
Expr: schema.ExprConstraints{schema.LiteralTypeExpr{Type: v.Type}},
IsSensitive: v.IsSensitive,
}
}

Expand Down
4 changes: 3 additions & 1 deletion schema/variable_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestSchemaForVariables(t *testing.T) {
"id": module.Variable{
Description: "id of the module",
Type: cty.Number,
IsSensitive: true,
},
},
&schema.BodySchema{Attributes: map[string]*schema.AttributeSchema{
Expand All @@ -66,7 +67,8 @@ func TestSchemaForVariables(t *testing.T) {
Value: "id of the module",
Kind: lang.PlainTextKind,
},
Expr: schema.ExprConstraints{schema.LiteralTypeExpr{cty.Number}},
Expr: schema.ExprConstraints{schema.LiteralTypeExpr{cty.Number}},
IsSensitive: true,
},
}},
},
Expand Down

0 comments on commit 8f28989

Please sign in to comment.