main.tf 3.0 KB

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