From 2ed9d05f097267b7674e5812e08b0a38a401cea1 Mon Sep 17 00:00:00 2001 From: danischm Date: Tue, 3 Oct 2023 14:29:55 +0200 Subject: [PATCH] Cleanup schema and add attribute descriptions --- gen/generator.go | 6 -- gen/schema/schema.yaml | 96 +++++++++++++++---------------- gen/templates/data_source_test.go | 16 +++--- gen/templates/model.go | 32 +++++------ gen/templates/resource.tf | 8 +-- gen/templates/resource_test.go | 16 +++--- 6 files changed, 81 insertions(+), 93 deletions(-) diff --git a/gen/generator.go b/gen/generator.go index 374dab9..8792b3e 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -95,7 +95,6 @@ var templates = []t{ type YamlConfig struct { Name string `yaml:"name"` - Model string `yaml:"model"` RestEndpoint string `yaml:"rest_endpoint"` GetNoId bool `yaml:"get_no_id"` NoDelete bool `yaml:"no_delete"` @@ -118,22 +117,17 @@ type YamlConfigAttribute struct { ModelName string `yaml:"model_name"` TfName string `yaml:"tf_name"` Type string `yaml:"type"` - ModelTypeString bool `yaml:"model_type_string"` DataPath []string `yaml:"data_path"` - Keys []string `yaml:"keys"` Id bool `yaml:"id"` Reference bool `yaml:"reference"` Mandatory bool `yaml:"mandatory"` WriteOnly bool `yaml:"write_only"` WriteChangesOnly bool `yaml:"write_changes_only"` - TfOnly bool `yaml:"tf_only"` ExcludeTest bool `yaml:"exclude_test"` ExcludeExample bool `yaml:"exclude_example"` - ExcludeIgnore bool `yaml:"exclude_ignore"` Description string `yaml:"description"` Example string `yaml:"example"` EnumValues []string `yaml:"enum_values"` - IgnoreEnum bool `yaml:"ignore_enum"` MinList int64 `yaml:"min_list"` MaxList int64 `yaml:"max_list"` MinInt int64 `yaml:"min_int"` diff --git a/gen/schema/schema.yaml b/gen/schema/schema.yaml index 489568f..2ead6f4 100644 --- a/gen/schema/schema.yaml +++ b/gen/schema/schema.yaml @@ -1,54 +1,48 @@ --- -name: str() -model: str(required=False) -rest_endpoint: str(required=False) -get_no_id: bool(required=False) -no_delete: bool(required=False) -post_update: bool(required=False) -root_list: bool(required=False) -no_read_prefix: bool(required=False) -id_path: str(required=False) -minimum_version: str(required=False) -ds_description: str(required=False) -res_description: str(required=False) -doc_category: str(required=False) -skip_minimum_test: bool(required=False) -attributes: list(include('attribute'), required=False) -test_tags: list(str(), required=False) -test_prerequisites: str(required=False) +name: str() # Name of the resource +rest_endpoint: str(required=False) # REST endpoint path +get_no_id: bool(required=False) # Set to true if the GET request does not require an ID +no_delete: bool(required=False) # Set to true if the DELETE request is not supported +post_update: bool(required=False) # Set to true if the POST request is used for update +root_list: bool(required=False) # Set to true if the root element of the data structure is a list +no_read_prefix: bool(required=False) # Set to true if it is an Open API endpoint put the response is not embeeded into a "response" element +id_path: str(required=False) # Path to the ID in the response (use "." to access nested elements) +minimum_version: str(required=False) # Define a minimum supported version +ds_description: str(required=False) # Define a data source description +res_description: str(required=False) # Define a resource description +doc_category: str(required=False) # Define a documentation category +skip_minimum_test: bool(required=False) # Do not perform a "minimum" (only mandatory attributes) test +attributes: list(include('attribute'), required=False) # List of attributes +test_tags: list(str(), required=False) # List of test tags, tests are only executed if an environment variable with one of these tags is configured +test_prerequisites: str(required=False) # HCL code that is included in the acceptance tests to define prerequisites --- attribute: - model_name: str(required=False) - tf_name: str(required=False) - type: enum('String', 'Int64', 'Bool', 'List', 'Set', 'StringList', required=False) - model_type_string: bool(required=False) - data_path: list(str(), required=False) - keys: list(str(), required=False) - id: bool(required=False) - reference: bool(required=False) - mandatory: bool(required=False) - write_only: bool(required=False) - write_changes_only: bool(required=False) - tf_only: bool(required=False) - exclude_test: bool(required=False) - exclude_example: bool(required=False) - exclude_ignore: bool(required=False) - description: str(required=False) - example: any(str(), int(), bool(), required=False) - enum_values: list(str(), required=False) - ignore_enum: bool(required=False) - min_list: int(required=False) - max_list: int(required=False) - min_int: int(required=False) - max_int: int(required=False) - min_float: num(required=False) - max_float: num(required=False) - string_patterns: list(str(), required=False) - string_min_length: int(required=False) - string_max_length: int(required=False) - default_value: any(str(), int(), bool(), required=False) - value: any(str(), int(), bool(), required=False) - test_value: str(required=False) - minimum_test_value: str(required=False) - test_tags: list(str(), required=False) - attributes: list(include('attribute'), required=False) + model_name: str(required=False) # Name of the attribute in the model (payload) + tf_name: str(required=False) # Name of the attribute in the Terraform resource, by default derived from model_name + type: enum('String', 'Int64', 'Float', 'Bool', 'List', 'Set', 'StringList', required=False) # Type of the attribute + data_path: list(str(), required=False) # Path to the attribute in the model structure + id: bool(required=False) # Set to true if the attribute is part of the ID + reference: bool(required=False) # Set to true if the attribute is a reference being used in the path (URL) of the REST endpoint + mandatory: bool(required=False) # Set to true if the attribute is mandatory + write_only: bool(required=False) # Set to true if the attribute is write-only, meaning we cannot read the value + write_changes_only: bool(required=False) # Set to true if the attribute should only be written (included in PUT payload) if it has changed + exclude_test: bool(required=False) # Exclude attribute from example (documentation) and acceptance test + exclude_example: bool(required=False) # Exclude attribute from acceptance test only (example/documentation is still generated) + description: str(required=False) # Attribute description + example: any(str(), int(), bool(), required=False) # Example value for documentation, also used for acceptance test + enum_values: list(str(), required=False) # List of enum values, only relevant if type is "String" + min_list: int(required=False) # Minimum number of elements in a list, only relevant if type is "List" + max_list: int(required=False) # Maximum number of elements in a list, only relevant if type is "List" + min_int: int(required=False) # Minimum value of an integer, only relevant if type is "Int64" + max_int: int(required=False) # Maximum value of an integer, only relevant if type is "Int64" + min_float: num(required=False) # Minimum value of a float, only relevant if type is "Float" + max_float: num(required=False) # Maximum value of a float, only relevant if type is "Float" + string_patterns: list(str(), required=False) # List of regular expressions that the string must match, only relevant if type is "String" + string_min_length: int(required=False) # Minimum length of a string, only relevant if type is "String" + string_max_length: int(required=False) # Maximum length of a string, only relevant if type is "String" + default_value: any(str(), int(), bool(), required=False) # Default value for the attribute + value: any(str(), int(), bool(), required=False) # Hardcoded value for the attribute + test_value: str(required=False) # Value used for acceptance test + minimum_test_value: str(required=False) # Value used for "minimum" resource acceptance test + test_tags: list(str(), required=False) # List of test tags, attribute is only included in acceptance tests if an environment variable with one of these tags is configured + attributes: list(include('attribute'), required=False) # List of attributes, only relevant if type is "List" or "Set" diff --git a/gen/templates/data_source_test.go b/gen/templates/data_source_test.go index 1ade1f6..8ae5eb8 100644 --- a/gen/templates/data_source_test.go +++ b/gen/templates/data_source_test.go @@ -38,28 +38,28 @@ func TestAccDataSourceIse{{camelCase .Name}}(t *testing.T) { var checks []resource.TestCheckFunc {{- $name := .Name }} {{- range .Attributes}} - {{- if and (not .WriteOnly) (not .ExcludeTest) (not .TfOnly) (not .Value) (not .TestValue)}} + {{- if and (not .WriteOnly) (not .ExcludeTest) (not .Value) (not .TestValue)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{- $list := .TfName }} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { {{- end}} {{- range .Attributes}} - {{- if and (not .WriteOnly) (not .ExcludeTest) (not .TfOnly) (not .Value) (not .TestValue)}} + {{- if and (not .WriteOnly) (not .ExcludeTest) (not .Value) (not .TestValue)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{- $clist := .TfName }} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { {{- end}} {{- range .Attributes}} - {{- if and (not .WriteOnly) (not .ExcludeTest) (not .TfOnly) (not .Value) (not .TestValue)}} + {{- if and (not .WriteOnly) (not .ExcludeTest) (not .Value) (not .TestValue)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{- $cclist := .TfName }} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { {{- end}} {{- range .Attributes}} - {{- if and (not .WriteOnly) (not .ExcludeTest) (not .TfOnly) (not .Value) (not .TestValue)}} + {{- if and (not .WriteOnly) (not .ExcludeTest) (not .Value) (not .TestValue)}} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { checks = append(checks, resource.TestCheckResourceAttr("data.ise_{{snakeCase $name}}.test", "{{$list}}.0.{{$clist}}.0.{{$cclist}}.0.{{.TfName}}{{if eq .Type "StringList"}}.0{{end}}", "{{.Example}}")) @@ -136,28 +136,28 @@ const testAccDataSourceIse{{camelCase .Name}}PrerequisitesConfig = ` func testAccDataSourceIse{{camelCase .Name}}Config() string { config := `resource "ise_{{snakeCase $name}}" "test" {` + "\n" {{- range .Attributes}} - {{- if and (not .ExcludeTest) (not .TfOnly) (not .Value)}} + {{- if and (not .ExcludeTest) (not .Value)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { {{- end}} config += ` {{.TfName}} = [{` + "\n" {{- range .Attributes}} - {{- if and (not .ExcludeTest) (not .TfOnly) (not .Value)}} + {{- if and (not .ExcludeTest) (not .Value)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { {{- end}} config += ` {{.TfName}} = [{` + "\n" {{- range .Attributes}} - {{- if and (not .ExcludeTest) (not .TfOnly) (not .Value)}} + {{- if and (not .ExcludeTest) (not .Value)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { {{- end}} config += ` {{.TfName}} = [{` + "\n" {{- range .Attributes}} - {{- if and (not .ExcludeTest) (not .TfOnly) (not .Value)}} + {{- if and (not .ExcludeTest) (not .Value)}} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { config += ` {{.TfName}} = {{if .TestValue}}{{.TestValue}}{{else}}{{if eq .Type "String"}}"{{.Example}}"{{else if eq .Type "StringList"}}["{{.Example}}"]{{else}}{{.Example}}{{end}}{{end}}` + "\n" diff --git a/gen/templates/model.go b/gen/templates/model.go index 90a0b03..ee71c88 100644 --- a/gen/templates/model.go +++ b/gen/templates/model.go @@ -155,10 +155,10 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context, state {{camelCase .N {{- range .Attributes}} {{- if .Value}} body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}}) - {{- else if and (not .TfOnly) (not .Reference)}} + {{- else if not .Reference}} {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}} if !data.{{toGoName .TfName}}.IsNull() {{if .WriteChangesOnly}}&& data.{{toGoName .TfName}} != state.{{toGoName .TfName}}{{end}} { - body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}data.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) + body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", data.{{toGoName .TfName}}.Value{{.Type}}()) } {{- else if eq .Type "StringList"}} if !data.{{toGoName .TfName}}.IsNull() { @@ -174,10 +174,10 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context, state {{camelCase .N {{- range .Attributes}} {{- if .Value}} itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}}) - {{- else if and (not .TfOnly) (not .Reference)}} + {{- else if not .Reference}} {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}} if !item.{{toGoName .TfName}}.IsNull() { - itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}item.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) + itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", item.{{toGoName .TfName}}.Value{{.Type}}()) } {{- else if eq .Type "StringList"}} if !item.{{toGoName .TfName}}.IsNull() { @@ -193,10 +193,10 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context, state {{camelCase .N {{- range .Attributes}} {{- if .Value}} itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}}) - {{- else if and (not .TfOnly) (not .Reference)}} + {{- else if not .Reference}} {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}} if !childItem.{{toGoName .TfName}}.IsNull() { - itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}childItem.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) + itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", childItem.{{toGoName .TfName}}.Value{{.Type}}()) } {{- else if eq .Type "StringList"}} if !childItem.{{toGoName .TfName}}.IsNull() { @@ -212,10 +212,10 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context, state {{camelCase .N {{- range .Attributes}} {{- if .Value}} itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}}) - {{- else if and (not .TfOnly) (not .Reference)}} + {{- else if not .Reference}} {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}} if !childChildItem.{{toGoName .TfName}}.IsNull() { - itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}childChildItem.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) + itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", childChildItem.{{toGoName .TfName}}.Value{{.Type}}()) } {{- else if eq .Type "StringList"}} if !childChildItem.{{toGoName .TfName}}.IsNull() { @@ -251,7 +251,7 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context, state {{camelCase .N //template:begin fromBody func (data *{{camelCase .Name}}) fromBody(ctx context.Context, res gjson.Result) { {{- range .Attributes}} - {{- if and (not .TfOnly) (not .Value) (not .WriteOnly) (not .Reference)}} + {{- if and (not .Value) (not .WriteOnly) (not .Reference)}} {{- $cname := toGoName .TfName}} {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}} if value := res.Get("{{if $openApi}}response.{{end}}{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}"); value.Exists() { @@ -276,7 +276,7 @@ func (data *{{camelCase .Name}}) fromBody(ctx context.Context, res gjson.Result) item := {{$name}}{{toGoName .TfName}}{} {{- range .Attributes}} {{- $ccname := toGoName .TfName}} - {{- if and (not .TfOnly) (not .Value) (not .WriteOnly) (not .Reference)}} + {{- if and (not .Value) (not .WriteOnly) (not .Reference)}} {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}} if cValue := v.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}"); cValue.Exists() { item.{{toGoName .TfName}} = types.{{.Type}}Value(cValue.{{if eq .Type "Int64"}}Int{{else if eq .Type "Float64"}}Float{{else}}{{.Type}}{{end}}()) @@ -299,7 +299,7 @@ func (data *{{camelCase .Name}}) fromBody(ctx context.Context, res gjson.Result) cValue.ForEach(func(ck, cv gjson.Result) bool { cItem := {{$name}}{{$cname}}{{toGoName .TfName}}{} {{- range .Attributes}} - {{- if and (not .TfOnly) (not .Value) (not .WriteOnly) (not .Reference)}} + {{- if and (not .Value) (not .WriteOnly) (not .Reference)}} {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}} if ccValue := cv.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}"); ccValue.Exists() { cItem.{{toGoName .TfName}} = types.{{.Type}}Value(ccValue.{{if eq .Type "Int64"}}Int{{else if eq .Type "Float64"}}Float{{else}}{{.Type}}{{end}}()) @@ -322,7 +322,7 @@ func (data *{{camelCase .Name}}) fromBody(ctx context.Context, res gjson.Result) ccValue.ForEach(func(cck, ccv gjson.Result) bool { ccItem := {{$name}}{{$cname}}{{$ccname}}{{toGoName .TfName}}{} {{- range .Attributes}} - {{- if and (not .TfOnly) (not .Value) (not .WriteOnly) (not .Reference)}} + {{- if and (not .Value) (not .WriteOnly) (not .Reference)}} {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}} if cccValue := ccv.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}"); cccValue.Exists() { ccItem.{{toGoName .TfName}} = types.{{.Type}}Value(cccValue.{{if eq .Type "Int64"}}Int{{else if eq .Type "Float64"}}Float{{else}}{{.Type}}{{end}}()) @@ -369,7 +369,7 @@ func (data *{{camelCase .Name}}) fromBody(ctx context.Context, res gjson.Result) //template:begin updateFromBody func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.Result) { {{- range .Attributes}} - {{- if and (not .TfOnly) (not .Value) (not .WriteOnly) (not .Reference)}} + {{- if and (not .Value) (not .WriteOnly) (not .Reference)}} {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}} if value := res.Get("{{if $openApi}}response.{{end}}{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}"); value.Exists() && !data.{{toGoName .TfName}}.IsNull() { data.{{toGoName .TfName}} = types.{{.Type}}Value(value.{{if eq .Type "Int64"}}Int{{else if eq .Type "Float64"}}Float{{else}}{{.Type}}{{end}}()) @@ -409,7 +409,7 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R ) {{- range .Attributes}} - {{- if and (not .TfOnly) (not .Value) (not .WriteOnly) (not .Reference)}} + {{- if and (not .Value) (not .WriteOnly) (not .Reference)}} {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}} if value := r.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}"); value.Exists() && !data.{{$list}}[i].{{toGoName .TfName}}.IsNull() { data.{{$list}}[i].{{toGoName .TfName}} = types.{{.Type}}Value(value.{{if eq .Type "Int64"}}Int{{else if eq .Type "Float64"}}Float{{else}}{{.Type}}{{end}}()) @@ -449,7 +449,7 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R ) {{- range .Attributes}} - {{- if and (not .TfOnly) (not .Value) (not .WriteOnly) (not .Reference)}} + {{- if and (not .Value) (not .WriteOnly) (not .Reference)}} {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}} if value := cr.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}"); value.Exists() && !data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}.IsNull() { data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}} = types.{{.Type}}Value(value.{{if eq .Type "Int64"}}Int{{else if eq .Type "Float64"}}Float{{else}}{{.Type}}{{end}}()) @@ -489,7 +489,7 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R ) {{- range .Attributes}} - {{- if and (not .TfOnly) (not .Value) (not .WriteOnly) (not .Reference)}} + {{- if and (not .Value) (not .WriteOnly) (not .Reference)}} {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}} if value := ccr.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}"); value.Exists() && !data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}.IsNull() { data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}} = types.{{.Type}}Value(value.{{if eq .Type "Int64"}}Int{{else if eq .Type "Float64"}}Float{{else}}{{.Type}}{{end}}()) diff --git a/gen/templates/resource.tf b/gen/templates/resource.tf index d587450..da83c11 100644 --- a/gen/templates/resource.tf +++ b/gen/templates/resource.tf @@ -1,21 +1,21 @@ resource "ise_{{snakeCase .Name}}" "example" { {{- range .Attributes}} -{{- if and (not .ExcludeTest) (not .ExcludeExample) (not .TfOnly) (not .Value)}} +{{- if and (not .ExcludeTest) (not .ExcludeExample) (not .Value)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{.TfName}} = [ { {{- range .Attributes}} - {{- if and (not .ExcludeTest) (not .ExcludeExample) (not .TfOnly) (not .Value)}} + {{- if and (not .ExcludeTest) (not .ExcludeExample) (not .Value)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{.TfName}} = [ { {{- range .Attributes}} - {{- if and (not .ExcludeTest) (not .ExcludeExample) (not .TfOnly) (not .Value)}} + {{- if and (not .ExcludeTest) (not .ExcludeExample) (not .Value)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{.TfName}} = [ { {{- range .Attributes}} - {{- if and (not .ExcludeTest) (not .ExcludeExample) (not .TfOnly) (not .Value)}} + {{- if and (not .ExcludeTest) (not .ExcludeExample) (not .Value)}} {{.TfName}} = {{if eq .Type "String"}}"{{.Example}}"{{else if eq .Type "StringList"}}["{{.Example}}"]{{else}}{{.Example}}{{end}} {{- end}} {{- end}} diff --git a/gen/templates/resource_test.go b/gen/templates/resource_test.go index 28e4438..e450f82 100644 --- a/gen/templates/resource_test.go +++ b/gen/templates/resource_test.go @@ -38,28 +38,28 @@ func TestAccIse{{camelCase .Name}}(t *testing.T) { var checks []resource.TestCheckFunc {{- $name := .Name }} {{- range .Attributes}} - {{- if and (not .WriteOnly) (not .ExcludeTest) (not .TfOnly) (not .Value) (not .TestValue)}} + {{- if and (not .WriteOnly) (not .ExcludeTest) (not .Value) (not .TestValue)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{- $list := .TfName }} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { {{- end}} {{- range .Attributes}} - {{- if and (not .WriteOnly) (not .ExcludeTest) (not .TfOnly) (not .Value) (not .TestValue)}} + {{- if and (not .WriteOnly) (not .ExcludeTest) (not .Value) (not .TestValue)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{- $clist := .TfName }} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { {{- end}} {{- range .Attributes}} - {{- if and (not .WriteOnly) (not .ExcludeTest) (not .TfOnly) (not .Value) (not .TestValue)}} + {{- if and (not .WriteOnly) (not .ExcludeTest) (not .Value) (not .TestValue)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{- $cclist := .TfName }} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { {{- end}} {{- range .Attributes}} - {{- if and (not .WriteOnly) (not .ExcludeTest) (not .TfOnly) (not .Value) (not .TestValue)}} + {{- if and (not .WriteOnly) (not .ExcludeTest) (not .Value) (not .TestValue)}} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { checks = append(checks, resource.TestCheckResourceAttr("ise_{{snakeCase $name}}.test", "{{$list}}.0.{{$clist}}.0.{{$cclist}}.0.{{.TfName}}{{if eq .Type "StringList"}}.0{{end}}", "{{.Example}}")) @@ -236,28 +236,28 @@ func testAccIse{{camelCase .Name}}Config_minimum() string { func testAccIse{{camelCase .Name}}Config_all() string { config := `resource "ise_{{snakeCase $name}}" "test" {` + "\n" {{- range .Attributes}} - {{- if and (not .ExcludeTest) (not .TfOnly) (not .Value)}} + {{- if and (not .ExcludeTest) (not .Value)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { {{- end}} config += ` {{.TfName}} = [{` + "\n" {{- range .Attributes}} - {{- if and (not .ExcludeTest) (not .TfOnly) (not .Value)}} + {{- if and (not .ExcludeTest) (not .Value)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { {{- end}} config += ` {{.TfName}} = [{` + "\n" {{- range .Attributes}} - {{- if and (not .ExcludeTest) (not .TfOnly) (not .Value)}} + {{- if and (not .ExcludeTest) (not .Value)}} {{- if or (eq .Type "List") (eq .Type "Set")}} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { {{- end}} config += ` {{.TfName}} = [{` + "\n" {{- range .Attributes}} - {{- if and (not .ExcludeTest) (not .TfOnly) (not .Value)}} + {{- if and (not .ExcludeTest) (not .Value)}} {{- if len .TestTags}} if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") != ""{{end}} { config += ` {{.TfName}} = {{if .TestValue}}{{.TestValue}}{{else}}{{if eq .Type "String"}}"{{.Example}}"{{else if eq .Type "StringList"}}["{{.Example}}"]{{else}}{{.Example}}{{end}}{{end}}` + "\n"