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

ADF terraform extension #397

Merged
merged 165 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 154 commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
5f625ac
added .gitignore
Oct 29, 2021
ff378bc
added adf terraform role to global.yml
Oct 29, 2021
0aebbf8
Added DynamoDB permission to adf-codebuild-policy in deployment/globa…
Oct 29, 2021
c5121a6
added adf-terraform-role to Organization Policy adf-build/global.yml
Oct 29, 2021
fb49f24
added organizations:ListChildren to OrganizationsReadOnlyPolicy
Oct 29, 2021
6a9b868
added DynamoDB table for terraform lock to adf-bootstrap/deployment/g…
Oct 29, 2021
9cb0d83
added DynamoDB table for terraform lock to adf-bootstrap/deployment/g…
Oct 29, 2021
3ceabf4
added sample-terraform repository
Oct 29, 2021
8be3e71
Added tfvars examples
Oct 29, 2021
bc8d00c
clean comments
Oct 29, 2021
3711c3d
pull request template
Oct 29, 2021
ecc13aa
Define PULL REQUEST
Oct 29, 2021
c2657dd
clean PULL_REQUEST_TEMPLATE.md
Nov 5, 2021
4ce58cc
Update samples/sample-terraform/README.md
stemons Nov 5, 2021
ab48994
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 5, 2021
d562c38
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 5, 2021
dec1f81
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 5, 2021
04c16db
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 5, 2021
a2eb125
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 5, 2021
2072056
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 5, 2021
2278028
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 5, 2021
c6d660d
removed .gitignore from sample-terraform
Nov 5, 2021
b18a0f5
Update samples/sample-terraform/README.md
stemons Nov 5, 2021
5f0ed7f
renamed tf_sec to tf_scan in sample-terraform
Nov 5, 2021
8952483
added more details to README.md regarding REGIONS parameters
Nov 5, 2021
948e147
removed restart_execution_on_update: true
Nov 5, 2021
5d18eeb
Update samples/sample-terraform/README.md
stemons Nov 5, 2021
23c8d55
Update samples/sample-terraform/README.md
stemons Nov 5, 2021
88449f7
Update samples/sample-terraform/README.md
stemons Nov 5, 2021
d173a2b
Update samples/sample-terraform/README.md
stemons Nov 5, 2021
d234a36
added latest terraform version in sample-terraform example
Nov 9, 2021
88f3e48
added terraform version support in documetation
Nov 9, 2021
cd71d42
fixed README.md format
Nov 9, 2021
0ffe83c
added tf pipeline documentation in user guide
Nov 9, 2021
7440ae3
added s3 public access block to terraform sample
Nov 9, 2021
bb52471
removed TF_STAGE as adf_terraform.sh input parameter
Nov 9, 2021
0b720d6
removed AWS_DEFAULT_REGION from tf_apply and tf_plan
Nov 9, 2021
30f116f
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 9, 2021
0f630b4
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 9, 2021
99e5e9f
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 9, 2021
1625ae0
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 9, 2021
e78223b
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 9, 2021
85ce85c
revert to original PULL_REQUEST_TEMPLATE.md
Nov 12, 2021
793ab2c
clean .gitignore
Nov 12, 2021
3fa1b92
add logging module
Nov 12, 2021
99fa20d
added main
Nov 12, 2021
bb58170
undo linter changes
Nov 12, 2021
70196b8
removed artifact from tf_apply
Nov 12, 2021
9043135
added ondemand capacity to DynamoDB table
Nov 12, 2021
50e17b3
removed terraform role. This could be added in global-iam by the user
Nov 12, 2021
a81899e
added an example of terraform role. It must be uncommented by the use…
Nov 12, 2021
5138c97
added tf pre-requisites to user-guide
Nov 12, 2021
6568537
global vars to upper case
Nov 12, 2021
07d42a1
added tfrun function to avoid code repetition and add functionality t…
Nov 12, 2021
0b1f697
clean documentation
Nov 12, 2021
ed32b14
Update docs/user-guide.md
stemons Nov 19, 2021
926c9e3
Update docs/user-guide.md
stemons Nov 19, 2021
8c653aa
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 19, 2021
e3762e7
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 19, 2021
fb9759e
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 19, 2021
7d5b8b0
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 19, 2021
44c5401
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 19, 2021
9fd62e2
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 19, 2021
3e7ada5
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 19, 2021
9180263
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 19, 2021
e7e0679
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 19, 2021
bafca0d
Update docs/user-guide.md
stemons Nov 19, 2021
e0be884
Update docs/user-guide.md
stemons Nov 19, 2021
c315037
Update docs/user-guide.md
stemons Nov 19, 2021
b0fcd77
Update docs/user-guide.md
stemons Nov 19, 2021
53572e7
Update docs/user-guide.md
stemons Nov 19, 2021
cfbbd37
Update docs/user-guide.md
stemons Nov 19, 2021
17a6c69
Update samples/sample-terraform/tf/s3.tf
stemons Nov 19, 2021
3a434ad
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bo…
stemons Nov 19, 2021
e9d3750
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 19, 2021
256e75b
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 19, 2021
4c034f0
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 22, 2021
4a91739
removed extra ]
Nov 22, 2021
f9bdf73
changed session name
Nov 22, 2021
d98feb6
move TERRAFORM_VERSION variable to buildspec.yml
Nov 22, 2021
d5f72a2
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 22, 2021
541262c
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 22, 2021
90e3786
renamed environment variables
Nov 22, 2021
7401122
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
0ea718b
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
d02171c
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
3d7fcb7
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
abea92b
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
b9da4dc
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
4201301
Update docs/user-guide.md
stemons Nov 23, 2021
de8ca78
Update docs/user-guide.md
stemons Nov 23, 2021
d0a51b5
fixed toc identation
Nov 23, 2021
7a166a6
added details to terraform sections
Nov 23, 2021
db13877
Update docs/user-guide.md
stemons Nov 23, 2021
48ff0a5
Update docs/user-guide.md
stemons Nov 23, 2021
5466280
Update docs/user-guide.md
stemons Nov 23, 2021
31f52a3
Update docs/user-guide.md
stemons Nov 23, 2021
b9a6edf
Update docs/user-guide.md
stemons Nov 23, 2021
544a71b
Update samples/sample-terraform/README.md
stemons Nov 23, 2021
d5ed60a
Update samples/sample-terraform/README.md
stemons Nov 23, 2021
1f3dba1
renamed terraform to upper case and align content of README.md file i…
Nov 23, 2021
1d0496c
Update samples/sample-terraform/README.md
stemons Nov 23, 2021
135c6b3
Update samples/sample-terraform/buildspec.yml
stemons Nov 23, 2021
4b8a1fd
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
ba5881c
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
f99f07a
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
33de671
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
722fa0c
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
fed666a
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
8ec3acd
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bu…
stemons Nov 23, 2021
2e3e139
removed Terraform IAM role and policy
Nov 23, 2021
c8aa794
added support to partitions
Nov 23, 2021
2cccef3
Update docs/user-guide.md
stemons Nov 24, 2021
75f97dc
Update docs/user-guide.md
stemons Nov 24, 2021
81c20d9
Update docs/user-guide.md
stemons Nov 24, 2021
9313a17
Update docs/user-guide.md
stemons Nov 24, 2021
196efb9
Update docs/user-guide.md
stemons Nov 24, 2021
b9dafee
Update samples/sample-terraform/README.md
stemons Nov 24, 2021
1398957
Update samples/sample-terraform/README.md
stemons Nov 24, 2021
fb84415
Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-bo…
stemons Nov 24, 2021
fb4c661
removed TerraformLockTable resource as already defined in regional.yml
Nov 24, 2021
f0d44f5
Update docs/user-guide.md
stemons Nov 24, 2021
9d2c71d
Update docs/user-guide.md
stemons Nov 24, 2021
beb9791
Update docs/user-guide.md
stemons Nov 24, 2021
fb743ac
Update samples/sample-terraform/README.md
stemons Nov 24, 2021
17818b9
Update samples/sample-terraform/README.md
stemons Nov 24, 2021
219186c
Merge remote-tracking branch 'upstream/master'
Nov 24, 2021
55c544d
added newline character
Dec 23, 2021
e2a93b1
added newline character
Dec 23, 2021
f98f3e5
added newline character
Dec 23, 2021
131c526
added docstring
Dec 23, 2021
4d97190
read CROSS_ACCOUNT_ACCESS_ROLE from parameter store
Dec 23, 2021
3fcda2d
replaced sample adf terraform policy example
Dec 23, 2021
e1ee1a6
replaced sample adf terraform policy example
Dec 23, 2021
868d88f
added details to adf terraform role description
Dec 23, 2021
a327b30
removed trailing spaces
Dec 23, 2021
c050572
added aws partition variable
Dec 23, 2021
35d3148
added init stage only as option
Dec 23, 2021
d50cc35
import extensions parameter in SSM Parameter Store of Management account
Dec 24, 2021
9742f97
import extensions parameter in SSM Parameter Store of Deployment acco…
Dec 24, 2021
a0b660b
added condition on DynamoDB table. Deploy only if Tf extension is ena…
Dec 24, 2021
b1e0020
added example in adfconfig related to Tf extension
Dec 24, 2021
5eccd06
added details related to terraform extension
Dec 24, 2021
6e2eb5c
added details related to terraform extension
Dec 24, 2021
9b6debb
fixed indentation
Dec 24, 2021
18fc837
renamed paginator variable
Jan 3, 2022
83efd01
Merge branch 'master' into master
StewartW Jan 5, 2022
31821a4
Merge branch 'master' into master
sbkok Jan 7, 2022
2b96912
Merge remote-tracking branch 'master' into PR #397
sbkok Mar 7, 2022
2f2f38b
Resolve W1514 - use open with encoding
sbkok Mar 7, 2022
f6c436c
Fix user guide target via tags
sbkok Mar 7, 2022
975c754
changed default codebuild image to STANDARD_5_0
May 27, 2022
3967707
Merge remote-tracking branch 'upstream/master' into stemons/master
sbkok Sep 16, 2022
3eb4732
Fix YAML lint issues
sbkok Sep 16, 2022
836bdb0
Fix CFN lint issues
sbkok Sep 16, 2022
0aa1f83
Fix MegaLint issues
sbkok Sep 16, 2022
02b7ee3
Merge remote-tracking branch 'upstream/master' into stemons-master
sbkok Sep 19, 2022
43e1cfd
Adding in default values for extensions
StewartW Sep 20, 2022
6eb593a
Merge branch 'master' of github.com:awslabs/aws-deployment-framework …
StewartW Sep 20, 2022
74b8049
Remove redundant paginator
sbkok Nov 3, 2022
0e433a8
Fix TF doc comments and links
sbkok Nov 3, 2022
81a3465
Fix TF line length findings
sbkok Nov 3, 2022
a5694a4
Revert default CodeBuild container, would introduce a breaking change
sbkok Nov 3, 2022
3be75e3
Replace redundant code writing extension parameters
sbkok Nov 3, 2022
f54c00f
Merge remote-tracking branch 'upstream/master' into stemons-master
sbkok Nov 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,15 @@ dmypy.json
.pyre/

megalinter-reports/

### Terraform ###
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Ignore CLI configuration files
.terraformrc
terraform.rc
162 changes: 162 additions & 0 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
- [Deploying Serverless Applications with SAM](#deploying-serverless-applications-with-sam)
- [Using YAML Anchors and Aliases](#using-yaml-anchors-and-aliases)
- [One to many relationships](#one-to-many-relationships)
- [Terraform pipeline](#terraform-pipeline)
- [Prerequisites](#prerequisites)
- [Overview](#overview)
- [Parameters](#parameters)
- [Deployment procedure](#deployment-procedure)

## Deployment Map

Expand Down Expand Up @@ -1028,3 +1033,160 @@ By passing in the Repository name *(repository)* we are overriding the
**name** property which normally is the name of our associated repository.
This will tie both of these pipelines to the single *sample-vpc* repository on
the `111111111111` AWS Account.

### Terraform pipeline

#### Prerequisites

To enable ADF Terraform extension the following steps are required:
- Enable ADF Terraform extension. Set the parameter
`extensions > terraform > enabled` to `True` in the `adfconfig.yml` file,
as shown in the `example-adfconfig.yml`, to deploy all the necessary
resources.
- Rename file `example-global-iam.yml` to `global-iam.yml` in the following
path `aws-deployment-framework-bootstrap/adf-bootstrap/` and ensure the
CloudFormation resources `ADFTerraformRole` and `ADFTerraformPolicy` are
no longer commented out.
- Rename file `example-global-iam.yml` to `global-iam.yml` in the following
path `aws-deployment-framework-bootstrap/adf-bootstrap/deployment`
**Please note:** the use of `deployment` at the end)
and ensure the CloudFormation resources `ADFTerraformRole` and
`ADFTerraformPolicy` are no longer commented out.

**Important note**: `ADFTerraformPolicy` IAM policy is a sample.
This policies should **NOT** be used for purposes other than testing.
You should scope this policy depending on what you would like to deploy
using Terraform within the selected Organizational Units.

#### Overview

ADF support the deployment of Terraform code to multiple accounts and
regions through Terraform pipelines. The module consists of four build
stages defined in the following CodeBuild build specification:

- `buildspec.yml`: install the version of Terraform specified in the
pipeline configuration.
- `tf_scan.yml`: (optional) scans for vulnerabilities in the Terraform
code using the [Terrascan](https://github.com/accurics/terrascan)
application. If vulnerabilities are found, it will fail and block
further execution in the pipeline. It is recommended to enable this
step in all ADF Terraform pipelines.
- `tf_plan.yml`: get the list of accounts from the organization and
run a Terraform plan.
- `tf_apply.yml`: get the list of accounts from the organization and
run a Terraform plan and apply.

An optional approval step could be added between plan and apply as
shown in the pipeline definition below.

Please look into the [sample-terraform](../samples/sample-terraform)
pipeline for more details in the setup and integration.

#### Parameters

- `TERRAFORM_VERSION`: the Terraform version used to deploy the
resource. This parameter must be defined in the `buildspec.yml`
file of the repository.
- `TARGET_ACCOUNTS`: comma separated list of target accounts.
- `TARGET_OUS`: comma separated list of target leaf OUs (parent
OUs are supported).
- `REGIONS`: comma separated list of target regions. If this parameter
is empty, the main ADF region is used.
- `MANAGEMENT_ACCOUNT_ID`: id of the AWS Organizations management account.

#### Deployment procedure

1. Add a sample-terraform pipeline in ADF `deployment-map.yml` as in the
example:

```yaml
- name: sample-terraform
default_providers:
source:
provider: codecommit
properties:
account_id: 111111111111 # Source account id
build:
provider: codebuild
deploy:
provider: codebuild
properties:
image: "STANDARD_5_0"
environment_variables:
TARGET_ACCOUNTS: 111111111111,222222222222 # Target accounts
TARGET_OUS: /core/infrastructure,/sandbox # Target OUs
MANAGEMENT_ACCOUNT_ID: 333333333333 # Billing account
# Target regions, as a comma separated list is supported
# For example, "eu-west-1,us-east-1".
REGIONS: eu-west-1
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
```

2. Add the project name in `params/global.yml` file.
3. Add Terraform code to the `tf` folder. **Please note**: Do not make changes
to `backend.tf` file and `main.tf` in the root folder of the sample.
These contain the definition of the remote state file location and the
Terraform provider definition. Any change to these files could disrupt
the standard functionalities of this module.
4. 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

```
tfvars <-- This folder contains the structure to define Terraform
│ variables
└───global.auto.tfvars <-- this file contains global variables applied to
│ all the target accounts
└───111111111111 <-- this folders contains variable files related to
│ │ the account
│ └──────│ local.auto.tfvars <-- this file contains variables related
│ │ to the account
└───222222222222
└──────│ local.auto.tfvars
```

5. Define the desired `TERRAFORM_VERSION` in the `buildspec.yml` file as shown
in the sample-terraform example. ADF supports Terraform version v0.13.0 and
later.
6. Push to your Terraform ADF repository, for example the sample-terraform one.
7. Pipeline contains a manual approval step 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:

- 111111111111 main region (eu-west-1)
-> adf-global-base-deployment-pipelinebucketxyz/sample-tf-module/111111111111.tfstate
- 111111111111 secondary region (us-east-1)
-> adf-regional-base-deploy-deploymentframeworkregio-jsm/sample-tf-module/111111111111.tfstate
- 222222222222 main region (eu-west-1)
-> adf-global-base-deployment-pipelinebucketxyz/sample-tf-module/222222222222.tfstate
- 222222222222 secondary region (us-east-1)
-> adf-regional-base-deploy-deploymentframeworkregio-jsm/sample-tf-module/222222222222.tfstate

A DynamoDB table is created to manage the lock of the state file. It is
deployed in every ADF regions named `adf_locktable`. **Please note**: usage
of this locking table is charged on the deployment account.
61 changes: 46 additions & 15 deletions samples/sample-terraform/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
# Sample Terraform
# Terraform template

## Deployment Map example
## Overview

Please read the[user guide on ADF's support for
Terraform](../docs/user-guide.md#terraform-pipeline) before you proceed.

## Deployment procedure

1. Add a sample-terraform pipeline in ADF `deployment-map.yml` as in the
example:

```yaml
- name: my-terraform-example
default_providers:
source:
provider: codecommit
properties:
account_id: 1111111111111
deploy:
provider: codebuild
properties:
image: "STANDARD_5_0"
targets:
- properties:
spec_filename: my_test_spec.yml
- name: sample-terraform
default_providers:
source:
provider: codecommit
properties:
account_id: 111111111111 # Source account id
build:
provider: codebuild
deploy:
provider: codebuild
properties:
image: "STANDARD_5_0"
environment_variables:
TARGET_ACCOUNTS: 111111111111,222222222222 # Target accounts
TARGET_OUS: /core/infrastructure,/sandbox # Target OUs
MANAGEMENT_ACCOUNT_ID: 333333333333 # Billing account
# Regions in comma-separated list format, for example
# "eu-west-1,us-east-1"
REGIONS: eu-west-1
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
```

The sample uses the following configuration, please update accordingly:

- Project name: sample-tf-module
- Target accounts: 111111111111, 222222222222
- Target regions: eu-west-1 (main ADF region), us-east-1
13 changes: 11 additions & 2 deletions samples/sample-terraform/buildspec.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
version: 0.2

env:
variables:
# Terraform version to use. ADF supports Terraform version v0.13.0 and later.
TERRAFORM_VERSION: "1.0.10"
phases:
install:
commands:
- aws s3 cp s3://$S3_BUCKET_NAME/adf-build/ adf-build/ --recursive --quiet
- export PATH=$PATH:$(pwd)
- bash scripts/terraform/install_terraform.sh
- bash adf-build/helpers/terraform/install_terraform.sh
- pip install -r adf-build/requirements.txt -q
build:
commands:
- python adf-build/generate_params.py

artifacts:
files: '**/*'
files: "**/*"
16 changes: 0 additions & 16 deletions samples/sample-terraform/main.tf

This file was deleted.

28 changes: 0 additions & 28 deletions samples/sample-terraform/my_test_spec.yml

This file was deleted.

2 changes: 2 additions & 0 deletions samples/sample-terraform/params/global.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Parameters:
ProjectName: "sample-terraform" # $ADF_PROJECT_NAME
11 changes: 0 additions & 11 deletions samples/sample-terraform/scripts/terraform/install_terraform.sh

This file was deleted.

1 change: 0 additions & 1 deletion samples/sample-terraform/terraform.tfvars

This file was deleted.

16 changes: 16 additions & 0 deletions samples/sample-terraform/tf/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
data "aws_partition" "current" {}

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0"
}
}
required_version = ">= 0.13.0"
}
provider "aws" {
assume_role {
role_arn = "arn:${data.aws_partition.current}:iam::${var.TARGET_ACCOUNT_ID}:role/${var.TARGET_ACCOUNT_ROLE}"
}
}
13 changes: 13 additions & 0 deletions samples/sample-terraform/tf/s3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "aws_s3_bucket" "s3" {
bucket = "my-tf-test-bucket-${var.TARGET_REGION}-${var.TARGET_ACCOUNT_ID}"
acl = "private"
}

resource "aws_s3_bucket_public_access_block" "s3-public-block" {
bucket = aws_s3_bucket.s3.id

block_public_acls = true
block_public_policy = true
stemons marked this conversation as resolved.
Show resolved Hide resolved
ignore_public_acls = true
restrict_public_buckets = true
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
variable "TARGET_ACCOUNT_ID" {}
variable "TARGET_ACCOUNT_ROLE" {}
variable my_bucket_name {}
variable "TARGET_REGION" {}

18 changes: 18 additions & 0 deletions samples/sample-terraform/tf_apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 0.2

env:
variables:
TF_VAR_TARGET_ACCOUNT_ROLE: adf-terraform-role # The IAM Role terraform will assume to deploy resources
TF_IN_AUTOMATION: true
TF_CLI_ARGS: "-no-color"
TF_STAGE: "apply"

phases:
install:
runtime-versions:
python: 3.8
build:
commands:
- python adf-build/helpers/terraform/get_accounts.py
- bash adf-build/helpers/terraform/adf_terraform.sh

Loading