Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 3190
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 2, 20222022-06-02T05:18:35+00:00 2022-06-02T05:18:35+00:00

Parsing an output variable, across YAML pipeline, from a powershell script, into a Terraform variable

  • 0

[ad_1]

I have been working on a solution to send Azure alerts to Slack, using a logic app (in order to transform the output from the alert into a JSON schema that Slack can display as a message.) The logic app has been deployed as an ARM template, in order to preserve the contents of the logic app fully, while the rest of the Azure resources are being deployed by Terraform. The Terraform and ARM template is being deploying with a Azure DevOps YAML pipeline, with multiple stages. So far I have written the logic app to transform alerts into messages (the logic app posts the message when the schema has been transformed.)

My current dilemma is how to programmatically include the URL of the logic app (where the alerts should be sent) in the Terraform configuration. This is made harder by the fact that there is no config attribute for the URL in the available data blocks for logic app workflows, or for a standard logic app instance.

In order to mitigate this lack of Terraform functionality, I have attempted to retrieve the logic app URL with the Az Powershell module command (the Azure CLI doesn’t appear to have the functionality yet.) Using a short script I am able to get the url to trigger the logic app:

$logicApp = Get-AzLogicAppTriggerCallbackUrl -ResourceGroupName "logic-app-rg" -Name "mylogicapp" -TriggerName "Manual"
$url = logicApp.Value

By adding the following line, this can be added into the YAML pipeline:

write-host "##vso[task.setvariable variable=outputURL;isOutput=true]$url"

As there are multiple stages, and only 1 logic app needed, it is placed in the first stage, where core infrastructure is created (storage account for Terraform state.)

The difficulty arises when I am unable to send the data from the task that outputs the URL to a different stage which contains the terraform. The rough structure of the YAML pipeline (simplified):

stages:
- stage: infra-1
  jobs:
  - job: deploy-common-infra
    steps:
    - script: |
        cd core-infra
        terraform init
        terraform plan
        terraform apply
        $logicApp = Get-AzLogicAppTriggerCallbackUrl -ResourceGroupName "logic-app-rg" -Name "mylogicapp" -TriggerName "Manual"
        $url = logicApp.Value
        write-host "##vso[task.setvariable variable=outputURL;isOutput=true]$url"
      name: getLogicAppURL
- stage: build
  jobs:
  - job: build
    - task: build-app
- stage: infra-2
  dependsOn:
  - infrastructure-1
  variables:
    outputURL: $[stageDependencies.infra-1.deploy-common-infra.outputs['getLogicAppURL.outputURL']]
  jobs:
  - job: deploy-infra
    - script: |
        cd infra
        terraform init
        terraform plan -var="logicAppUrl="$(outputURL)""
        terraform apply

It should be noted that in the real pipeline, I am using dedicated Terraform tasks, as opposed to writing Terraform commands in scripts.

The main part of my trouble comes as I don’t want to skip the “build” stage, otherwise I won’t have an app being deployed at the last stage (excluded from the above example pipeline.) In addition, the value that is sent to terraform is “null” (there is no URL sent!)

I have used and looked at existing answers for how to share variables across jobs and stages, and while using dependencies in a pipeline, but have so far struggled to find a solution that allows me to parse the URL variable across stages. Is this the only way to parse a YAML variable across stages, into Terraform?

(An additional question might be is this the best approach to the challenge at hand, or is there a different solution that I should be attempting?)

[ad_2]

  • 0 0 Answers
  • 8 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 2 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 4 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 3 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.