terragrunt.hcl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. locals {
  2. # If you want to use any of the variables in _this_ file, you have to load them here.
  3. # However, they will all be available as inputs to the module loaded in terraform.source
  4. # below.
  5. environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
  6. partition_vars = read_terragrunt_config(find_in_parent_folders("partition.hcl"))
  7. region_vars = read_terragrunt_config(find_in_parent_folders("region.hcl"))
  8. account_vars = read_terragrunt_config(find_in_parent_folders("account.hcl"))
  9. global_vars = read_terragrunt_config(find_in_parent_folders("globals.hcl"))
  10. # Generate our standard tags
  11. standard_tags = merge(
  12. local.global_vars.locals.global_tags,
  13. local.environment_vars.locals.environment_tags,
  14. local.partition_vars.locals.partition_tags,
  15. local.region_vars.locals.region_tags,
  16. local.account_vars.locals.account_tags
  17. )
  18. # Extract the variables we need for easy access
  19. account_name = local.account_vars.locals.account_name
  20. account_id = local.account_vars.locals.aws_account_id
  21. aws_region = local.region_vars.locals.aws_region
  22. aws_partition = local.partition_vars.locals.aws_partition
  23. common_services_account = local.partition_vars.locals.common_services_account
  24. legacy_account = local.environment_vars.locals.legacy_account
  25. tfstate_region = local.partition_vars.locals.tfstate_region
  26. common_profile = local.partition_vars.locals.common_profile
  27. }
  28. # Terragrunt will copy the Terraform configurations specified by the source parameter, along with any files in the
  29. # working directory, into a temporary folder, and execute your Terraform commands in that folder.
  30. terraform {
  31. # Double slash is intentional and required to show root of modules
  32. source = "git@github.xdr.accenturefederalcyber.com:mdr-engineering/xdr-terraform-modules.git//base/codebuild_portal_lambda?ref=v4.1.0"
  33. }
  34. # ---------------------------------------------------------------------------------------------------------------------
  35. # Generate an AWS provider block
  36. # ---------------------------------------------------------------------------------------------------------------------
  37. generate "provider" {
  38. path = "provider.tf"
  39. if_exists = "overwrite_terragrunt"
  40. contents = <<EOF
  41. provider "template" {
  42. }
  43. provider "aws" {
  44. region = "${local.aws_region}"
  45. assume_role {
  46. role_arn = "arn:${local.aws_partition}:iam::${local.account_id}:role/user/mdr_terraformer"
  47. session_name = "terraform-default"
  48. }
  49. profile = "${local.common_profile}"
  50. # Only these AWS Account IDs may be operated on by this template
  51. allowed_account_ids = ["${local.account_id}"]
  52. }
  53. # The "common" provider in the respective partition is always available
  54. provider "aws" {
  55. region = "${local.aws_region}"
  56. allowed_account_ids = [ "471284459109", "701290387780" ]
  57. profile = "${local.common_profile}"
  58. alias = "common"
  59. assume_role {
  60. role_arn = "arn:${local.aws_partition}:iam::${local.common_services_account}:role/user/mdr_terraformer"
  61. session_name = "terraform-common"
  62. }
  63. }
  64. # The "mdr-common-services-commercial" provider is used for public DNS entries
  65. provider "aws" {
  66. region = "us-east-1"
  67. allowed_account_ids = [ "471284459109" ]
  68. profile = "commercial"
  69. alias = "mdr-common-services-commercial"
  70. assume_role {
  71. role_arn = "arn:aws:iam::471284459109:role/user/mdr_terraformer"
  72. session_name = "terraform-mdr-common-services-commercial"
  73. }
  74. }
  75. # The "C2" provider, used for private DNS
  76. provider "aws" {
  77. region = "us-gov-east-1"
  78. allowed_account_ids = [ "721817724804", "738800754746" ]
  79. profile = "govcloud"
  80. alias = "c2"
  81. #use_fips_endpoint = true
  82. assume_role {
  83. role_arn = "arn:aws-us-gov:iam::${ local.environment_vars.locals.c2_accounts["aws-us-gov"] }:role/user/mdr_terraformer"
  84. session_name = "terraform-c2"
  85. }
  86. }
  87. EOF
  88. }
  89. #Github specific provider
  90. generate "required_providers" {
  91. path = "required_provider.tf"
  92. if_exists = "overwrite_terragrunt"
  93. contents = <<EOF
  94. terraform {
  95. required_providers {
  96. aws = {
  97. source = "hashicorp/aws"
  98. version = "= 3.63.0" # 2022-03-08: upgrade from 3.63.0; 2021-09-21: upgrade from 3.37.0
  99. }
  100. vault = {
  101. source = "hashicorp/vault"
  102. version = "= 2.19.1" # 2021-04-29: upgrade from 2.18.0
  103. }
  104. sensu = {
  105. source = "jtopjian/sensu"
  106. version = "= 0.10.5"
  107. }
  108. github = {
  109. source = "integrations/github"
  110. version = "4.2.0"
  111. }
  112. }
  113. }
  114. EOF
  115. }
  116. generate "github-provider" {
  117. path = "github-provider.tf"
  118. if_exists = "overwrite_terragrunt"
  119. contents = <<EOF
  120. provider "github" {
  121. organization = "MDR-Content"
  122. base_url = "https://github.xdr.accenturefederalcyber.com/"
  123. }
  124. EOF
  125. }
  126. # Include all settings from the root terragrunt.hcl file
  127. include {
  128. path = find_in_parent_folders()
  129. }
  130. # These are the variables we have to pass in to use the module specified in the terragrunt source above
  131. inputs = {
  132. # All of the inputs from the inherited hcl files are available automatically
  133. # (via the `inputs` section of the root `terragrunt.hcl`). However, modules
  134. # will be more flexible if you specify particular input values.
  135. tags = {
  136. Purpose = "Build portal_data_sync with Codebuild"
  137. Terraform = "aws/${basename(get_parent_terragrunt_dir())}/${path_relative_to_include()}/"
  138. }
  139. source_version = "develop"
  140. webhook_filter_pattern = "^refs/heads/develop$"
  141. name = "portal_data_sync"
  142. }
  143. terraform_version_constraint = "= 1.1.6"
  144. terragrunt_version_constraint = "= 0.36.2"