azure-pipelines-tasks-terraform icon indicating copy to clipboard operation
azure-pipelines-tasks-terraform copied to clipboard

Set terraform output variables as multi-job output pipeline variables

Open charleszipp opened this issue 4 years ago • 11 comments

Set the pipeline variables generated from terraform output to be accessible across multiple jobs within a stage as documented here.

This would require setting the isOutput=true flag when setting the variable.

Currently the azure-pipelines-task-lib does not provide a means to do this. See this issue. However, if can write the task.setvariable command manually to stdout then this should still be possible.

This should include the TERRAFORM_PLAN_HAS_CHANGES variable produced when running terraform plan with detailed exit code.

charleszipp avatar May 20 '20 16:05 charleszipp

I'm guessing this is why I'm seeing this?

Evaluating: and(succeeded(), eq(variables['TERRAFORM_PLAN_HAS_CHANGES'], 'true'))
Expanded: and(True, eq(Null, 'true'))
Result: False

FernandoMiguel avatar Apr 16 '21 16:04 FernandoMiguel

yeah i saw that. i'll link the code to this ticket and wait it gets fixed before re-enabling

FernandoMiguel avatar Apr 16 '21 16:04 FernandoMiguel

After a quick look into the azure-pipeline-task-lib repo it does look like functionality was added to the setVariable method to allow output variables starting with version 2.12.0 so it should be possible to implement this natively now. Ref: https://github.com/microsoft/azure-pipelines-task-lib/pull/691

OmnipotentOwl avatar May 14 '21 16:05 OmnipotentOwl

Thanks for pointing this out @OmnipotentOwl!

charleszipp avatar May 14 '21 16:05 charleszipp

see PR #31

DenWin avatar May 16 '21 02:05 DenWin

There would be 2 options - either to add a parameter to switch between variables and outputs - though in that case I would only have one or the other. A better option - in my opinion - would be to use an additional name for the output variables, e.g. to suffix them

DenWin avatar May 26 '21 17:05 DenWin

It should also be possible to get the output variable of a specific job. For example: I've got a pipeline with multiple generated plans splitted into multiple jobs. AFAIK there's no way to get TERRAFORM_PLAN_HAS_CHANGES from job X.

dsfrederic avatar Apr 14 '22 06:04 dsfrederic

That feature has been reverted last year and has not been reimplemented, yet or did I miss any parameter to activate it?

Michaelvsk avatar May 12 '22 12:05 Michaelvsk

Indeed, this would be nice.

I'm resorting to adding a step directly after, that just sets another variable with isOutput=true :(

terrymunro avatar May 29 '23 08:05 terrymunro

Hello, Are there any changes in this question? Realy helpful thing)

mdanylyuk avatar Jul 21 '23 10:07 mdanylyuk

This is planned but a workaround is shown here .

jason-johnson avatar Jul 21 '23 14:07 jason-johnson