Handle JSON parsing error in the ReadFunc for the template body document.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
This commit is contained in:
Krzysztof Wilczynski 2016-09-21 19:18:01 +01:00
parent f1d3b21fd2
commit 749e6ba893
No known key found for this signature in database
GPG Key ID: B89F6447B63419A6
1 changed files with 5 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
)
@ -106,10 +107,11 @@ func dataSourceAwsCloudFormationStackRead(d *schema.ResourceData, meta interface
return err
}
template, _ := normalizeJsonString(*tOut.TemplateBody)
if err := d.Set("template_body", template); err != nil {
return err
template, err := normalizeJsonString(*tOut.TemplateBody)
if err != nil {
return errwrap.Wrapf("template body contains an invalid JSON: {{err}}", err)
}
d.Set("template_body", template)
return nil
}