Reputation: 11
def publishVersion() {
def Payload = versionPayload()
def response = httpRequest(
customHeaders: [
[ name: "Authorization", value: "Bearer " + env.BEARER_TOKEN ],
[ name: "Content-Type", value: "application/vnd.api+json" ]
],
httpMode: 'POST',
requestBody: "${Payload}",
url: "https://app.terraform.io/api/v2/organizations/my-organization/registry-modules/private/my-organization/vnet/provider/versions"
)
def data = new JsonSlurper().parseText(response.content)
println ("Run Id: " + data.data.links.upload)
return data.data.links.upload
}
def UPLOAD
UPLOAD = sh(
'''curl \
--header "Content-Type: application/octet-stream" \
--request PUT \
--data-binary @module.tar.gz \
data.data.links.upload
'''
)
I am trying to create a module version in Terraform cloud. The publishVersion()
method will invoke the API call and part of the API response is a URL where the module will be uploaded. And that URL is what publishVersion()
is returning as data.data.links.upload
. The URL returned by the publishVersion()
method, I am trying to upload the module.tar.gz
to the URL by using the UPLOAD method in the last part. "it says could not resolve host."
Upvotes: 1
Views: 308
Reputation: 14574
Probably you have to do something like the below.
def URL = publishVersion()
UPLOAD = sh(
"""curl \
--header "Content-Type: application/octet-stream" \
--request PUT \
--data-binary @module.tar.gz \
${URL}
"""
)
Upvotes: 0