From 749e6ba8935fb7b591205ecbd24f308a65195784 Mon Sep 17 00:00:00 2001 From: Krzysztof Wilczynski Date: Wed, 21 Sep 2016 19:18:01 +0100 Subject: [PATCH] Handle JSON parsing error in the ReadFunc for the template body document. Signed-off-by: Krzysztof Wilczynski --- .../providers/aws/data_source_aws_cloudformation_stack.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/data_source_aws_cloudformation_stack.go b/builtin/providers/aws/data_source_aws_cloudformation_stack.go index 528c841a1..c58e5dea6 100644 --- a/builtin/providers/aws/data_source_aws_cloudformation_stack.go +++ b/builtin/providers/aws/data_source_aws_cloudformation_stack.go @@ -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 }