-
Notifications
You must be signed in to change notification settings - Fork 224
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
ADF terraform extension #397
Conversation
…lobal.yml and regional.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, thanks!
I have one main observation though.
In the deployment map we define the targets of the pipeline as a property of the deploy provider
environment_variables: TARGET_ACCOUNTS: 111111111111,222222222222 # target accounts TARGET_OUS: /core/infrastructure,/sandbox # target OUs MASTER_ACCOUNT_ID: 333333333333 # master account REGIONS: eu-west-1 # target regions
And configure the deployment provider with the use of the target configuration
targets: - name: terraform-scan # optional properties: spec_filename: tf_scan.yml # terraform scan - name: terraform-plan properties: spec_filename: tf_plan.yml # terraform plan - approval # manual approval - name: terraform-apply properties: spec_filename: tf_apply.yml # terraform apply
This means that you've had to write duplicate logic for getting accounts etc.
Would it not make more sense to actually make a new terraform pipeline type that reuses the existing code for resolving targets and passes that information into your deploy provider?
...ebase/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/get_accounts.py
Outdated
Show resolved
Hide resolved
...ebase/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/get_accounts.py
Outdated
Show resolved
Hide resolved
...ebase/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/get_accounts.py
Outdated
Show resolved
Hide resolved
...ebase/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/get_accounts.py
Outdated
Show resolved
Hide resolved
...ebase/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/get_accounts.py
Outdated
Show resolved
Hide resolved
...ebase/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/get_accounts.py
Outdated
Show resolved
Hide resolved
...ebase/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/get_accounts.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing these changes.
There are some comments in here that need to be fixed before we can merge it.
Please reach out directly if anything is unclear or if help is needed.
...base/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/adf_terraform.sh
Outdated
Show resolved
Hide resolved
...base/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/adf_terraform.sh
Outdated
Show resolved
Hide resolved
...base/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/adf_terraform.sh
Outdated
Show resolved
Hide resolved
...base/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/adf_terraform.sh
Outdated
Show resolved
Hide resolved
...base/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/adf_terraform.sh
Outdated
Show resolved
Hide resolved
Co-authored-by: Stewart Wallace <[email protected]>
…ild/shared/helpers/terraform/get_accounts.py Co-authored-by: Stewart Wallace <[email protected]>
…ild/shared/helpers/terraform/get_accounts.py clean comments Co-authored-by: Stewart Wallace <[email protected]>
…ild/shared/helpers/terraform/get_accounts.py Co-authored-by: Stewart Wallace <[email protected]>
…ild/shared/helpers/terraform/get_accounts.py clean comments Co-authored-by: Stewart Wallace <[email protected]>
…ild/shared/helpers/terraform/get_accounts.py Co-authored-by: Stewart Wallace <[email protected]>
…ild/shared/helpers/terraform/get_accounts.py Co-authored-by: Stewart Wallace <[email protected]>
src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/deployment/regional.yml
Show resolved
Hide resolved
src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/main.py
Outdated
Show resolved
Hide resolved
src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/tests/test_config.py
Outdated
Show resolved
Hide resolved
…into stemons-master
...ase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codebuild.py
Outdated
Show resolved
Hide resolved
This is already available at: src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/paginator.py
The default CodeBuild container image to use cannot be changed without introducing a breaking change. A breaking change would imply a major version release. Since we are adding TF support in v3.2.0, a minor version release, we cannot modify this yet. It is on the roadmap though for the next major release :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for contributing!
Issue #, if available:
Description of changes:
This PR enables ADF to run terraform pipelines multi-accounts/OUs and multi-regions and manages in a structured way terraform state file and lock.
Terraform module includes:
adf_terraform.sh
: this script:sample-terraform
: this folder contains an example of terraform pipelines definition and repositoryadf_terraform_role
: additional role added during the bootstrap of an account to deploy terraform resourcesadf_locktable
: regional DynamoDB to manage the lock of the state fileAn overview of the terraform template components and functionalities
Overview
This repository contains a module that manage the deployment of terraform code to multiple accounts and regions.
The module consists of three build stages defined in the following file:
buildspec.yml
: install the version of terraform specified in the pipeline configurationtf_scan.yml
: (optional) returns any vulnerabilities in terraform code according with terrascan utilitiytf_plan.yml
: get the list of accounts from the organization and run a terraform plantf_apply.yml
: run a terraform apply after the manual step approvalParameters
Deployment procedure
deployment-map.yml
as in the example:Add the project name in params/global.yml file
Add terraform code to the
tf
folder. Do not make changes tobackend.tf
file andmain.tf
.Add variable definition to tf\variables.tf file and variable values to tfvars/global.auto.tfvars
Local variables (per account) can be configured using the following naming convention
Push to sample-terraform ADF repository
Pipeline contains a manual step approval between terraform plan and terraform apply. Confirm to proceed.
Terraform state files are stored in the regional S3 buckets in the deployment account. One state file per account/region/module is created
e.g. Project name: sample-tf-module
Target accounts: 111111111111, 222222222222
Target regions: eu-west-1 (main ADF region), us-east-1
The following state files are created
A DynamoDB table manage the lock of the state file. It is deployed in every ADF regions named adf_locktable
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.