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

Fix ordering between withEnv and plugins #142

Closed
kmanning opened this issue Sep 3, 2019 · 0 comments
Closed

Fix ordering between withEnv and plugins #142

kmanning opened this issue Sep 3, 2019 · 0 comments

Comments

@kmanning
Copy link
Collaborator

kmanning commented Sep 3, 2019

  • withEnv immediately adds a decoration to TerraformEnvironmentStages
  • Plugins may additionally add decorations, but they aren't applied until the build() method is called
  • This guarantees that plugin decorations always wrap withEnv environment variables

In pseudocode, it roughly plays out like this:

Plugin1.init()
Plugin2.init()

deployQa.withEnv(MY_VAR, 'value')

which roughly leads to:

plugin2 {
    plugin1 {
        withEnv(MY_VAR=value) {
            terraform command
        }
    }
}

This outcome doesn't change regardless of how you order your code:

Plugin1.init()
deployQa.withEnv(MY_VAR, 'value')
Plugin2.init()
deployQa.withEnv(MY_VAR, 'value')
Plugin1.init()
Plugin2.init()

This is important, because some plugins can be configured by environment variables. If the environment variables don't exist until after the plugin is applied, then the plugins can't be configured with withEnv.

plugin2 {
    // I do a thing that expected MY_VAR to be set - it is not yet set
    plugin1 {
        // I do a thing that expected MY_VAR to be set - it is not yet set
        withEnv(MY_VAR=value) {
            // Only now is MY_VAR set, but it's too late now
            terraform command
        }
    }
}

A better, and less surprising implementation, would be to apply withEnv decorations in the same order in which they are called, relative to plugins. Eg:

Plugin1.init()
Plugin2.init()
deployQa.withEnv(MY_VAR, 'value')

Should result in

withEnv(MY_VAR=value) {
    plugin2 {
        plugin1 {
            terraform command
        }
    }
}

=====

Plugin1.init()
deployQa.withEnv(MY_VAR, 'value')
Plugin2.init()

Should result in

plugin2 {
    withEnv(MY_VAR=value) {
        plugin1 {
            terraform command
        }
    }
}

=====

deployQa.withEnv(MY_VAR, 'value')
Plugin1.init()
Plugin2.init()

Should result in

plugin2 {
    plugin1 {
        withEnv(MY_VAR=value) {
            terraform command
        }
    }
}
@kmanning kmanning closed this as completed Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant