Remove the redundant validation from the config transformers, making
sure most of the validation is now done by NodeValidatableResource.
Inset Validate calls into import tests to ensure both that existing
errors are still found, and that existing plans don't fail the new
validation code.
// we have no config and aren't generating any. This isn't caught during
// validation because generateConfigPath is only a plan option. If we
// got this far however, it means this node is eligible for config
// generation, so suggest it to the user.
diags=diags.Append(&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Configuration for import target does not exist",
Detail:fmt.Sprintf("The configuration for the given import target %s does not exist. If you wish to automatically generate config for this resource, use the -generate-config-out option within terraform plan. Otherwise, make sure the target resource exists within your configuration. For example:\n\n terraform plan -generate-config-out=generated.tf",n.Addr),
Summary:"Configuration for import target does not exist",
Detail:"The given import block is not compatible with config generation. The -generate-config-out option cannot be used with import blocks which use for_each, or resources which use for_each or count.",
// the target config exists, which is all we're looking for at this point.
continue
}
ifmoduleCfg==nil{
diags=diags.Append(&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Configuration for import target does not exist",
Detail:fmt.Sprintf("The configuration for the given import target %s does not exist. All target instances must have an associated configuration to be imported.",i.Config.ToResource),
Detail:"The given import block is not compatible with config generation. The -generate-config-out option cannot be used with import blocks which use for_each, or resources which use for_each or count.",
Subject:i.Config.To.Range().Ptr(),
})
continue
}
ifcanGenerate{
diags=diags.Append(&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Configuration for import target does not exist",
Detail:fmt.Sprintf("The configuration for the given import target %s does not exist. If you wish to automatically generate config for this resource, use the -generate-config-out option within terraform plan. Otherwise, make sure the target resource exists within your configuration. For example:\n\n terraform plan -generate-config-out=generated.tf",to),
Subject:i.Config.To.Range().Ptr(),
})
continue
}
}
diags=diags.Append(&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Configuration for import target does not exist",
Detail:fmt.Sprintf("The configuration for the given import target %s does not exist. All target instances must have an associated configuration to be imported.",i.Config.ToResource),