Advertisement
Guest User

Untitled

a guest
Aug 20th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. terraform {
  2. required_providers {
  3. boundary = {
  4. source = "hashicorp/boundary"
  5. version = "1.0.3"
  6. }
  7. }
  8. }
  9.  
  10. provider "boundary" {
  11. addr = "http://127.0.0.1:9200"
  12. recovery_kms_hcl = <<EOT
  13. kms "awskms" {
  14. purpose = "recovery"
  15. region = "${var.kms_region}"
  16. access_key = "${var.aws_access_key}"
  17. secret_key = "${var.aws_secret_key}"
  18. kms_key_id = "${var.kms_key_id}"
  19. }
  20. EOT
  21. }
  22.  
  23. resource "boundary_scope" "global" {
  24. global_scope = true
  25. name = "global"
  26. scope_id = "global"
  27. }
  28.  
  29. resource "boundary_scope" "org" {
  30. name = "Company org."
  31. description = "This org belongs to ${var.environment} environment"
  32. scope_id = boundary_scope.global.id
  33. }
  34.  
  35. // create a project for core infrastructure
  36. resource "boundary_scope" "core_infra" {
  37. name = "Infra scope"
  38. description = "${var.environment} project"
  39. scope_id = boundary_scope.org.id
  40. auto_create_admin_role = true
  41. auto_create_default_role = true
  42. }
  43.  
  44.  
  45. resource "boundary_auth_method" "password" {
  46. name = "password"
  47. scope_id = boundary_scope.org.id
  48. type = "password"
  49. }
  50.  
  51.  
  52. # User account policy
  53.  
  54. resource "boundary_auth_method_password" "method_password" {
  55. name = "password"
  56. scope_id = boundary_scope.org.scope_id
  57. min_login_name_length = 3
  58. min_password_length = 10
  59. }
  60.  
  61. resource "boundary_user" "devops_team" {
  62. for_each = var.devops_team
  63. name = each.key
  64. description = "Devops user: ${each.key}"
  65. account_ids = [boundary_account.devops_user_acct[each.value].id]
  66. scope_id = boundary_scope.org.id
  67. }
  68.  
  69.  
  70. # User account creation
  71. resource "boundary_account" "devops_user_acct" {
  72. for_each = var.devops_team
  73. description = "user account"
  74. name = each.key
  75. type = "password"
  76. login_name = lower(each.key)
  77. password = var.default_devops_password
  78. auth_method_id = boundary_auth_method.password.id
  79. }
  80.  
  81.  
  82. // project level group for backend management of org
  83. resource "boundary_group" "devops_core_infra" {
  84. name = "devops"
  85. description = "devops team group"
  86. member_ids = [for user in boundary_user.devops_team : user.id]
  87. scope_id = boundary_scope.org.id
  88. }
  89.  
  90.  
  91. # Allows make any changes in the org
  92. resource "boundary_role" "org_admin" {
  93. name = "devops_role"
  94. description = "DevOps role"
  95. scope_id = boundary_scope.global.id
  96. grant_scope_id = boundary_scope.org.id
  97. grant_strings = [
  98. "id=*;type=*;actions=*"
  99. ]
  100. principal_ids = concat(
  101. [for user in boundary_user.devops_team : user.id],
  102. )
  103. }
  104.  
  105.  
  106.  
  107. # Allows make any changes in the project core_infra
  108. resource "boundary_role" "infra_admin" {
  109. name = "devops_role"
  110. description = "DevOps role"
  111. scope_id = boundary_scope.org.id
  112. grant_scope_id = boundary_scope.core_infra.id
  113. grant_strings = [
  114. "id=*;type=*;actions=*"
  115. ]
  116. principal_ids = concat(
  117. [for user in boundary_user.devops_team : user.id],
  118. )
  119. }
  120.  
  121.  
  122. # Creation of catalog, this store server ip
  123. resource "boundary_host_catalog" "infra_servers" {
  124. name = "infra_servers"
  125. description = "Infraestructure host catalog"
  126. type = "static"
  127. scope_id = boundary_scope.core_infra.id
  128. }
  129.  
  130. # Add static hosts using list of infra_server_ips in variables.tf
  131. resource "boundary_host" "infra_servers" {
  132. for_each = var.infra_server_ips
  133. type = "static"
  134. name = "infra_server_service?${each.value}"
  135. description = "Infraestructure server host"
  136. address = each.key
  137. host_catalog_id = boundary_host_catalog.infra_servers.id
  138. }
  139.  
  140. resource "boundary_host_set" "infra_server_ssh" {
  141. type = "static"
  142. name = "infra_server_ssh"
  143. description = "Host set for infra servers"
  144. host_catalog_id = boundary_host_catalog.infra_servers.id
  145. host_ids = [for host in boundary_host.infra_servers : host.id]
  146.  
  147. }
  148.  
  149. resource "boundary_target" "infra_servers_service" {
  150. type = "tcp"
  151. name = "infra_server"
  152. description = "Infra server target"
  153. scope_id = boundary_scope.core_infra.id
  154. default_port = var.host_port
  155.  
  156. host_set_ids = [
  157. boundary_host_set.infra_server_ssh.id
  158. ]
  159.  
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement