* Enable parsing of blocks in individual files
Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>
* Enable handling of state stores when parsing a module from its constituent files.
This includes: validations of duplicates and clashes, supporting override files.
Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>
* Add tests for validation that detects conflicts between state_store blocks and others
* Add tests for state_store override behavior
* Add tests for validation that detects when conflicting state-related blocks are used, either in the same file or across separate files
* Update error message summaries to explicitly say blocks conflict
* Add small changes to assertions in state_store override tests
* Update state_store block parsing to expect scoped provider block
* Update tests following syntax change
* Make config parsing experimental
* Remove testModuleFromDirWithExperiment, as testModuleFromDirWithExperiments exists!
* Update code comment
---------
Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>
Co-authored-by: Radek Simko <radek.simko@gmail.com>
Detail:fmt.Sprintf("A module may have only one 'state_store' configuration block. The state store was previously configured at %s.",m.StateStore.DeclRange),
Summary:"Both a backend and cloud configuration are present",
Detail:fmt.Sprintf("A module may declare either one 'cloud' block OR one 'backend' block configuring a state backend. The 'cloud' block is configured at %s; a backend is configured at %s. Remove the backend block to configure HCP Terraform or Terraform Enteprise.",m.CloudConfig.DeclRange,m.Backend.DeclRange),
Subject:&m.Backend.DeclRange,
Summary:"Only one of 'cloud', 'state_store', or 'backend' configuration blocks are allowed",
Detail:fmt.Sprintf("A module may only declare one 'cloud', 'state_store' OR 'backend' block when configuring state storage. "+
"The 'cloud' block is configured at %s; a 'state_store' is configured at %s; a 'backend' is configured at %s. Remove two of these blocks.",
Summary:"Conflicting 'cloud' and 'backend' configuration blocks are present",
Detail:fmt.Sprintf("A module may declare either one 'cloud' block OR one 'backend' block for configuring state storage. "+
"The 'cloud' block is configured at %s; a 'backend' is configured at %s. Remove the 'backend' block to configure HCP Terraform or Terraform Enterprise.",
m.CloudConfig.DeclRange,m.Backend.DeclRange),
Subject:&m.Backend.DeclRange,
})
casem.CloudConfig!=nil&&m.StateStore!=nil:
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Conflicting 'cloud' and 'state_store' configuration blocks are present",
Detail:fmt.Sprintf("A module may declare either one 'cloud' block OR one 'state_store' block for configuring state storage. "+
"A 'cloud' block is configured at %s; a 'state_store' is configured at %s. Remove the 'state_store' block to configure HCP Terraform or Terraform Enterprise.",
m.CloudConfig.DeclRange,m.StateStore.DeclRange),
Subject:&m.StateStore.DeclRange,
})
casem.StateStore!=nil&&m.Backend!=nil:
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Conflicting 'state_store' and 'backend' configuration blocks are present",
Detail:fmt.Sprintf("A module may declare either one 'state_store' block OR one 'backend' block when configuring state storage. "+
"A 'state_store' block is configured at %s; a 'backend' is configured at %s. Remove one of these blocks.",
// The cloud, state_store, and backend blocks are mutually exclusive
// By setting a state_store we must unset others
m.Backend=nil
m.CloudConfig=nil
m.StateStore=file.StateStores[0]
default:
// An override file with multiple state storages is still invalid, even
// though it can override state storages from _other_ files.
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Duplicate state storage configuration",
Detail:fmt.Sprintf("Each override file may have only one state storage configuration. A state storage was previously configured at %s.",file.StateStores[0].DeclRange),
Subject:&file.StateStores[1].DeclRange,
})
}
}
iflen(file.CloudConfigs)!=0{
switchlen(file.CloudConfigs){
case1:
m.Backend=nil// A cloud block is mutually exclusive with a backend one, and overwrites any backend
// The cloud, state_store, and backend blocks are mutually exclusive
// By setting a cloud block we must unset others
m.Backend=nil
m.CloudConfig=file.CloudConfigs[0]
m.StateStore=nil
default:
// An override file with multiple cloud blocks is still invalid, even
// though it can override cloud/backend blocks from _other_ files.