func readableTerraformPolicyChangesWithDiffer()

in astro/terraform/policy_diff.go [120:156]


func readableTerraformPolicyChangesWithDiffer(differ, terraformChanges string) (string, error) {
	result := ""
	var errs error
	for _, line := range strings.Split(terraformChanges, "\n") {
		// Check if the line matches a Terraform policy diff
		changeGroups := terraformPolicyChangeLine.FindStringSubmatch(line)
		addGroups := terraformPolicyAddLine.FindStringSubmatch(line)
		if changeGroups == nil && addGroups == nil {
			// If it doesn't match, just print the line verbatim and move on
			result += line
			result += "\n"
			continue
		}

		// Get a readable diff from the policy change
		var difftext []byte
		var err error
		if changeGroups != nil {
			difftext, err = terraformPolicyChangeToDiff(differ, changeGroups[1], changeGroups[2])
		} else {
			difftext, err = terraformPolicyChangeToDiff(differ, "", addGroups[1])
		}
		if err != nil {
			errs = multierror.Append(errs, err)
			result += line
			result += "\n"
			continue
		}

		// Output a readable diff
		result += "\n"
		result += string(tail(difftext, 2, true))
		result += "\n"
	}

	return result, errs
}