I have a terraform script something like below.
resource "aws_sfn_state_machine" "sfn_state_machine" {
name = "my-state-machine"
role_arn = aws_iam_role.iam_for_sfn.arn
definition = <<EOF
{
"Comment": "A Hello World example of the Amazon States Language using an AWS Lambda Function",
"StartAt": "HelloWorld",
"States": {
"HelloWorld": {
"Type": "Task",
"Resource": "${aws_lambda_function.lambda.arn}",
"End": true
}
}
}
EOF
}
Now, I want to update the definition from my java code.
so 1st I'm able to parse the code with HCL4j library and gave me the data is Map Structure. below is the code to parse and get the data in Map:
File terraformFile = new File("./terraform.tf");
Map<String, Map<String, Map<String, Map<String, Object>>>> map = new HCLParser().parse(terraformFile, "UTF-8");
After this I have updated the content little bit, but don't have any clue to update back to terraform script.
So any Idea, how to convert back from Java object to terraform script again?