Skip to content

Conversation

@floatingman
Copy link

Introduce shared library functions for Tofu and Ansible operations, enabling execution within Docker containers. Enhance AWS credentials handling and SSH key management for improved security and functionality. Implement infrastructure helpers for configuration management and workspace handling.

- Add tofu.groovy: Functions for backend init, workspace management, apply/destroy
- Add ansible.groovy: Functions for running playbooks and managing inventory
- Add infrastructure.groovy: Helper functions for config, SSH keys, and workspace naming
- Update tofu.groovy to execute all commands in Docker
- Update ansible.groovy runPlaybook to use Docker
- Pass AWS credentials as environment variables to container
- Mount workspace and SSH keys into container
- Fixes 'tofu: not found' error on Jenkins agents
- Remove invalid steps.env access that caused MissingPropertyException
- AWS credentials now inherited from withCredentials block via -e flags
- Docker run automatically picks up AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from environment
- Fixes 'No such property: env for class: org.jenkinsci.plugins.workflow.cps.DSL' error
Copy link

@slickwarren slickwarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not very well versed in this but I don't see anything standing out as an issue. Would like the main contributor's review just in case we miss something.

}

// Run the init-backend.sh script which generates backend.tf and runs tofu init
def initCommand = "cd ${config.dir} && ./scripts/init-backend.sh ${scriptArgs.join(' ')}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a fan of this being hard-coded, do we do this anywhere else in the shared lib?

what about something like this instead?

if (params?.configureScript) {
// by doing this we accept all build and configure going to run from dir, 'docker build .', currently target is in validation dir so this is necessary
def statusConfigure = steps.sh(script: "./${params.dir}/${params?.configureScript}", returnStatus: true)
if (statusConfigure != 0) {
error "Build script failed with ${statusBuild}"
}
}
def statusBuild = steps.sh(script: "./${params.dir}/${params.buildScript}", returnStatus: true)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing the problem as it's only designed to run the init-backend script.

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

Successfully merging this pull request may close these issues.

3 participants