Skip to content

Commit

Permalink
[feature] Add terraform remote state between accounts (#299)
Browse files Browse the repository at this point in the history
[feature] Add terraform remote state between accounts### Summary
Similar to other components, accounts now get a reference to all other account's remote state

### Test Plan
unittests + ran it in a couple of repos

### References
  • Loading branch information
Eduardo Lopez authored and czimergebot committed Jun 19, 2019
1 parent d7a5ccc commit 020d294
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
17 changes: 17 additions & 0 deletions templates/account/fogg.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,20 @@ data "terraform_remote_state" "global" {
{{ if .Global.Backend.Profile }}profile = "{{ .Global.Backend.Profile }}"{{ end }}
}
}

{{ $outer := . }}
{{ range $accountName, $accountID := .AllAccounts}}
{{ if ne $accountName $outer.AccountName }}
data "terraform_remote_state" "{{ $accountName }}" {
backend = "s3"

config = {
bucket = "{{ $outer.Backend.Bucket }}"
{{ if $outer.Backend.DynamoTable }}dynamodb_table = "{{ $outer.Backend.DynamoTable }}"{{ end -}}
key = "terraform/{{ $outer.Project }}/accounts/{{ $accountName }}.tfstate"
region = "{{ $outer.Backend.Region }}"
{{ if $outer.Backend.Profile }}profile = "{{ $outer.Backend.Profile }}"{{ end }}
}
}
{{ end }}
{{ end }}
13 changes: 13 additions & 0 deletions testdata/v1_full/terraform/accounts/bar/fogg.tf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions testdata/v1_full/terraform/accounts/foo/fogg.tf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions testdata/v2_full/terraform/accounts/bar/fogg.tf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions testdata/v2_full/terraform/accounts/foo/fogg.tf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 020d294

Please sign in to comment.