terragrunt.hcl 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. # ---------------------------------------------------------------------------------------------------------------------
  29. # Generate an AWS provider block
  30. # Temp fix to backlevel provider because of codebuild issue
  31. # <insert github link here to provider issue>
  32. # ---------------------------------------------------------------------------------------------------------------------
  33. generate "provider" {
  34. path = "provider.tf"
  35. if_exists = "overwrite_terragrunt"
  36. contents = <<EOF
  37. provider "template" {
  38. }
  39. provider "aws" {
  40. region = "${local.aws_region}"
  41. assume_role {
  42. role_arn = "arn:${local.aws_partition}:iam::${local.account_id}:role/user/mdr_terraformer"
  43. session_name = "terraform-default"
  44. }
  45. profile = "${local.common_profile}"
  46. # Only these AWS Account IDs may be operated on by this template
  47. allowed_account_ids = ["${local.account_id}"]
  48. }
  49. # The "common" provider in the respective partition is always available
  50. provider "aws" {
  51. region = "${local.aws_region}"
  52. allowed_account_ids = [ "471284459109", "701290387780" ]
  53. profile = "${local.common_profile}"
  54. alias = "common"
  55. assume_role {
  56. role_arn = "arn:${local.aws_partition}:iam::${local.common_services_account}:role/user/mdr_terraformer"
  57. session_name = "terraform-common"
  58. }
  59. }
  60. # The "mdr-common-services-commercial" provider is used for public DNS entries
  61. provider "aws" {
  62. region = "us-east-1"
  63. allowed_account_ids = [ "471284459109" ]
  64. profile = "commercial"
  65. alias = "mdr-common-services-commercial"
  66. assume_role {
  67. role_arn = "arn:aws:iam::471284459109:role/user/mdr_terraformer"
  68. session_name = "terraform-mdr-common-services-commercial"
  69. }
  70. }
  71. # The "C2" provider, used for private DNS
  72. provider "aws" {
  73. region = "us-gov-east-1"
  74. allowed_account_ids = [ "721817724804", "738800754746" ]
  75. profile = "govcloud"
  76. alias = "c2"
  77. #use_fips_endpoint = true
  78. assume_role {
  79. role_arn = "arn:aws-us-gov:iam::${ local.environment_vars.locals.c2_accounts["aws-us-gov"] }:role/user/mdr_terraformer"
  80. session_name = "terraform-c2"
  81. }
  82. }
  83. EOF
  84. }
  85. #Github specific provider
  86. generate "required_providers" {
  87. path = "required_provider.tf"
  88. if_exists = "overwrite_terragrunt"
  89. contents = <<EOF
  90. terraform {
  91. required_providers {
  92. aws = {
  93. source = "hashicorp/aws"
  94. version = "= 3.63.0" # 2022-03-08: upgrade from 3.63.0; 2021-09-21: upgrade from 3.37.0
  95. }
  96. vault = {
  97. source = "hashicorp/vault"
  98. version = "= 2.19.1" # 2021-04-29: upgrade from 2.18.0
  99. }
  100. sensu = {
  101. source = "jtopjian/sensu"
  102. version = "= 0.10.5"
  103. }
  104. github = {
  105. source = "integrations/github"
  106. version = "4.2.0"
  107. }
  108. }
  109. }
  110. EOF
  111. }
  112. # Terragrunt will copy the Terraform configurations specified by the source parameter, along with any files in the
  113. # working directory, into a temporary folder, and execute your Terraform commands in that folder.
  114. terraform {
  115. # Double slash is intentional and required to show root of modules
  116. source = "git@github.xdr.accenturefederalcyber.com:mdr-engineering/xdr-terraform-modules.git//base/codebuild_ecr_base?ref=v4.0.11"
  117. }
  118. # Include all settings from the root terragrunt.hcl file
  119. include {
  120. path = find_in_parent_folders()
  121. }
  122. # These are the variables we have to pass in to use the module specified in the terragrunt source above
  123. inputs = {
  124. # All of the inputs from the inherited hcl files are available automatically
  125. # (via the `inputs` section of the root `terragrunt.hcl`). However, modules
  126. # will be more flexible if you specify particular input values.
  127. tags = {
  128. Purpose = "Base module for Codebuild"
  129. Terraform = "aws/${basename(get_parent_terragrunt_dir())}/${path_relative_to_include()}/"
  130. }
  131. }
  132. terraform_version_constraint = "= 1.1.6"
  133. terragrunt_version_constraint = "= 0.36.2"