hashicorp / hashicorp/terraform-plugin-sdk

Formats: consider extend value types to allow format enforcing

Open
#812 1 comment 1 reaction 0 assignees View on GitHub
enhancement terraform-plugin-framework
Dominant language
Go
Stars
485
Forks
244
Avg merge
19h 57m
Merged PRs (30d)
4

Description

### Proposal

[schema/valuetype](https://github.com/hashicorp/terraform-plugin-sdk/blob/main/helper/schema/valuetype.go) 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:
```golang
const (
TypeInvalid ValueType = iota
...
...
...
TypeURI
TypeHEX
TypeUnixTimeStamp
TypePath
TypeHash
TypeVersion
etc.
)
```

### Use-cases

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

The schema would look like this:
```golang
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](https://github.com/secure-systems-lab/securesystemslib/blob/master/securesystemslib/formats.py)

Contributor guide

Open the contributing guide

Research direction

Start by reading helper/schema/valuetype.go and reviewing the proposed URI, HEX, Unix timestamp, path, hash, and version formats. Clarify which formats and validation semantics should be supported; done means the selected value types and their validation behavior are defined and implemented.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.