I need to send current terraform run details through sentinel policy to Jira ticket as a comment
I’m trying using tfrun import for run details and HTTP import to add comments to the Jira ticket.
But I am unable to do that. Can someone help me?
error calling function “post”: expected status code to be one of [200], got 400
@hcrhall Can you please share with me an example?
@hemanth
Take a look at the following:
import "http"
import "json"
breakdown = func(plan, token) {
body = string(
"--TerraformPlan\r\n" +
"Content-Disposition: form-data; name=\"path\"; filename=\"plan.json\"\r\nContent-Type: \"application/json\"\r\n" +
"\r\n" + json.marshal(plan) + "\r\n" +
"--TerraformPlan\r\n" +
"Content-Disposition: form-data; name=\"format\"\r\n" +
"\r\njson\r\n" +
"--TerraformPlan--")
request = http.request("https://pricing.api.infracost.io/breakdown").
with_header("x-api-key", token).
with_header("Content-Type", "multipart/form-data;boundary=TerraformPlan").
with_body(body)
response = http.post(request)
This file has been truncated. show original
Hope this helps.
Regards,
RH.
@hcrhall Thanks for your response.
I’m testing using the below code. Still getting the 400 error. Is there anything I’m doing wrong?
breakdown = func() {
body = string("Comment added when resolving issue")
request = http.request("https://{jira}/rest/api/2/issue/{issuekey}/comment").
with_basic_auth(jira_user, jira_pass).
with_header("Content-Type", "application/json").
with_body(body)
response = http.post(request)
return json.unmarshal(response.body)
}
error calling function “post”: expected status code to be one of [200], got 400
I’m able to do the same through curl command.
Able to resolve it. Thanks
@hemanth
Can you share the solution so other folks know how the enable this use case with Sentinel?
Thanks!