use hardcoded old str as tfvars is not being changed

This commit is contained in:
Viktor Barzin 2023-05-10 17:47:59 +00:00
parent 36091ab4c2
commit 0d97747fda
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863

View file

@ -63,14 +63,17 @@ func getNewContent(gitFs *GitFS, currIp, newIp net.IP) (string, error) {
// extract old and new ip
// line example:
// bind_db_viktorbarzin_me = replace(var.bind_db_viktorbarzin_me, "<current_ip>", "<new_ip>")
lineToAdd = strings.Replace(lineToAdd, "\"", "", -1) // remove all quotes
lineToAdd = strings.Replace(lineToAdd, ")", "", -1) // remove the trailing closing bracket
splitByComma := strings.Split(lineToAdd, ",")
if len(splitByComma) != 3 {
return "", fmt.Errorf("invalid line; got: %s", line)
}
newIpStr := strings.ReplaceAll(splitByComma[2], " ", "")
lineToAdd = fmt.Sprintf(" bind_db_viktorbarzin_me = replace(var.bind_db_viktorbarzin_me, \"%s\", \"%s\")", newIpStr, newIp.String())
// lineToAdd = strings.Replace(lineToAdd, "\"", "", -1) // remove all quotes
// lineToAdd = strings.Replace(lineToAdd, ")", "", -1) // remove the trailing closing bracket
// splitByComma := strings.Split(lineToAdd, ",")
// if len(splitByComma) != 3 {
// return "", fmt.Errorf("invalid line; got: %s", line)
// }
// newIpStr := strings.ReplaceAll(splitByComma[2], " ", "")
// lineToAdd = fmt.Sprintf(" bind_db_viktorbarzin_me = replace(var.bind_db_viktorbarzin_me, \"%s\", \"%s\")", newIpStr, newIp.String())
// Since we're not changing tfvars, only update the replacement value
lineToAdd = fmt.Sprintf(" bind_db_viktorbarzin_me = replace(var.bind_db_viktorbarzin_me, \"85.130.108.6\", \"%s\")", newIp.String())
}
newLines = append(newLines, lineToAdd)
}