Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Improve config builders #3207

Merged
merged 82 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
4f9d1e3
Test the HCL v1 printing
sfc-gh-asawicki Sep 7, 2024
f0c5ba8
Experiment with V2 unsuccessfully, reverting to V1
sfc-gh-asawicki Sep 8, 2024
5379e27
Replace the test data
sfc-gh-asawicki Sep 8, 2024
5fc63e6
Split conversion and formatting
sfc-gh-asawicki Sep 8, 2024
abc5928
Add more complex test case
sfc-gh-asawicki Sep 8, 2024
04f8fbc
PoC generating configs with lists and sets
sfc-gh-asawicki Nov 15, 2024
5abe92e
Reorganized
sfc-gh-asawicki Nov 15, 2024
add6635
Extract logical parts
sfc-gh-asawicki Nov 15, 2024
17dde40
Rename and add defaults
sfc-gh-asawicki Nov 15, 2024
90f59d3
Rename json provider method
sfc-gh-asawicki Nov 17, 2024
d15f882
List missing block types
sfc-gh-asawicki Nov 17, 2024
927037b
Prepare provider block config
sfc-gh-asawicki Nov 17, 2024
b4e1ee8
Prepare provider config generator
sfc-gh-asawicki Nov 17, 2024
c28b622
Generate provider config
sfc-gh-asawicki Nov 17, 2024
bd0832c
Test provider model generation
sfc-gh-asawicki Nov 17, 2024
740ea6f
Extract to separate package
sfc-gh-asawicki Nov 17, 2024
928718b
Reorganize files in model, add datasource gen
sfc-gh-asawicki Nov 17, 2024
7f94097
Generate databases config builder
sfc-gh-asawicki Nov 17, 2024
3d15762
Add datasource generation
sfc-gh-asawicki Nov 17, 2024
204a69d
Fix block quoting
sfc-gh-asawicki Nov 17, 2024
9549b0e
Fix depends_on for datasources
sfc-gh-asawicki Nov 17, 2024
f8054f7
Unquote arguments
sfc-gh-asawicki Nov 18, 2024
8d18777
Use provider config builder instead of string ones (WIP)
sfc-gh-asawicki Nov 18, 2024
a8ae363
Add model joining
sfc-gh-asawicki Nov 18, 2024
bb69b5c
Use multi model config builder
sfc-gh-asawicki Nov 18, 2024
9cd1d5a
Inline provider building functions
sfc-gh-asawicki Nov 18, 2024
42e83b2
Try to use new config generation for view acceptance test (WIP)
sfc-gh-asawicki Nov 18, 2024
67994b9
Add fix for block types equal sign
sfc-gh-asawicki Nov 18, 2024
97b2444
Add test for single object
sfc-gh-asawicki Nov 18, 2024
db3d412
Use datasource model builder in existing test
sfc-gh-asawicki Nov 18, 2024
74c65c9
Add all missing datasources to provider/datasources
sfc-gh-asawicki Nov 18, 2024
3ac7f59
Clean up and move explore hcl test
sfc-gh-asawicki Nov 19, 2024
0df2026
Clean up hcl config provider formatters
sfc-gh-asawicki Nov 19, 2024
22b703a
Add default hcl provider test
sfc-gh-asawicki Nov 19, 2024
7ffb6d7
Improve hcl config provider tests
sfc-gh-asawicki Nov 19, 2024
3fd7318
Move poc directly to config
sfc-gh-asawicki Nov 19, 2024
47167be
Deprecate old methods
sfc-gh-asawicki Nov 19, 2024
f39a409
Add issue numbers to TODOs and add some descriptions
sfc-gh-asawicki Nov 19, 2024
ab8940d
Add missing descriptions
sfc-gh-asawicki Nov 19, 2024
9b64097
Rename interfaces and add json config provider basic tests
sfc-gh-asawicki Nov 19, 2024
1059378
Add a negative test for depends_on
sfc-gh-asawicki Nov 19, 2024
5f5375b
Update readme
sfc-gh-asawicki Nov 19, 2024
d8e0cfe
Run make pre-push
sfc-gh-asawicki Nov 19, 2024
840b928
Undeprecate the old config temporarily (until proper ignore in linter)
sfc-gh-asawicki Nov 19, 2024
157d080
Fix readme and provider test setup
sfc-gh-asawicki Nov 19, 2024
669caa1
Fix equality sign for map type params
sfc-gh-asawicki Nov 19, 2024
0e07b5f
Fix after review
sfc-gh-asawicki Nov 20, 2024
e9a70c8
Merge branch 'main' into improve-config-builders
sfc-gh-asawicki Nov 20, 2024
374b51f
Adjust config hierarchy test
sfc-gh-asawicki Nov 20, 2024
5f24aed
Progress with next tests
sfc-gh-asawicki Nov 21, 2024
9bb2347
Progress with next tests part 2
sfc-gh-asawicki Nov 21, 2024
27746eb
Remove unused asserts
sfc-gh-asawicki Nov 22, 2024
b49ef2d
Use tmp user for toml config test
sfc-gh-asawicki Nov 22, 2024
ec59063
Use tmp service user for env config test
sfc-gh-asawicki Nov 22, 2024
158d13f
Use tmp service user for tfconfig test
sfc-gh-asawicki Nov 22, 2024
b5b3048
Use tmp service user for the config hierarchy test
sfc-gh-asawicki Nov 25, 2024
4500654
Move user setup functions
sfc-gh-asawicki Nov 25, 2024
44c6c35
Get rid of only account details profile
sfc-gh-asawicki Nov 26, 2024
e3d10d8
Simplify the test set up
sfc-gh-asawicki Nov 26, 2024
ba06037
Persist toml file as part of the setup
sfc-gh-asawicki Nov 26, 2024
ecb4ed8
Use tmp service user in tests (WIP)
sfc-gh-asawicki Nov 26, 2024
68c9311
Use tmp service user in tests part 2
sfc-gh-asawicki Nov 26, 2024
660822c
Test user+pass login
sfc-gh-asawicki Nov 26, 2024
895c8e3
Test jwt login
sfc-gh-asawicki Nov 26, 2024
3227e38
Get rid of unused profiles
sfc-gh-asawicki Nov 26, 2024
f27fa3a
Clean up tmp user setup helpers
sfc-gh-asawicki Nov 26, 2024
fccf25e
Extract empty auth type
sfc-gh-asawicki Nov 26, 2024
ddbcee9
Add issue numbers
sfc-gh-asawicki Nov 26, 2024
816eaf9
Set config file temporarily
sfc-gh-asawicki Nov 26, 2024
9111355
Run pre-push
sfc-gh-asawicki Nov 26, 2024
7a59c2e
Uncomment assertions
sfc-gh-asawicki Nov 26, 2024
1526af7
Fix tests
sfc-gh-asawicki Nov 27, 2024
5253a50
Merge branch 'main' into use-service-user-for-ci
sfc-gh-asawicki Nov 28, 2024
87ef844
Fix after review
sfc-gh-asawicki Nov 28, 2024
cfbdc3d
Merge branch 'main' into improve-config-builders
sfc-gh-asawicki Nov 28, 2024
50fee2e
Merge branch 'use-service-user-for-ci' into improve-config-builders
sfc-gh-asawicki Nov 28, 2024
a9e7d5d
Generate single database data source
sfc-gh-asawicki Nov 28, 2024
b0b8b86
Add a way to handle multiline private key (WIP)
sfc-gh-asawicki Nov 28, 2024
ced7313
Generate multiline key in tf config properly (bud ugly)
sfc-gh-asawicki Nov 28, 2024
a2ecad1
Pass all other tests
sfc-gh-asawicki Nov 28, 2024
c12c11f
Merge branch 'main' into improve-config-builders
sfc-gh-asawicki Nov 28, 2024
7d49a98
Fix after merge
sfc-gh-asawicki Nov 28, 2024
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
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,20 @@ generate-resource-model-builders: ## Generate resource model builders
clean-resource-model-builders: ## Clean resource model builders
rm -f ./pkg/acceptance/bettertestspoc/config/model/*_gen.go

clean-all-assertions-and-config-models: clean-snowflake-object-assertions clean-snowflake-object-parameters-assertions clean-resource-assertions clean-resource-parameters-assertions clean-resource-show-output-assertions clean-resource-model-builders ## clean all generated assertions and config models
generate-provider-model-builders: ## Generate provider model builders
go generate ./pkg/acceptance/bettertestspoc/config/providermodel/generate.go

generate-all-assertions-and-config-models: generate-snowflake-object-assertions generate-snowflake-object-parameters-assertions generate-resource-assertions generate-resource-parameters-assertions generate-resource-show-output-assertions generate-resource-model-builders ## generate all assertions and config models
clean-provider-model-builders: ## Clean provider model builders
rm -f ./pkg/acceptance/bettertestspoc/config/providermodel/*_gen.go

generate-datasource-model-builders: ## Generate datasource model builders
go generate ./pkg/acceptance/bettertestspoc/config/datasourcemodel/generate.go

clean-datasource-model-builders: ## Clean datasource model builders
rm -f ./pkg/acceptance/bettertestspoc/config/datasourcemodel/*_gen.go

clean-all-assertions-and-config-models: clean-snowflake-object-assertions clean-snowflake-object-parameters-assertions clean-resource-assertions clean-resource-parameters-assertions clean-resource-show-output-assertions clean-resource-model-builders clean-provider-model-builders clean-datasource-model-builders ## clean all generated assertions and config models

generate-all-assertions-and-config-models: generate-snowflake-object-assertions generate-snowflake-object-parameters-assertions generate-resource-assertions generate-resource-parameters-assertions generate-resource-show-output-assertions generate-resource-model-builders generate-provider-model-builders generate-datasource-model-builders ## generate all assertions and config models

.PHONY: build-local clean-generator-poc dev-setup dev-cleanup docs docs-check fmt fmt-check fumpt help install lint lint-fix mod mod-check pre-push pre-push-check sweep test test-acceptance uninstall-tf
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/gookit/color v1.5.4
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/terraform-json v0.21.0
github.com/hashicorp/terraform-plugin-framework v1.8.0
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mO
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/hc-install v0.6.3 h1:yE/r1yJvWbtrJ0STwScgEnCanb0U9v7zp0Gbkmcoxqs=
github.com/hashicorp/hc-install v0.6.3/go.mod h1:KamGdbodYzlufbWh4r9NRo8y6GLHWZP2GBtdnms1Ln0=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI=
github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE=
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
Expand Down
82 changes: 75 additions & 7 deletions pkg/acceptance/bettertestspoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ It contains the following packages:
- resource parameters assertions (generated in subpackage `resourceparametersassert`)
- show output assertions (generated in subpackage `resourceshowoutputassert`)

- `config` - the new `ResourceModel` abstraction resides here. It provides models for objects and the builder methods allowing better config preparation in the acceptance tests.
- `config` - the new model abstractions (`ResourceModel`, `DatasourceModel`, and `ProviderModel`) reside here. They provide models for objects and the builder methods allowing better config preparation in the acceptance tests.
It aims to be more readable than using `Config:` with hardcoded string or `ConfigFile:` for file that is not directly reachable from the test body. Also, it should be easier to reuse the models and prepare convenience extension methods. The models are already generated.

## How it works
Expand Down Expand Up @@ -97,18 +97,58 @@ Resource config model builders can be generated automatically. For object `abc`
- add object you want to generate to `allResourceSchemaDefs` slice in the `assert/resourceassert/gen/resource_schema_def.go`
- to add custom (not generated) config builder methods create file `warehouse_model_ext` in the `config/model` package. Example would be:
```go
func BasicWarehouseModel(
func BasicAbcModel(
name string,
comment string,
) *WarehouseModel {
return WarehouseWithDefaultMeta(name).WithComment(comment)
) *AbcModel {
return AbcWithDefaultMeta(name).WithComment(comment)
}

func (w *WarehouseModel) WithWarehouseSizeEnum(warehouseSize sdk.WarehouseSize) *WarehouseModel {
func (w *AbcModel) WithWarehouseSizeEnum(warehouseSize sdk.WarehouseSize) *AbcModel {
return w.WithWarehouseSize(string(warehouseSize))
}
```

### Adding new datasource config model builders
Data source config model builders can be generated automatically. For object `abc` do the following:
- add object you want to generate to `allDatasourcesSchemaDefs` slice in the `config/datasourcemodel/gen/datasource_schema_def.go`
- to add custom (not generated) config builder methods create file `abc_model_ext` in the `config/datasourcemodel` package. Example would be:
```go
func BasicAbcModel(
name string,
comment string,
) *AbcModel {
return AbcWithDefaultMeta(name).WithComment(comment)
}

func (d *AbcModel) WithLimit(rows int) *AbcModel {
return d.WithLimitValue(
tfconfig.ObjectVariable(map[string]tfconfig.Variable{
"rows": tfconfig.IntegerVariable(rows),
}),
)
}
```

### Adding new provider config model builders
Provider config model builders can be generated automatically. For object `abc` do the following:
- add object you want to generate to `allProviderSchemaDefs` slice in the `config/providermodel/gen/provider_schema_def.go`
- to add custom (not generated) config builder methods create file `abc_model_ext` in the `config/providermodel` package. Example would be:
```go
func BasicAbcModel(
name string,
comment string,
) *AbcModel {
return AbcWithDefaultMeta(name).WithComment(comment)
}

func (w *AbcModel) WithWarehouseSizeEnum(warehouseSize sdk.WarehouseSize) *AbcModel {
return w.WithWarehouseSize(string(warehouseSize))
}
```

*Note*: our provider's config is already generated, so there should not be a need to generate any more providers (the regeneration or adding custom methods are still expected).

### Running the generators
Each of the above assertion types/config models has its own generator and cleanup entry in our Makefile.
You can generate config models with:
Expand Down Expand Up @@ -310,12 +350,12 @@ it will result in:
Test: TestInt_Warehouses/create:_complete
```

## Known limitations/planned improvements
## Planned improvements
- Test all the utilities for assertion/model construction (public interfaces, methods, functions).
- Verify if all the config types are supported.
- Consider a better implementation for the model conversion to config (TODO left in `config/config.go`).
- Support additional methods for references in models (TODO left in `config/config.go`).
- Support depends_on in models so that it can be chained like other resource fields (TODO left in `config/config.go`).
- Generate depends_on for all compatible models. Consider exporting it in meta (discussion: https://github.com/Snowflake-Labs/terraform-provider-snowflake/pull/3207#discussion_r1850053618).
- Add a convenience function to concatenate multiple models (TODO left in `config/config.go`).
- Add function to support using `ConfigFile:` in the acceptance tests (TODO left in `config/config.go`).
- Replace `acceptance/snowflakechecks` with the new proposed Snowflake objects assertions.
Expand Down Expand Up @@ -354,3 +394,31 @@ func (w *WarehouseDatasourceShowOutputAssert) IsEmpty() {
- utilize `ContainsExactlyInAnyOrder` function in `pkg/acceptance/bettertestspoc/assert/commons.go` to create asserts on collections that are order independent
- Additional asserts for sets and lists that wouldn't rely on the order of items saved to the state (SNOW-1706544)
- support generating provider config and use generated configs in `pkg/provider/provider_acceptance_test.go`
- add config builders for other block types (Variable, Output, Locals, Module, Terraform)
- add provider to resource/datasource models (use in the grant_ownership_acceptance_test)
- explore HCL v2 in more detail (especially struct tags generation; probably with migration to plugin framework because of schema models); ref: https://github.com/hashicorp/hcl/blob/bee2dc2e75f7528ad85777b7a013c13796426bd6/gohcl/encode_test.go#L48
- introduce some common interface for all three existing models (ResourceModel, DatasourceModel, and ProviderModel)
- rename ResourceSchemaDetails (because it is used for the datasources and provider too)
- consider duplicating the builders template from resource (currently same template used for datasources and provider which limits the customization possibilities for just one block type)
- consider merging ResourceModel with DatasourceModel (currently the implementation is really similar)
- remove schema.TypeMap workaround or make it wiser (e.g. during generation we could programmatically gather all schema.TypeMap and use this workaround only for them)

## Known limitations
- generating provider config may misbehave when used only with one object/map paramter (like `params`), e.g.:
```json
{
"provider": {
"snowflake": {
"params": {
"statement_timeout_in_seconds": 31337
}
}
}
}
```
will be converted to HCL:
```hcl
provider "snowflake" "params" {
statement_timeout_in_seconds = 31337
}
```
126 changes: 71 additions & 55 deletions pkg/acceptance/bettertestspoc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,95 @@ import (

tfconfig "github.com/hashicorp/terraform-plugin-testing/config"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources"
"github.com/stretchr/testify/require"
)

// TODO [SNOW-1501905]: add possibility to have reference to another object (e.g. WithResourceMonitorReference); new config.Variable impl?
// TODO [SNOW-1501905]: generate With/SetDependsOn for the resources to preserve builder pattern
// TODO [SNOW-1501905]: add a convenience method to use multiple configs from multiple models

// ResourceModel is the base interface all of our config models will implement.
// To allow easy implementation, ResourceModelMeta can be embedded inside the struct (and the struct will automatically implement it).
type ResourceModel interface {
Resource() resources.Resource
ResourceName() string
SetResourceName(name string)
ResourceReference() string
DependsOn() []string
SetDependsOn(values ...string)
}
// ResourceFromModel should be used in terraform acceptance tests for Config attribute to get string config from ResourceModel.
// Current implementation is an improved implementation using two steps:
// - .tf.json generation
// - conversion to HCL using hcl v1 lib
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
// It is still not ideal. HCL v2 should be considered.
func ResourceFromModel(t *testing.T, model ResourceModel) string {
t.Helper()

type ResourceModelMeta struct {
name string
resource resources.Resource
dependsOn []string
}
resourceJson, err := DefaultJsonConfigProvider.ResourceJsonFromModel(model)
require.NoError(t, err)

func (m *ResourceModelMeta) Resource() resources.Resource {
return m.resource
}
hcl, err := DefaultHclConfigProvider.HclFromJson(resourceJson)
require.NoError(t, err)
t.Logf("Generated config:\n%s", hcl)

func (m *ResourceModelMeta) ResourceName() string {
return m.name
return hcl
}

func (m *ResourceModelMeta) SetResourceName(name string) {
m.name = name
}
// DatasourceFromModel should be used in terraform acceptance tests for Config attribute to get string config from DatasourceModel.
// Current implementation is an improved implementation using two steps:
// - .tf.json generation
// - conversion to HCL using hcl v1 lib
// It is still not ideal. HCL v2 should be considered.
func DatasourceFromModel(t *testing.T, model DatasourceModel) string {
t.Helper()

func (m *ResourceModelMeta) ResourceReference() string {
return fmt.Sprintf(`%s.%s`, m.resource, m.name)
}
datasourceJson, err := DefaultJsonConfigProvider.DatasourceJsonFromModel(model)
require.NoError(t, err)

func (m *ResourceModelMeta) DependsOn() []string {
return m.dependsOn
}
hcl, err := DefaultHclConfigProvider.HclFromJson(datasourceJson)
require.NoError(t, err)
t.Logf("Generated config:\n%s", hcl)

func (m *ResourceModelMeta) SetDependsOn(values ...string) {
m.dependsOn = values
return hcl
}

// DefaultResourceName is exported to allow assertions against the resources using the default name.
const DefaultResourceName = "test"
// ProviderFromModel should be used in terraform acceptance tests for Config attribute to get string config from ProviderModel.
// Current implementation is an improved implementation using two steps:
// - .tf.json generation
// - conversion to HCL using hcl v1 lib
// It is still not ideal. HCL v2 should be considered.
func ProviderFromModel(t *testing.T, model ProviderModel) string {
t.Helper()

providerJson, err := DefaultJsonConfigProvider.ProviderJsonFromModel(model)
require.NoError(t, err)

hcl, err := DefaultHclConfigProvider.HclFromJson(providerJson)
require.NoError(t, err)
hcl, err = revertEqualSignForMapTypeAttributes(hcl)
require.NoError(t, err)

func DefaultMeta(resource resources.Resource) *ResourceModelMeta {
return &ResourceModelMeta{name: DefaultResourceName, resource: resource}
return hcl
}

func Meta(resourceName string, resource resources.Resource) *ResourceModelMeta {
return &ResourceModelMeta{name: resourceName, resource: resource}
// FromModels allows to combine multiple models.
// TODO [SNOW-1501905]: introduce some common interface for all three existing models (ResourceModel, DatasourceModel, and ProviderModel)
func FromModels(t *testing.T, models ...any) string {
t.Helper()

var sb strings.Builder
for i, model := range models {
switch m := model.(type) {
case ResourceModel:
sb.WriteString(ResourceFromModel(t, m))
case DatasourceModel:
sb.WriteString(DatasourceFromModel(t, m))
case ProviderModel:
sb.WriteString(ProviderFromModel(t, m))
default:
t.Fatalf("unknown model: %T", model)
}
if i < len(models)-1 {
sb.WriteString("\n")
}
}
return sb.String()
}

// FromModel should be used in terraform acceptance tests for Config attribute to get string config from ResourceModel.
// Current implementation is really straightforward but it could be improved and tested. It may not handle all cases (like objects, lists, sets) correctly.
// TODO [SNOW-1501905]: use reflection to build config directly from model struct (or some other different way)
// TODO [SNOW-1501905]: add support for config.TestStepConfigFunc (to use as ConfigFile); the naive implementation would be to just create a tmp directory and save file there
// TODO [SNOW-1501905]: add generating MarshalJSON() function
// TODO [SNOW-1501905]: migrate resources to new config generation method (above needed first)
// Use ResourceFromModel, DatasourceFromModel, ProviderFromModel, and FromModels instead.
func FromModel(t *testing.T, model ResourceModel) string {
t.Helper()

Expand All @@ -99,7 +124,9 @@ func FromModel(t *testing.T, model ResourceModel) string {
return s
}

func FromModels(t *testing.T, models ...ResourceModel) string {
// FromModelsDeprecated allows to combine multiple resource models.
// Use FromModels instead.
func FromModelsDeprecated(t *testing.T, models ...ResourceModel) string {
t.Helper()
var sb strings.Builder
for _, model := range models {
Expand All @@ -110,6 +137,7 @@ func FromModels(t *testing.T, models ...ResourceModel) string {

// ConfigVariablesFromModel constructs config.Variables needed in acceptance tests that are using ConfigVariables in
// combination with ConfigDirectory. It's necessary for cases not supported by FromModel, like lists of objects.
// Use ResourceFromModel, DatasourceFromModel, ProviderFromModel, and FromModels instead.
func ConfigVariablesFromModel(t *testing.T, model ResourceModel) tfconfig.Variables {
t.Helper()
variables := make(tfconfig.Variables)
Expand Down Expand Up @@ -139,15 +167,3 @@ func ConfigVariablesFromModels(t *testing.T, variableName string, models ...Reso
variableName: tfconfig.ListVariable(allVariables...),
}
}

type nullVariable struct{}

// MarshalJSON returns the JSON encoding of nullVariable.
func (v nullVariable) MarshalJSON() ([]byte, error) {
return json.Marshal(nil)
}

// NullVariable returns nullVariable which implements Variable.
func NullVariable() nullVariable {
return nullVariable{}
}
Loading
Loading