Skip to content

Instantly share code, notes, and snippets.

View kevincloud's full-sized avatar
😎
Work, work, work...

Kevin Cochran kevincloud

😎
Work, work, work...
View GitHub Profile
curl -s \
--header "Authorization: Bearer $TOKEN" \
https://app.terraform.io/api/v2/runs/{run-id}
variable "resource_group_name" { }
variable "location" { }
variable "account_names" {
type = list(string)
description = "List of names for storage accounts"
default = [
"myaccount",
"hisaccount",
module "custom-igw" {
source = "app.terraform.io/<YOUR_TFC_ORG_NAME>/custom-igw/aws"
vpc_id = aws_vpc.primary-vpc.id
tags = var.tags
}
def getWorkspaceId() {
def response = httpRequest(
customHeaders: [
[ name: "Authorization", value: "Bearer " + env.BEARER_TOKEN ],
[ name: "Content-Type", value: "application/vnd.api+json" ]
],
url: "https://app.terraform.io/api/v2/organizations/" + env.TF_ORGNAME + "/workspaces/" + env.TF_WORKSPACE
)
def data = new JsonSlurper().parseText(response.content)
{
"data": {
"attributes": {
"is-destroy":false,
"message": "Triggered run from Jenkins"
},
"type":"runs",
"relationships": {
"workspace": {
"data": {
def startPlan() {
def payload = buildPayload()
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/runs"
def getPlanStatus(runid) {
def result = ""
def response = httpRequest(
customHeaders: [[ name: "Authorization", value: "Bearer " + env.BEARER_TOKEN ]],
url: "https://app.terraform.io/api/v2/runs/${runid}"
)
def data = new JsonSlurper().parseText(response.content)
switch (data.data.attributes.status) {
case 'pending':
result = "noop"
def overridePolicy(policyid) {
def response = httpRequest(
customHeaders: [
[ name: "Authorization", value: "Bearer " + env.BEARER_TOKEN ],
[ name: "Content-Type", value: "application/vnd.api+json" ]
],
httpMode: 'POST',
url: "https://app.terraform.io/api/v2/policy-checks/${policyid}/actions/override"
)
def data = new JsonSlurper().parseText(response.content)
def applyRun(runid) {
def response = httpRequest(
customHeaders: [
[ name: "Authorization", value: "Bearer " + env.BEARER_TOKEN ],
[ name: "Content-Type", value: "application/vnd.api+json" ]
],
httpMode: 'POST',
responseBody: '{ comment: "Apply confirmed" }',
url: "https://app.terraform.io/api/v2/runs/${runid}/actions/apply"
)