Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin Initialization Order Effects are Uncodumented #206

Closed
dkolb opened this issue Mar 25, 2020 · 2 comments · Fixed by #239
Closed

Plugin Initialization Order Effects are Uncodumented #206

dkolb opened this issue Mar 25, 2020 · 2 comments · Fixed by #239
Assignees
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@dkolb
Copy link
Contributor

dkolb commented Mar 25, 2020

Update

Updating this issue to a documentation issue and will open a PR Soon ™️ with updates to the relevant sections of README.md. Essentially we should just document that plugins are initialized in an "inside out" order where the last plugin initialized will have it's decorations wrapping all other plugin decorations. Specifically we should call out that TerraformEnvironmentStage.withGlobalEnv(String, String) should be the last thing you do so that your environment variables are available to all other variables.

Original Issue

// Jenkinsfile
@Library(['terraform-pipeline-modern', 'pingfederate-pipeline-customizations']) _

Jenkinsfile.init(this)
Jenkinsfile.declarative = true
Jenkinsfile.pipelineTemplate = this.PingFederatePipelineTemplateLowers
Jenkinsfile.defaultNodeName = 'tfenv'

TerraformEnvironmentStage.withGlobalEnv('AWS_ROLE_ARN', 'role::arn::here')

WithAwsPlugin.init()

This will result in withAWS being skipped due to the withEnv from the EnvironmentVariablePlugin's decorations being after withGlobalEnv.

Workarounds are to directly manipulate env at the top of your file:

env.PERF_AWS_ROLE_ARN = env.PROD_AWS_ROLE_ARN

I'm not sure if we should fix this or just update documentation on the withAWS plugin page.

@dkolb dkolb changed the title WithAwsPlugin Decorations Apply Before Global Environments WithAwsPlugin Decorations Apply Before EnvironmentVariablePlugin (via withGlobalEnv(String, String)) Mar 25, 2020
@dkolb dkolb changed the title WithAwsPlugin Decorations Apply Before EnvironmentVariablePlugin (via withGlobalEnv(String, String)) WithAwsPlugin Decorations Apply Before EnvironmentVariablePlugin Mar 25, 2020
@kmanning
Copy link
Collaborator

kmanning commented Mar 25, 2020

Hrm, I expected a question of this form to come up at some point.

The plugins are ordered, which means you SHOULD be able to solve nesting issues like this by simply reordering your calls.

Meaning, instead of doing this, which will nest the environment variables inside of the WithAwsPlugin:

TerraformEnvironmentStage.withGlobalEnv('AWS_ROLE_ARN', 'role::arn::here')

WithAwsPlugin.init()

You can simply flip your calls to nest it the other way:

WithAwsPlugin.init()

TerraformEnvironmentStage.withGlobalEnv('AWS_ROLE_ARN', 'role::arn::here')

Does this NOT work?

@dkolb dkolb self-assigned this May 9, 2020
@dkolb dkolb added the documentation Improvements or additions to documentation label May 9, 2020
@dkolb dkolb changed the title WithAwsPlugin Decorations Apply Before EnvironmentVariablePlugin Plugin Initialization Order Effects are Uncodumented May 9, 2020
@kmanning kmanning added this to the v5.8 milestone May 29, 2020
@kmanning
Copy link
Collaborator

kmanning commented Jul 7, 2020

So it dawned on me - EnvironmentVariablePlugin came later, and was never documented. I'm gonna add EnvironmentVariablePlugin to the list of plugins, then use it to describe exactly what you did above. Then the example that you're describing will use 2 plugins, and can be used to illustrate the importance of order when initializing plugins. PR on the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants