main.tf 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #tfsec:ignore:aws-s3-block-public-acls tfsec:ignore:aws-s3-block-public-policy tfsec:ignore:aws-s3-ignore-public-acls
  2. #tfsec:ignore:aws-s3-no-public-buckets Certificate CRLs need to be publicly accessible
  3. resource "aws_s3_bucket" "bucket" {
  4. count = var.palo_alto_count
  5. bucket = "xdr-palo-alto-bootstrap-${count.index}"
  6. }
  7. resource "aws_s3_bucket_acl" "s3_acl_bucket" {
  8. bucket = aws_s3_bucket.bucket.id
  9. acl = "private"
  10. }
  11. locals {
  12. # Bootstrap process requires that folders exist, so we must create them in each bucket. This looks complicated,
  13. # but it's just doing a foreach bucket: foreach directory: ...
  14. bucket_folder_map = { for p in setproduct(range(var.palo_alto_count), local.bootstrap_dirs) : "${p[0]}/${p[1]}" => {
  15. num = p[0]
  16. folder = p[1]
  17. }
  18. }
  19. }
  20. resource "aws_s3_bucket_object" "bootstrap_dirs" {
  21. for_each = local.bucket_folder_map
  22. bucket = aws_s3_bucket.bucket[each.value["num"]].id
  23. key = each.value["folder"]
  24. content = "/dev/null"
  25. }
  26. resource "aws_s3_bucket_object" "init_cfg" {
  27. count = var.palo_alto_count
  28. bucket = aws_s3_bucket.bucket[count.index].id
  29. key = "config/init-cfg.txt"
  30. content = templatefile("${path.module}/init-cfg.txt.tmpl",
  31. {
  32. "hostname" = "xdr_palo_${var.aws_partition_alias}_${var.environment}_${count.index}"
  33. "authkey" = var.palo_alto_auth_keys[count.index]
  34. "tplname" = "XDR-Interconnect-Stack-${count.index}"
  35. "dgname" = "XDR-Interconnects"
  36. "op-command-modes" = "jumbo-frame, mgmt-interface-swap"
  37. "panorama_primary" = var.panorama_servers[0]
  38. "panorama_secondary" = var.panorama_servers[1]
  39. }
  40. )
  41. }
  42. # No bootstrap configuration, as we're registered to panorama
  43. # resource "aws_s3_bucket_object" "bootstrap_xml" {
  44. # count = var.palo_alto_count
  45. # bucket = aws_s3_bucket.bucket[count.index].id
  46. # key = "config/bootstrap.xml"
  47. # content = templatefile("${path.module}/bootstrap.xml.tmpl",
  48. # {
  49. # index = count.index
  50. # }
  51. # )
  52. #}
  53. resource "aws_s3_bucket_object" "authcodes" {
  54. count = var.palo_alto_count
  55. bucket = aws_s3_bucket.bucket[count.index].id
  56. key = "license/authcodes"
  57. content = <<EOF
  58. ${var.palo_alto_license_keys[count.index]}
  59. EOF
  60. }
  61. resource "aws_iam_role" "bootstrap_role" {
  62. count = var.palo_alto_count
  63. name = "palo_alto_bootstrap_${count.index}"
  64. path = "/instance/"
  65. assume_role_policy = <<EOF
  66. {
  67. "Version": "2012-10-17",
  68. "Statement": [
  69. {
  70. "Effect": "Allow",
  71. "Principal": {
  72. "Service": "ec2.amazonaws.com"
  73. },
  74. "Action": "sts:AssumeRole"
  75. }
  76. ]
  77. }
  78. EOF
  79. }
  80. resource "aws_iam_role_policy" "bootstrap_policy" {
  81. count = var.palo_alto_count
  82. name = "palo_alto_bootstrap_${count.index}"
  83. role = aws_iam_role.bootstrap_role[count.index].id
  84. policy = <<EOF
  85. {
  86. "Version" : "2012-10-17",
  87. "Statement": [
  88. {
  89. "Effect": "Allow",
  90. "Action": "s3:ListBucket",
  91. "Resource": "arn:${var.aws_partition}:s3:::${aws_s3_bucket.bucket[count.index].bucket}"
  92. },
  93. {
  94. "Effect": "Allow",
  95. "Action": "s3:GetObject",
  96. "Resource": "arn:${var.aws_partition}:s3:::${aws_s3_bucket.bucket[count.index].bucket}/*"
  97. }
  98. ]
  99. }
  100. EOF
  101. }
  102. resource "aws_iam_instance_profile" "bootstrap" {
  103. count = var.palo_alto_count
  104. name = "palo_alto_bootstrap_${count.index}"
  105. role = aws_iam_role.bootstrap_role[count.index].name
  106. path = "/instance/"
  107. }
  108. //AWS Provider outdated arguments <4.4.0
  109. /*resource "aws_s3_bucket" "bucket" {
  110. count = var.palo_alto_count
  111. bucket = "xdr-palo-alto-bootstrap-${count.index}"
  112. acl = "private"
  113. }
  114. */