terraform-plugin-sdk icon indicating copy to clipboard operation
terraform-plugin-sdk copied to clipboard

Formats: consider extend value types to allow format enforcing

Open Dentrax opened this issue 3 years ago • 1 comments

Proposal

schema/valuetype is widely used enum across schemas for building custom plugins.

I propose that we can enrich this enum to validate much more different formats [^1], like the following:

const (
  TypeInvalid ValueType = iota
  ...
  ...
  ...
  TypeURI
  TypeHEX
  TypeUnixTimeStamp
  TypePath
  TypeHash
  TypeVersion
  etc.
)

Use-cases

data "foo" "bar" {
 url = "docker://qux/quux"
 hash = "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b"
 path = "./path/to/file/"
 ver = "v1.0"
}

The schema would look like this:

Schema: map[string]*schema.Schema{
  "url": {
    Type:        schema.TypeURI,
  },
  "hash": {
    Type:        schema.TypeHash,
  },
  "path": {
    Type:        schema.TypePath,
  },
  "ver": {
    Type:        schema.TypeVerion,
  },
},

Attempted Solutions

We have to manually implement the algorithm that checks if given format is valid.


What do you think? We can get to it if sounds makes sense. @developer-guy @erkanzileli

Any feedback would be appreciated.

[^1]: The idea comes from securesystemslib/formats.py

Dentrax avatar Oct 08 '21 20:10 Dentrax

Any thoughts? I think we can add this schema type validations into validation package. 🤔

Dentrax avatar Dec 09 '21 09:12 Dentrax