From 8f289892aa015fa9a5aed381ed998d5805023aa7 Mon Sep 17 00:00:00 2001 From: Isabel Andrade <67916678+beandrad@users.noreply.github.com> Date: Wed, 9 Jun 2021 17:13:01 +0100 Subject: [PATCH] Set `IsSensitive` in variable schema (#55) So that terraform-ls can return information about whether a variable value is sensitive. --- schema/convert_json.go | 1 + schema/schema_merge_v012_test.go | 6 ++- schema/schema_merge_v013_test.go | 78 +++++++++++++++++++++----------- schema/variable_schema.go | 3 +- schema/variable_schema_test.go | 4 +- 5 files changed, 62 insertions(+), 30 deletions(-) diff --git a/schema/convert_json.go b/schema/convert_json.go index 84113c5f..5e95a9c8 100644 --- a/schema/convert_json.go +++ b/schema/convert_json.go @@ -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), } } diff --git a/schema/schema_merge_v012_test.go b/schema/schema_merge_v012_test.go index 69dfd63e..63336e04 100644 --- a/schema/schema_merge_v012_test.go +++ b/schema/schema_merge_v012_test.go @@ -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}, @@ -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}, diff --git a/schema/schema_merge_v013_test.go b/schema/schema_merge_v013_test.go index 77b823f2..3d258646 100644 --- a/schema/schema_merge_v013_test.go +++ b/schema/schema_merge_v013_test.go @@ -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}, @@ -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{ @@ -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, }, }, }, @@ -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{ @@ -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{ @@ -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, }, }, }, @@ -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{ @@ -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, }, }, }, @@ -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{ @@ -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{ @@ -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, }, }, }, @@ -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}, diff --git a/schema/variable_schema.go b/schema/variable_schema.go index a25e1694..88dc2b4b 100644 --- a/schema/variable_schema.go +++ b/schema/variable_schema.go @@ -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, } } diff --git a/schema/variable_schema_test.go b/schema/variable_schema_test.go index 55282a91..156a94e4 100644 --- a/schema/variable_schema_test.go +++ b/schema/variable_schema_test.go @@ -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{ @@ -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, }, }}, },