Skip to content

Commit

Permalink
feat(examples): flexible bootstrap options (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbil authored Apr 18, 2024
1 parent 7a6761c commit a952af8
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 116 deletions.
2 changes: 1 addition & 1 deletion examples/multi_nic_common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ please see https://cloud.google.com/iap/docs/using-tcp-forwarding#increasing_the
| [google_compute_instance.linux_vm](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance) | resource |
| [google_compute_route.this](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_route) | resource |
| [local_file.bootstrap_xml](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_file.init_cfg](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_sensitive_file.init_cfg](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/sensitive_file) | resource |
| [google_compute_image.my_image](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_image) | data source |

### Inputs
Expand Down
17 changes: 7 additions & 10 deletions examples/multi_nic_common/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,17 @@ resource "local_file" "bootstrap_xml" {
)
}

resource "local_file" "init_cfg" {
resource "local_sensitive_file" "init_cfg" {

for_each = { for k, v in var.vmseries : k => v
if can(v.bootstrap_template_map)
}

filename = "files/${each.key}/config/init-cfg.txt"
content = templatefile("templates/init-cfg.tmpl",
{
panorama-server = try(each.value.bootstrap_options.panorama-server, var.vmseries_common.bootstrap_options.panorama-server, "")
type = try(each.value.bootstrap_options.type, var.vmseries_common.bootstrap_options.type, "")
dns-primary = try(each.value.bootstrap_options.dns-primary, var.vmseries_common.bootstrap_options.dns-primary, "")
dns-secondary = try(each.value.bootstrap_options.dns-secondary, var.vmseries_common.bootstrap_options.dns-secondary, "")
})
content = templatefile(
"templates/init-cfg.tmpl",
{ bootstrap_options = merge(var.vmseries_common.bootstrap_options, each.value.bootstrap_options) }
)
}

module "bootstrap" {
Expand All @@ -56,8 +53,8 @@ module "bootstrap" {
service_account = module.iam_service_account[each.value.service_account_key].email
location = each.value.location
files = merge(
{ for k, v in var.vmseries : "files/${k}/config/bootstrap.xml" => "${k}/config/bootstrap.xml" },
{ for k, v in var.vmseries : "files/${k}/config/init-cfg.txt" => "${k}/config/init-cfg.txt" },
{ for k, v in var.vmseries : "files/${k}/config/bootstrap.xml" => "${k}/config/bootstrap.xml" if can(v.bootstrap_template_map) },
{ for k, v in var.vmseries : "files/${k}/config/init-cfg.txt" => "${k}/config/init-cfg.txt" if can(v.bootstrap_template_map) },
)
}

Expand Down
15 changes: 3 additions & 12 deletions examples/multi_nic_common/templates/init-cfg.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
%{ if panorama-server != "" ~}
panorama-server=${panorama-server}
%{ endif ~}
%{ if type != "" ~}
type=${type}
%{ endif ~}
%{ if dns-primary != "" ~}
dns-primary=${dns-primary}
%{ endif ~}
%{ if dns-secondary != "" ~}
dns-secondary=${dns-secondary}
%{ endif ~}
%{ for k, v in bootstrap_options ~}
${k}=${v}
%{ endfor ~}
2 changes: 1 addition & 1 deletion examples/vmseries_ha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ Check the succesful inbound and outbound traffic fail-over to and from the spoke
| [google_compute_instance.linux_vm](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance) | resource |
| [google_compute_route.this](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_route) | resource |
| [local_file.bootstrap_xml](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_file.init_cfg](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_sensitive_file.init_cfg](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/sensitive_file) | resource |
| [google_compute_image.my_image](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_image) | data source |

### Inputs
Expand Down
19 changes: 8 additions & 11 deletions examples/vmseries_ha/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,17 @@ resource "local_file" "bootstrap_xml" {
)
}

resource "local_file" "init_cfg" {
resource "local_sensitive_file" "init_cfg" {

for_each = { for k, v in var.vmseries : k => v
if can(v.bootstrap_template_map)
}

filename = "files/${each.key}/config/init-cfg.txt"
content = templatefile("templates/init-cfg.tmpl",
{
panorama-server = try(each.value.bootstrap_options.panorama-server, var.vmseries_common.bootstrap_options.panorama-server, "")
type = try(each.value.bootstrap_options.type, var.vmseries_common.bootstrap_options.type, "")
dns-primary = try(each.value.bootstrap_options.dns-primary, var.vmseries_common.bootstrap_options.dns-primary, "")
dns-secondary = try(each.value.bootstrap_options.dns-secondary, var.vmseries_common.bootstrap_options.dns-secondary, "")
})
content = templatefile(
"templates/init-cfg.tmpl",
{ bootstrap_options = merge(var.vmseries_common.bootstrap_options, each.value.bootstrap_options) }
)
}

module "bootstrap" {
Expand All @@ -59,10 +56,10 @@ module "bootstrap" {
service_account = module.iam_service_account[each.value.service_account_key].email
location = each.value.location
files = merge(
{ for k, v in var.vmseries : "files/${k}/config/bootstrap.xml" => "${k}/config/bootstrap.xml" },
{ for k, v in var.vmseries : "files/${k}/config/init-cfg.txt" => "${k}/config/init-cfg.txt" },
{ for k, v in var.vmseries : "files/${k}/config/bootstrap.xml" => "${k}/config/bootstrap.xml" if can(v.bootstrap_template_map) },
{ for k, v in var.vmseries : "files/${k}/config/init-cfg.txt" => "${k}/config/init-cfg.txt" if can(v.bootstrap_template_map) },
)
depends_on = [local_file.bootstrap_xml, local_file.init_cfg]
depends_on = [local_file.bootstrap_xml, local_sensitive_file.init_cfg]
}

module "vpc" {
Expand Down
15 changes: 3 additions & 12 deletions examples/vmseries_ha/templates/init-cfg.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
%{ if panorama-server != "" ~}
panorama-server=${panorama-server}
%{ endif ~}
%{ if type != "" ~}
type=${type}
%{ endif ~}
%{ if dns-primary != "" ~}
dns-primary=${dns-primary}
%{ endif ~}
%{ if dns-secondary != "" ~}
dns-secondary=${dns-secondary}
%{ endif ~}
%{ for k, v in bootstrap_options ~}
${k}=${v}
%{ endfor ~}
2 changes: 1 addition & 1 deletion examples/vpc_peering_common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ please see https://cloud.google.com/iap/docs/using-tcp-forwarding#increasing_the
| [google_compute_instance.linux_vm](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance) | resource |
| [google_compute_route.this](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_route) | resource |
| [local_file.bootstrap_xml](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_file.init_cfg](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_sensitive_file.init_cfg](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/sensitive_file) | resource |
| [google_compute_image.my_image](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_image) | data source |

### Inputs
Expand Down
17 changes: 7 additions & 10 deletions examples/vpc_peering_common/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@ resource "local_file" "bootstrap_xml" {
)
}

resource "local_file" "init_cfg" {
resource "local_sensitive_file" "init_cfg" {

for_each = { for k, v in var.vmseries : k => v
if can(v.bootstrap_template_map)
}

filename = "files/${each.key}/config/init-cfg.txt"
content = templatefile("templates/init-cfg.tmpl",
{
panorama-server = try(each.value.bootstrap_options.panorama-server, var.vmseries_common.bootstrap_options.panorama-server, "")
type = try(each.value.bootstrap_options.type, var.vmseries_common.bootstrap_options.type, "")
dns-primary = try(each.value.bootstrap_options.dns-primary, var.vmseries_common.bootstrap_options.dns-primary, "")
dns-secondary = try(each.value.bootstrap_options.dns-secondary, var.vmseries_common.bootstrap_options.dns-secondary, "")
})
content = templatefile(
"templates/init-cfg.tmpl",
{ bootstrap_options = merge(var.vmseries_common.bootstrap_options, each.value.bootstrap_options) }
)
}

module "bootstrap" {
Expand All @@ -54,8 +51,8 @@ module "bootstrap" {
service_account = module.iam_service_account[each.value.service_account_key].email
location = each.value.location
files = merge(
{ for k, v in var.vmseries : "files/${k}/config/bootstrap.xml" => "${k}/config/bootstrap.xml" },
{ for k, v in var.vmseries : "files/${k}/config/init-cfg.txt" => "${k}/config/init-cfg.txt" },
{ for k, v in var.vmseries : "files/${k}/config/bootstrap.xml" => "${k}/config/bootstrap.xml" if can(v.bootstrap_template_map) },
{ for k, v in var.vmseries : "files/${k}/config/init-cfg.txt" => "${k}/config/init-cfg.txt" if can(v.bootstrap_template_map) },
)
}

Expand Down
15 changes: 3 additions & 12 deletions examples/vpc_peering_common/templates/init-cfg.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
%{ if panorama-server != "" ~}
panorama-server=${panorama-server}
%{ endif ~}
%{ if type != "" ~}
type=${type}
%{ endif ~}
%{ if dns-primary != "" ~}
dns-primary=${dns-primary}
%{ endif ~}
%{ if dns-secondary != "" ~}
dns-secondary=${dns-secondary}
%{ endif ~}
%{ for k, v in bootstrap_options ~}
${k}=${v}
%{ endfor ~}
2 changes: 1 addition & 1 deletion examples/vpc_peering_common_with_network_tags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ please see https://cloud.google.com/iap/docs/using-tcp-forwarding#increasing_the
| [google_compute_instance.linux_vm](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance) | resource |
| [google_compute_route.route](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_route) | resource |
| [local_file.bootstrap_xml](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_file.init_cfg](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_sensitive_file.init_cfg](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/sensitive_file) | resource |
| [google_compute_image.my_image](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_image) | data source |

### Inputs
Expand Down
17 changes: 7 additions & 10 deletions examples/vpc_peering_common_with_network_tags/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@ resource "local_file" "bootstrap_xml" {
)
}

resource "local_file" "init_cfg" {
resource "local_sensitive_file" "init_cfg" {

for_each = { for k, v in var.vmseries : k => v
if can(v.bootstrap_template_map)
}

filename = "files/${each.key}/config/init-cfg.txt"
content = templatefile("templates/init-cfg.tmpl",
{
panorama-server = try(each.value.bootstrap_options.panorama-server, var.vmseries_common.bootstrap_options.panorama-server, "")
type = try(each.value.bootstrap_options.type, var.vmseries_common.bootstrap_options.type, "")
dns-primary = try(each.value.bootstrap_options.dns-primary, var.vmseries_common.bootstrap_options.dns-primary, "")
dns-secondary = try(each.value.bootstrap_options.dns-secondary, var.vmseries_common.bootstrap_options.dns-secondary, "")
})
content = templatefile(
"templates/init-cfg.tmpl",
{ bootstrap_options = merge(var.vmseries_common.bootstrap_options, each.value.bootstrap_options) }
)
}

module "bootstrap" {
Expand All @@ -54,8 +51,8 @@ module "bootstrap" {
service_account = module.iam_service_account[each.value.service_account_key].email
location = each.value.location
files = merge(
{ for k, v in var.vmseries : "files/${k}/config/bootstrap.xml" => "${k}/config/bootstrap.xml" },
{ for k, v in var.vmseries : "files/${k}/config/init-cfg.txt" => "${k}/config/init-cfg.txt" },
{ for k, v in var.vmseries : "files/${k}/config/bootstrap.xml" => "${k}/config/bootstrap.xml" if can(v.bootstrap_template_map) },
{ for k, v in var.vmseries : "files/${k}/config/init-cfg.txt" => "${k}/config/init-cfg.txt" if can(v.bootstrap_template_map) },
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
%{ if panorama-server != "" ~}
panorama-server=${panorama-server}
%{ endif ~}
%{ if type != "" ~}
type=${type}
%{ endif ~}
%{ if dns-primary != "" ~}
dns-primary=${dns-primary}
%{ endif ~}
%{ if dns-secondary != "" ~}
dns-secondary=${dns-secondary}
%{ endif ~}
%{ for k, v in bootstrap_options ~}
${k}=${v}
%{ endfor ~}
2 changes: 1 addition & 1 deletion examples/vpc_peering_dedicated/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ The GCP Global HTTP LB acts as a proxy and sends traffic to the VM-Series `Untru
| [google_compute_instance.linux_vm](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance) | resource |
| [google_compute_route.this](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_route) | resource |
| [local_file.bootstrap_xml](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_file.init_cfg](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_sensitive_file.init_cfg](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/sensitive_file) | resource |
| [google_compute_image.my_image](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_image) | data source |

### Inputs
Expand Down
17 changes: 7 additions & 10 deletions examples/vpc_peering_dedicated/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@ resource "local_file" "bootstrap_xml" {
)
}

resource "local_file" "init_cfg" {
resource "local_sensitive_file" "init_cfg" {

for_each = { for k, v in var.vmseries : k => v
if can(v.bootstrap_template_map)
}

filename = "files/${each.key}/config/init-cfg.txt"
content = templatefile("templates/init-cfg.tmpl",
{
panorama-server = try(each.value.bootstrap_options.panorama-server, var.vmseries_common.bootstrap_options.panorama-server, "")
type = try(each.value.bootstrap_options.type, var.vmseries_common.bootstrap_options.type, "")
dns-primary = try(each.value.bootstrap_options.dns-primary, var.vmseries_common.bootstrap_options.dns-primary, "")
dns-secondary = try(each.value.bootstrap_options.dns-secondary, var.vmseries_common.bootstrap_options.dns-secondary, "")
})
content = templatefile(
"templates/init-cfg.tmpl",
{ bootstrap_options = merge(var.vmseries_common.bootstrap_options, each.value.bootstrap_options) }
)
}

module "bootstrap" {
Expand All @@ -54,8 +51,8 @@ module "bootstrap" {
service_account = module.iam_service_account[each.value.service_account_key].email
location = each.value.location
files = merge(
{ for k, v in var.vmseries : "files/${k}/config/bootstrap.xml" => "${k}/config/bootstrap.xml" },
{ for k, v in var.vmseries : "files/${k}/config/init-cfg.txt" => "${k}/config/init-cfg.txt" },
{ for k, v in var.vmseries : "files/${k}/config/bootstrap.xml" => "${k}/config/bootstrap.xml" if can(v.bootstrap_template_map) },
{ for k, v in var.vmseries : "files/${k}/config/init-cfg.txt" => "${k}/config/init-cfg.txt" if can(v.bootstrap_template_map) },
)
}

Expand Down
15 changes: 3 additions & 12 deletions examples/vpc_peering_dedicated/templates/init-cfg.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
%{ if panorama-server != "" ~}
panorama-server=${panorama-server}
%{ endif ~}
%{ if type != "" ~}
type=${type}
%{ endif ~}
%{ if dns-primary != "" ~}
dns-primary=${dns-primary}
%{ endif ~}
%{ if dns-secondary != "" ~}
dns-secondary=${dns-secondary}
%{ endif ~}
%{ for k, v in bootstrap_options ~}
${k}=${v}
%{ endfor ~}

0 comments on commit a952af8

Please sign in to comment.