From 51492df12480f06e311917d08a775f443ae434a9 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 2 Oct 2024 15:42:10 +0100 Subject: [PATCH] Add support for ephemeral resources (#138) --- schemas.go | 3 +++ schemas_test.go | 17 +++++++++++++++++ testdata/ephemeral_resources/schemas.json | 1 + 3 files changed, 21 insertions(+) create mode 100644 testdata/ephemeral_resources/schemas.json diff --git a/schemas.go b/schemas.go index a2918ef..f6acc1f 100644 --- a/schemas.go +++ b/schemas.go @@ -87,6 +87,9 @@ type ProviderSchema struct { // The schemas for any data sources in this provider. DataSourceSchemas map[string]*Schema `json:"data_source_schemas,omitempty"` + // The schemas for any ephemeral resources in this provider. + EphemeralResourceSchemas map[string]*Schema `json:"ephemeral_resource_schemas,omitempty"` + // The definitions for any functions in this provider. Functions map[string]*FunctionSignature `json:"functions,omitempty"` } diff --git a/schemas_test.go b/schemas_test.go index 53cbce2..dddf5e1 100644 --- a/schemas_test.go +++ b/schemas_test.go @@ -43,6 +43,23 @@ func TestProviderSchemasValidate_functions(t *testing.T) { } } +func TestProviderSchemasValidate_ephemeralResources(t *testing.T) { + f, err := os.Open("testdata/ephemeral_resources/schemas.json") + if err != nil { + t.Fatal(err) + } + defer f.Close() + + var schemas *ProviderSchemas + if err := json.NewDecoder(f).Decode(&schemas); err != nil { + t.Fatal(err) + } + + if err := schemas.Validate(); err != nil { + t.Fatal(err) + } +} + func TestProviderSchemasValidate_nestedAttributes(t *testing.T) { f, err := os.Open("testdata/nested_attributes/schemas.json") if err != nil { diff --git a/testdata/ephemeral_resources/schemas.json b/testdata/ephemeral_resources/schemas.json new file mode 100644 index 0000000..f2e98e1 --- /dev/null +++ b/testdata/ephemeral_resources/schemas.json @@ -0,0 +1 @@ +{"format_version":"1.0","provider_schemas":{"registry.terraform.io/hashicorp/random":{"provider":{"version":0,"block":{"description_kind":"plain"}},"ephemeral_resource_schemas":{"random_password":{"version":0,"block":{"attributes":{"bcrypt_hash":{"type":"string","description":"A bcrypt hash of the generated random string. **NOTE**: If the generated random string is greater than 72 bytes in length, `bcrypt_hash` will contain a hash of the first 72 bytes.","description_kind":"plain","computed":true,"sensitive":true},"length":{"type":"number","description":"The length of the string desired. The minimum value for length is 1 and, length must also be \u003e= (`min_upper` + `min_lower` + `min_numeric` + `min_special`).","description_kind":"plain","required":true},"lower":{"type":"bool","description":"Include lowercase alphabet characters in the result. Default value is `true`.","description_kind":"plain","optional":true,"computed":true},"min_lower":{"type":"number","description":"Minimum number of lowercase alphabet characters in the result. Default value is `0`.","description_kind":"plain","optional":true,"computed":true},"min_numeric":{"type":"number","description":"Minimum number of numeric characters in the result. Default value is `0`.","description_kind":"plain","optional":true,"computed":true},"min_special":{"type":"number","description":"Minimum number of special characters in the result. Default value is `0`.","description_kind":"plain","optional":true,"computed":true},"min_upper":{"type":"number","description":"Minimum number of uppercase alphabet characters in the result. Default value is `0`.","description_kind":"plain","optional":true,"computed":true},"numeric":{"type":"bool","description":"Include numeric characters in the result. Default value is `true`. If `numeric`, `upper`, `lower`, and `special` are all configured, at least one of them must be set to `true`.","description_kind":"plain","optional":true,"computed":true},"override_special":{"type":"string","description":"Supply your own list of special characters to use for string generation. This overrides the default character list in the special argument. The `special` argument must still be set to true for any overwritten characters to be used in generation.","description_kind":"plain","optional":true},"result":{"type":"string","description":"The generated random string.","description_kind":"plain","computed":true,"sensitive":true},"special":{"type":"bool","description":"Include special characters in the result. These are `!@#$%\u0026*()-_=+[]{}\u003c\u003e:?`. Default value is `true`.","description_kind":"plain","optional":true,"computed":true},"upper":{"type":"bool","description":"Include uppercase alphabet characters in the result. Default value is `true`.","description_kind":"plain","optional":true,"computed":true}},"description_kind":"plain"}}}}}}