Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add float64 to supported sensitve fields #290

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions pkg/types/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ func TestBuild(t *testing.T) {
TerraformResource: &schema.Resource{
Schema: map[string]*schema.Schema{
"key_1": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Sensitive: true,
},
},
},
},
},
want: want{
err: errors.Wrapf(fmt.Errorf(`got type %q for field %q, only types "string", "*string", []string, []*string, "map[string]string" and "map[string]*string" supported as sensitive`, "*float64", "Key1"), "cannot build the Types"),
err: errors.Wrapf(fmt.Errorf(`got type %q for field %q, only types "string", "*string", []string, []*string, "map[string]string", "map[string]*string", float64 and *float64 supported as sensitive`, "*int64", "Key1"), "cannot build the Types"),
},
},
"References": {
Expand Down
7 changes: 4 additions & 3 deletions pkg/types/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func NewSensitiveField(g *Builder, cfg *config.Resource, r *resource, sch *schem
cfg.Sensitive.AddFieldPath(fieldPathWithWildcard(f.TerraformPaths), "spec.forProvider."+fieldPathWithWildcard(f.CRDPaths)+sfx)
// todo(turkenh): do we need to support other field types as sensitive?
if f.FieldType.String() != "string" && f.FieldType.String() != "*string" && f.FieldType.String() != "[]string" &&
f.FieldType.String() != "[]*string" && f.FieldType.String() != "map[string]string" && f.FieldType.String() != "map[string]*string" {
return nil, false, fmt.Errorf(`got type %q for field %q, only types "string", "*string", []string, []*string, "map[string]string" and "map[string]*string" supported as sensitive`, f.FieldType.String(), f.FieldNameCamel)
f.FieldType.String() != "[]*string" && f.FieldType.String() != "map[string]string" && f.FieldType.String() != "map[string]*string" &&
f.FieldType.String() != "float64" && f.FieldType.String() != "*float64" {
return nil, false, fmt.Errorf(`got type %q for field %q, only types "string", "*string", []string, []*string, "map[string]string", "map[string]*string", float64 and *float64 supported as sensitive`, f.FieldType.String(), f.FieldNameCamel)
}
// Replace a parameter field with secretKeyRef if it is sensitive.
// If it is an observation field, it will be dropped.
Expand All @@ -98,7 +99,7 @@ func NewSensitiveField(g *Builder, cfg *config.Resource, r *resource, sch *schem

f.TFTag = "-"
switch f.FieldType.String() {
case "string", "*string":
case "string", "*string", "float64", "*float64":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this change manually and confirmed it works? Here is where we take the value from secret and then write to the TF file but it converts it to string before doing so. So, I think we may end up having a "231231241" as value instead of 231231241 in the main.tf.json, which Terraform may accept but better check if that's the case. Otherwise, we need to find a way to discover the type and convert it to that type before calling setSensitiveParametersWithPaved function. cc @turkenh

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only tried upgrading terraform-provider-datadog to version v3.14 which seems to work. But did not try creating a resource with it that uses float64 for sensitive fields check. Will test it out and get back

f.FieldType = typeSecretKeySelector
case "[]string", "[]*string":
f.FieldType = types.NewSlice(typeSecretKeySelector)
Expand Down