// No specified out file, so don't write anything.
return nil
returnfalse,nil
}
diags:= ValidateTargetFile(out)
diags= ValidateTargetFile(out)
ifdiags.HasErrors(){
returndiags
returnfalse,diags
}
varwriterio.Writer
for_,change:=rangeplan.Changes.Resources{
iflen(change.GeneratedConfig)>0{
ifwriter==nil{
// Lazily create the generated file, in case we have no
// generated config to create.
@ -47,14 +46,14 @@ func MaybeWriteGeneratedConfig(plan *plans.Plan, out string) tfdiags.Diagnostics
tfdiags.Error,
"Failed to create target generated file",
fmt.Sprintf("Terraform did not have permission to create the generated file (%s) in the target directory. Please modify permissions over the target directory, and try again.",out)))
returndiags
returnfalse,diags
}
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Failed to create target generated file",
fmt.Sprintf("Terraform could not create the generated file (%s) in the target directory: %v. Depending on the error message, this may be a bug in Terraform itself. If so, please report it!",out,err)))
returndiags
returnfalse,diags
}
header:="# __generated__ by Terraform\n# Please review these resources and move them into your main configuration files.\n"
@ -74,8 +73,9 @@ func MaybeWriteGeneratedConfig(plan *plans.Plan, out string) tfdiags.Diagnostics
"Failed to save generated config",
fmt.Sprintf("Terraform encountered an error while writing generated config: %v. The config for %s must be created manually before applying. Depending on the error message, this may be a bug in Terraform itself. If so, please report it!",err,change.Addr.String())))