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

CredentialsPlugin should support unique credentials for different TerraformEnvironmentStages #213

Open
kmanning opened this issue Apr 8, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@kmanning
Copy link
Collaborator

kmanning commented Apr 8, 2020

@kmanning
Copy link
Collaborator Author

kmanning commented Apr 8, 2020

From @dkolb :

Overview

Currently Credentials Plugin only supports the build stage and Username/Password credentail types.

The current use case I have requires mapping credentials onto TF_VAR_blah environment variables in the environment stages. Furthermore, some of these credentials are of the string() type of DSL call. Finally, some of these credentials differ between individual environment stage.

Current Workarounds

Currently I'm moving to decorating each stage directly in the Jenkinsfile for now.

def validate   = new TerraformValidateStage()
def deployDev  = new TerraformEnvironmentStage('dev')

deployDev.decorate(TerraformEnvironmentStage.ALL, { closure ->
  withCredentials([
    usernamePassword(
      credentialsId: 'some-user'
      usernameVariable: 'TF_VAR_some_user',
      passwordVariable: 'TF_VAR_some_passord'
    ),
    string(
      credentialsId: 'some-secret',
      variable: 'TF_VAR_some_secret'
    )
  ]) {
    closure()
  }
})

validate
  .then(deployDev)
  .build()

@dkolb
Copy link
Contributor

dkolb commented Apr 9, 2020

(Migrated from the issue I didn't notice you closed)

At the risk of being less DRY perhaps credentials and environment variables should be a first-class object you apply to a particular stage instance rather than a plugin?

It seems mapping various "things" into the environment of each stage is something that needs to be directly supported through a common interface on the stages themselves than being deferred to the plugin system.

@kmanning
Copy link
Collaborator Author

kmanning commented Apr 9, 2020

I think you're right - the more I think about it, the more it feels like a first-class object.

I think you're right that decorate is currently the closest thing to such a common interface for generically modifying any stage in any arbitrary way.

I started carving out a common interface, and immediately hit a snag with TerraformEnvironmentStage - you can decorate specific areas (plan/apply), which is different from TerraformValidateStage/Build/Regression, where you basically just decorate the whole-thing/one-thing.

The common interface could be decorate(Closure closure) (ALL), and decorate(String specificPart, Closure closure), but the second method doesn't make a whole lot of sense for non-TerraformEnvironmentStages. It's not the worst thing in the world, but already is feeling 'icky'

@kmanning kmanning added the enhancement New feature or request label Jul 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants