-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added examples and refactored codebase
- Loading branch information
1 parent
7708dae
commit 6f8befc
Showing
6 changed files
with
114 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
locals { | ||
# Group service instances by service name | ||
consul_services = { | ||
for id, s in var.services : s.name => s... | ||
} | ||
} | ||
|
||
module "boundary_resources" { | ||
for_each = var.services | ||
|
||
source = "github.com/hashicorp-dev-advocates/terraform-cts-boundary" | ||
|
||
project_scope_id = "p_1234567890" | ||
service_name = each.value["name"] | ||
service_address = each.value["address"] | ||
service_port = each.value["port"] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
provider "boundary" { | ||
addr = var.boundary_address | ||
|
||
auth_method_id = var.auth_method_id | ||
password_auth_method_login_name = var.login_name | ||
password_auth_method_password = var.password | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Boundary variables | ||
variable "boundary_address" { | ||
type = string | ||
description = "Boundary address" | ||
default = "http://localhost:9200" | ||
} | ||
|
||
variable "project_scope_id" { | ||
type = string | ||
description = "Scope ID for Boundary project" | ||
default = "p_1234567890" | ||
} | ||
|
||
variable "auth_method_id" { | ||
type = string | ||
description = "Auth method ID for Terraform to authenticate to." | ||
} | ||
|
||
variable "login_name" { | ||
type = string | ||
description = "Login name for Terraform to authenticate with." | ||
} | ||
|
||
variable "password" { | ||
type = string | ||
description = "Password for Terraform to authenticate with." | ||
sensitive = true | ||
} | ||
|
||
#Consul Terraform Sync variables | ||
variable "services" { | ||
description = "Consul services monitored by Consul-Terraform-Sync" | ||
type = map( | ||
object({ | ||
id = string | ||
name = string | ||
kind = string | ||
address = string | ||
port = number | ||
meta = map(string) | ||
tags = list(string) | ||
namespace = string | ||
status = string | ||
|
||
node = string | ||
node_id = string | ||
node_address = string | ||
node_datacenter = string | ||
node_tagged_addresses = map(string) | ||
node_meta = map(string) | ||
|
||
cts_user_defined_meta = map(string) | ||
}) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,39 @@ | ||
locals { | ||
# Group service instances by service name | ||
consul_services = { | ||
for id, s in var.services : s.name => s... | ||
} | ||
} | ||
|
||
resource "boundary_host_catalog" "host_catalog" { | ||
resource "boundary_host_catalog_static" "host_catalog" { | ||
|
||
for_each = var.services | ||
|
||
name = each.value["name"] | ||
description = "${each.value["name"]} host catalog created by Consul Terraform Sync" | ||
type = "static" | ||
name = var.service_name | ||
description = "${var.service_name} host catalog created by Consul Terraform Sync" | ||
scope_id = var.project_scope_id | ||
} | ||
|
||
resource "boundary_host" "host" { | ||
resource "boundary_host_static" "host" { | ||
|
||
for_each = var.services | ||
|
||
name = each.value["name"] | ||
description = "${each.value["name"]} host created by Consul Terraform Sync" | ||
host_catalog_id = boundary_host_catalog.host_catalog[each.key].id | ||
address = each.value["address"] | ||
name = var.service_name | ||
description = "${var.service_name} host created by Consul Terraform Sync" | ||
host_catalog_id = boundary_host_catalog_static.host_catalog.id | ||
address = var.service_address | ||
|
||
type = "static" | ||
} | ||
|
||
resource "boundary_host_set" "host_set" { | ||
for_each = var.services | ||
|
||
name = each.value["name"] | ||
description = "${each.value["name"]} host set created by Consul Terraform Sync" | ||
host_catalog_id = boundary_host_catalog.host_catalog[each.key].id | ||
resource "boundary_host_set_static" "host_set" { | ||
name = var.service_name | ||
description = "${var.service_name} host set created by Consul Terraform Sync" | ||
host_catalog_id = boundary_host_catalog_static.host_catalog.id | ||
type = "static" | ||
host_ids = [ | ||
boundary_host.host[each.key].id | ||
boundary_host_static.host.id | ||
] | ||
} | ||
|
||
resource "boundary_target" "target" { | ||
for_each = var.services | ||
|
||
name = each.value["name"] | ||
name = var.service_name | ||
type = "tcp" | ||
description = "${each.value["name"]} target created by Consul Terraform Sync" | ||
default_port = each.value["port"] | ||
description = "${var.service_name} target created by Consul Terraform Sync" | ||
default_port = var.service_port | ||
scope_id = var.project_scope_id | ||
host_source_ids = [ | ||
boundary_host_set.host_set[each.key].id | ||
boundary_host_set_static.host_set.id | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
output "consul_services" { | ||
value = local.consul_services | ||
} | ||
#output "consul_services" { | ||
# value = local.consul_services | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,19 @@ | ||
variable "project_scope_id" { | ||
type = string | ||
description = "Scope ID for Boundary project" | ||
} | ||
|
||
variable "services" { | ||
description = "Consul services monitored by Consul-Terraform-Sync" | ||
type = map( | ||
object({ | ||
id = string | ||
name = string | ||
kind = string | ||
address = string | ||
port = number | ||
meta = map(string) | ||
tags = list(string) | ||
namespace = string | ||
status = string | ||
|
||
node = string | ||
node_id = string | ||
node_address = string | ||
node_datacenter = string | ||
node_tagged_addresses = map(string) | ||
node_meta = map(string) | ||
|
||
cts_user_defined_meta = map(string) | ||
}) | ||
) | ||
variable "service_name" { | ||
type = string | ||
description = "Name of Consul Service to register as a host and target in Boundary." | ||
} | ||
|
||
variable "project_scope_id" { | ||
variable "service_address" { | ||
type = string | ||
description = "Scope ID for Boundary project" | ||
default = "p_1234567890" | ||
description = "IP address or DNS name for Consul service to register as a host in Boundary." | ||
} | ||
|
||
variable "service_port" { | ||
type = number | ||
description = "Port of Consul service to register as a target in Boundary." | ||
} |