Documentation
¶
Index ¶
- Constants
- Variables
- func ConfigVariablesFromModel(t *testing.T, model ResourceModel) tfconfig.Variables
- func ConfigVariablesFromModels(t *testing.T, variableName string, models ...ResourceModel) tfconfig.Variables
- func DatasourceFromModel(t *testing.T, model DatasourceModel) string
- func EmptyListVariable() emptyListVariable
- func FromModels(t *testing.T, models ...any) string
- func MultilineWrapperVariable(content string) multilineWrapperVariable
- func ProviderFromModel(t *testing.T, model ProviderModel) string
- func ReplacementPlaceholderVariable(placeholder ReplacementPlaceholder) replacementPlaceholderVariable
- func ResourceFromModel(t *testing.T, model ResourceModel) string
- type DatasourceModel
- type DatasourceModelMeta
- func (m *DatasourceModelMeta) Datasource() datasources.Datasource
- func (m *DatasourceModelMeta) DatasourceName() string
- func (m *DatasourceModelMeta) DatasourceReference() string
- func (m *DatasourceModelMeta) DependsOn() []string
- func (m *DatasourceModelMeta) SetDatasourceName(name string)
- func (m *DatasourceModelMeta) SetDependsOn(values ...string)
- type DynamicBlock
- type DynamicBlockContent
- type HclConfigProvider
- type HclFormatter
- type JsonConfigProvider
- type ProviderModel
- type ProviderModelMeta
- type ReplacementPlaceholder
- type ResourceModel
- type ResourceModelMeta
- func (m *ResourceModelMeta) DependsOn() []string
- func (m *ResourceModelMeta) Resource() resources.Resource
- func (m *ResourceModelMeta) ResourceName() string
- func (m *ResourceModelMeta) ResourceReference() string
- func (m *ResourceModelMeta) SetDependsOn(values ...string)
- func (m *ResourceModelMeta) SetResourceName(name string)
Constants ¶
const DefaultDatasourceName = "test"
DefaultDatasourceName is exported to allow assertions against the resources using the default name.
const DefaultResourceName = "test"
DefaultResourceName is exported to allow assertions against the resources using the default name.
Variables ¶
var DefaultHclConfigProvider = NewHclV1ConfigProvider(replaceNullPlaceholders, removeSingleAttributeWorkaroundLines, unquoteBlockType, fixBlockArguments, unquotePlaceholders, quotePlaceholders, replaceMultilinePlaceholders, unquoteArguments, removeDoubleNewlines, unquoteDependsOnReferences)
var DefaultJsonConfigProvider = NewBasicJsonConfigProvider()
Functions ¶
func ConfigVariablesFromModel ¶ added in v0.96.0
func ConfigVariablesFromModel(t *testing.T, model ResourceModel) tfconfig.Variables
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 ConfigVariablesFromModels ¶ added in v0.99.0
func ConfigVariablesFromModels(t *testing.T, variableName string, models ...ResourceModel) tfconfig.Variables
ConfigVariablesFromModels can be used to create a list of objects that are referring to the same resource model. It's useful when there's a need to create associations between objects of the same type in Snowflake.
func DatasourceFromModel ¶ added in v1.0.0
func DatasourceFromModel(t *testing.T, model DatasourceModel) string
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 EmptyListVariable ¶ added in v1.0.1
func EmptyListVariable() emptyListVariable
EmptyListVariable returns Variable representing an empty list. This is because the current hcl parser handles empty SetVariable incorrectly.
func FromModels ¶ added in v0.98.0
FromModels should be used in terraform acceptance tests for Config attribute to get string config from all models. FromModels allows to combine multiple model types. TODO [SNOW-1501905]: introduce some common interface for all three existing models (ResourceModel, DatasourceModel, and ProviderModel)
func MultilineWrapperVariable ¶ added in v1.0.1
func MultilineWrapperVariable(content string) multilineWrapperVariable
MultilineWrapperVariable returns Variable containing multiline content wrapped with SnowflakeProviderConfigMultilineMarker later replaced by HclFormatter.
func ProviderFromModel ¶ added in v1.0.0
func ProviderFromModel(t *testing.T, model ProviderModel) string
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 ReplacementPlaceholderVariable ¶ added in v1.0.1
func ReplacementPlaceholderVariable(placeholder ReplacementPlaceholder) replacementPlaceholderVariable
ReplacementPlaceholderVariable returns Variable containing one of the ReplacementPlaceholder which is later replaced by HclFormatter.
func ResourceFromModel ¶ added in v1.0.0
func ResourceFromModel(t *testing.T, model ResourceModel) 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 It is still not ideal. HCL v2 should be considered.
Types ¶
type DatasourceModel ¶ added in v1.0.0
type DatasourceModel interface {
Datasource() datasources.Datasource
DatasourceName() string
SetDatasourceName(name string)
DatasourceReference() string
DependsOn() []string
SetDependsOn(values ...string)
}
DatasourceModel is the base interface all of our datasource config models will implement. To allow easy implementation, DatasourceModelMeta can be embedded inside the struct (and the struct will automatically implement it). TODO [SNOW-1501905]: consider merging ResourceModel with DatasourceModel (currently the implementation is really similar)
type DatasourceModelMeta ¶ added in v1.0.0
type DatasourceModelMeta struct {
// contains filtered or unexported fields
}
func DatasourceDefaultMeta ¶ added in v1.0.0
func DatasourceDefaultMeta(datasource datasources.Datasource) *DatasourceModelMeta
func DatasourceMeta ¶ added in v1.0.0
func DatasourceMeta(resourceName string, datasource datasources.Datasource) *DatasourceModelMeta
func (*DatasourceModelMeta) Datasource ¶ added in v1.0.0
func (m *DatasourceModelMeta) Datasource() datasources.Datasource
func (*DatasourceModelMeta) DatasourceName ¶ added in v1.0.0
func (m *DatasourceModelMeta) DatasourceName() string
func (*DatasourceModelMeta) DatasourceReference ¶ added in v1.0.0
func (m *DatasourceModelMeta) DatasourceReference() string
func (*DatasourceModelMeta) DependsOn ¶ added in v1.0.0
func (m *DatasourceModelMeta) DependsOn() []string
func (*DatasourceModelMeta) SetDatasourceName ¶ added in v1.0.0
func (m *DatasourceModelMeta) SetDatasourceName(name string)
func (*DatasourceModelMeta) SetDependsOn ¶ added in v1.0.0
func (m *DatasourceModelMeta) SetDependsOn(values ...string)
type DynamicBlock ¶ added in v1.1.0
type DynamicBlock map[string]DynamicBlockContent
func NewDynamicBlock ¶ added in v1.1.0
func NewDynamicBlock(label string, variableName string, values []string) *DynamicBlock
NewDynamicBlock is a quick and dirty implementation to add dynamic blocks to our config builders. Dynamic blocks look like this:
dynamic "<label_name>" {
for_each = var.<variable_name>
content {
name = argument.value["name"]
type = argument.value["type"]
}
}
which in JSON would look like (<...> mark the fields with dynamic names):
{
"dynamic": {
"<label_name>": {
"for_each": "var.<variable_name>",
"content": {
"<arg1_name>": "<label_name>.value[\"<arg1_name>\"]",
"<arg2_name>": "<label_name>.value[\"<arg2_name>\"]"
...
"<argN_name>": "<label_name>.value[\"<argN_name>\"]"
}
}
}
}
The main complexity with our struct -> json -> hcl -> formatted hcl approach is that in JSON all string values are quoted. We need to unquote them and unescape the escaped quotes inside the quoted value. We use the SnowflakeProviderConfigUnquoteMarker and SnowflakeProviderConfigQuoteMarker to apply this formatting.
type DynamicBlockContent ¶ added in v1.1.0
type HclConfigProvider ¶ added in v1.0.0
HclConfigProvider defines methods to generate .tf config from .tf.json configs.
func NewHclV1ConfigProvider ¶ added in v1.0.0
func NewHclV1ConfigProvider(formatters ...HclFormatter) HclConfigProvider
type HclFormatter ¶ added in v1.0.0
type JsonConfigProvider ¶ added in v1.0.0
type JsonConfigProvider interface {
ResourceJsonFromModel(model ResourceModel) ([]byte, error)
DatasourceJsonFromModel(model DatasourceModel) ([]byte, error)
ProviderJsonFromModel(model ProviderModel) ([]byte, error)
}
JsonConfigProvider defines methods to generate .tf.json configs. TODO [SNOW-1501905]: add config builders for other block types (Variable, Output, Localsl, Module, Terraform)
func NewBasicJsonConfigProvider ¶ added in v1.0.0
func NewBasicJsonConfigProvider() JsonConfigProvider
type ProviderModel ¶ added in v1.0.0
ProviderModel is the base interface all of our provider config models will implement. To allow easy implementation, ProviderModelMeta can be embedded inside the struct (and the struct will automatically implement it).
type ProviderModelMeta ¶ added in v1.0.0
type ProviderModelMeta struct {
// contains filtered or unexported fields
}
func DefaultProviderMeta ¶ added in v1.0.0
func DefaultProviderMeta(name string) *ProviderModelMeta
func ProviderMeta ¶ added in v1.0.0
func ProviderMeta(name string, alias string) *ProviderModelMeta
func (*ProviderModelMeta) Alias ¶ added in v1.0.0
func (m *ProviderModelMeta) Alias() string
func (*ProviderModelMeta) ProviderName ¶ added in v1.0.0
func (m *ProviderModelMeta) ProviderName() string
type ReplacementPlaceholder ¶ added in v1.0.0
type ReplacementPlaceholder string
const ( SnowflakeProviderConfigNull ReplacementPlaceholder = "SF_TF_TEST_NULL_PLACEHOLDER" SnowflakeProviderConfigMultilineMarker ReplacementPlaceholder = "SF_TF_TEST_MULTILINE_MARKER_PLACEHOLDER" SnowflakeProviderConfigSingleAttributeWorkaround ReplacementPlaceholder = "SF_TF_TEST_SINGLE_ATTRIBUTE_WORKAROUND" SnowflakeProviderConfigUnquoteMarker ReplacementPlaceholder = "SF_TF_TEST_UNQUOTE_MARKER" SnowflakeProviderConfigQuoteMarker ReplacementPlaceholder = "SF_TF_TEST_QUOTE_MARKER" )
type ResourceModel ¶
type ResourceModel interface {
Resource() resources.Resource
ResourceName() string
SetResourceName(name string)
ResourceReference() string
DependsOn() []string
SetDependsOn(values ...string)
}
ResourceModel is the base interface all of our resource config models will implement. To allow easy implementation, ResourceModelMeta can be embedded inside the struct (and the struct will automatically implement it).
type ResourceModelMeta ¶
type ResourceModelMeta struct {
// contains filtered or unexported fields
}
func DefaultMeta ¶
func DefaultMeta(resource resources.Resource) *ResourceModelMeta
func (*ResourceModelMeta) DependsOn ¶ added in v0.95.0
func (m *ResourceModelMeta) DependsOn() []string
func (*ResourceModelMeta) Resource ¶
func (m *ResourceModelMeta) Resource() resources.Resource
func (*ResourceModelMeta) ResourceName ¶
func (m *ResourceModelMeta) ResourceName() string
func (*ResourceModelMeta) ResourceReference ¶ added in v0.95.0
func (m *ResourceModelMeta) ResourceReference() string
func (*ResourceModelMeta) SetDependsOn ¶ added in v0.95.0
func (m *ResourceModelMeta) SetDependsOn(values ...string)
func (*ResourceModelMeta) SetResourceName ¶
func (m *ResourceModelMeta) SetResourceName(name string)