@@ -6,12 +6,12 @@ import (
66 "regexp"
77 "time"
88
9- "github.com/hashicorp/terraform/helper/resource"
10- "github.com/hashicorp/terraform/helper/schema"
11-
129 "github.com/aws/aws-sdk-go/aws"
1310 "github.com/aws/aws-sdk-go/aws/awserr"
1411 "github.com/aws/aws-sdk-go/service/cloudformation"
12+ "github.com/hashicorp/errwrap"
13+ "github.com/hashicorp/terraform/helper/resource"
14+ "github.com/hashicorp/terraform/helper/schema"
1515)
1616
1717func resourceAwsCloudFormationStack () * schema.Resource {
@@ -108,7 +108,10 @@ func resourceAwsCloudFormationStackCreate(d *schema.ResourceData, meta interface
108108 StackName : aws .String (d .Get ("name" ).(string )),
109109 }
110110 if v , ok := d .GetOk ("template_body" ); ok {
111- template , _ := normalizeJsonString (v .(string ))
111+ template , err := normalizeJsonString (v )
112+ if err != nil {
113+ return errwrap .Wrapf ("template body contains an invalid JSON: {{err}}" , err )
114+ }
112115 input .TemplateBody = aws .String (template )
113116 }
114117 if v , ok := d .GetOk ("template_url" ); ok {
@@ -130,7 +133,10 @@ func resourceAwsCloudFormationStackCreate(d *schema.ResourceData, meta interface
130133 input .Parameters = expandCloudFormationParameters (v .(map [string ]interface {}))
131134 }
132135 if v , ok := d .GetOk ("policy_body" ); ok {
133- policy , _ := normalizeJsonString (v .(string ))
136+ policy , err := normalizeJsonString (v )
137+ if err != nil {
138+ return errwrap .Wrapf ("policy body contains an invalid JSON: {{err}}" , err )
139+ }
134140 input .StackPolicyBody = aws .String (policy )
135141 }
136142 if v , ok := d .GetOk ("policy_url" ); ok {
@@ -280,7 +286,10 @@ func resourceAwsCloudFormationStackRead(d *schema.ResourceData, meta interface{}
280286 return err
281287 }
282288
283- template , _ := normalizeJsonString (* out .TemplateBody )
289+ template , err := normalizeJsonString (* out .TemplateBody )
290+ if err != nil {
291+ return errwrap .Wrapf ("template body contains an invalid JSON: {{err}}" , err )
292+ }
284293 d .Set ("template_body" , template )
285294
286295 stack := stacks [0 ]
@@ -344,7 +353,10 @@ func resourceAwsCloudFormationStackUpdate(d *schema.ResourceData, meta interface
344353 input .TemplateURL = aws .String (v .(string ))
345354 }
346355 if v , ok := d .GetOk ("template_body" ); ok && input .TemplateURL == nil {
347- template , _ := normalizeJsonString (v .(string ))
356+ template , err := normalizeJsonString (v )
357+ if err != nil {
358+ return errwrap .Wrapf ("template body contains an invalid JSON: {{err}}" , err )
359+ }
348360 input .TemplateBody = aws .String (template )
349361 }
350362
@@ -363,7 +375,10 @@ func resourceAwsCloudFormationStackUpdate(d *schema.ResourceData, meta interface
363375 }
364376
365377 if d .HasChange ("policy_body" ) {
366- policy , _ := normalizeJsonString (d .Get ("policy_body" ).(string ))
378+ policy , err := normalizeJsonString (d .Get ("policy_body" ))
379+ if err != nil {
380+ return errwrap .Wrapf ("policy body contains an invalid JSON: {{err}}" , err )
381+ }
367382 input .StackPolicyBody = aws .String (policy )
368383 }
369384 if d .HasChange ("policy_url" ) {
0 commit comments