func()

in rules/terraform_heredoc_usage.go [79:103]


func (r *TerraformHeredocUsageRule) checkHeredocIsJSONOrYAML(runner tflint.Runner, heredoc string, heredocStartRange hcl.Range) error {
	prunedHereDoc := strings.ReplaceAll(heredoc, "\t", "")
	prunedHereDoc = strings.ReplaceAll(prunedHereDoc, " ", "")
	prunedHereDoc = strings.ReplaceAll(prunedHereDoc, "\n", "")
	if prunedHereDoc == "" {
		return nil
	}
	bytes := []byte(heredoc)
	if json.Valid(bytes) {
		return runner.EmitIssue(
			r,
			"for JSON, instead of HEREDOC, use a combination of a `local` and the `jsonencode` function",
			heredocStartRange,
		)
	}
	temp := map[string]interface{}{}
	if yaml.Unmarshal(bytes, &temp) == nil {
		return runner.EmitIssue(
			r,
			"for YAML, instead of HEREDOC, use a combination of a `local` and the `yamlencode` function",
			heredocStartRange,
		)
	}
	return nil
}