Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
feat(module/bootstrap): add possibility to upload whole folder struct…
Browse files Browse the repository at this point in the history
…ure (#300)
  • Loading branch information
FoSix authored Aug 2, 2023
1 parent eb138c3 commit d210b07
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ No modules.
| <a name="input_location"></a> [location](#input\_location) | Region to deploy bootstrap resources. Ignored when `create_storage_account` is set to `false`. | `string` | `null` | no |
| <a name="input_min_tls_version"></a> [min\_tls\_version](#input\_min\_tls\_version) | The minimum supported TLS version for the storage account. | `string` | `"TLS1_2"` | no |
| <a name="input_files"></a> [files](#input\_files) | Map of all files to copy to bucket. The keys are local paths, the values are remote paths.<br>Always use slash `/` as directory separator (unix-like), not the backslash `\`.<br>Example:<pre>files = {<br> "dir/my.txt" = "config/init-cfg.txt"<br>}</pre> | `map(string)` | `{}` | no |
| <a name="input_bootstrap_files_dir"></a> [bootstrap\_files\_dir](#input\_bootstrap\_files\_dir) | Bootstrap file directory. If the variable has a value of `null` (default) - then it will not upload any other files other than the ones specified in the `files` variable. More information can be found at https://docs.paloaltonetworks.com/vm-series/9-1/vm-series-deployment/bootstrap-the-vm-series-firewall/bootstrap-package. | `string` | `null` | no |
| <a name="input_files_md5"></a> [files\_md5](#input\_files\_md5) | Optional map of MD5 hashes of file contents.<br>Normally the map could be empty, because all the files that exist before the `terraform apply` will have their hashes auto-calculated.<br>This input is necessary only for the selected files which are created/modified within the same Terraform run as this module.<br>The keys of the map should be identical with selected keys of the `files` input, while the values should be MD5 hashes of the contents of that file.<br><br>Example:<pre>files_md5 = {<br> "dir/my.txt" = "6f7ce3191b50a58cc13e751a8f7ae3fd"<br>}</pre> | `map(string)` | `{}` | no |
| <a name="input_storage_share_name"></a> [storage\_share\_name](#input\_storage\_share\_name) | Name of a storage File Share to be created that will hold `files` used for bootstrapping.<br>For rules defining a valid name see [Microsoft documentation](https://docs.microsoft.com/en-us/rest/api/storageservices/Naming-and-Referencing-Shares--Directories--Files--and-Metadata#share-names). | `string` | `null` | no |
| <a name="input_storage_share_quota"></a> [storage\_share\_quota](#input\_storage\_share\_quota) | Maximum size of a File Share. | `number` | `50` | no |
Expand Down
11 changes: 10 additions & 1 deletion modules/bootstrap/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
locals {
bootstrap_filenames = { for f in try(fileset(var.bootstrap_files_dir, "**"), {}) : f => "${var.bootstrap_files_dir}/${f}" }
# invert var.files map
inverted_files = { for k, v in var.files : v => k }
inverted_filenames = merge(local.bootstrap_filenames, local.inverted_files)
# invert local.filenames map
filenames = { for k, v in local.inverted_filenames : v => k }
}

resource "azurerm_storage_account" "this" {
count = var.create_storage_account ? 1 : 0

Expand Down Expand Up @@ -86,7 +95,7 @@ resource "azurerm_storage_share_directory" "this" {
}

resource "azurerm_storage_share_file" "this" {
for_each = var.storage_share_name != null ? var.files : {}
for_each = var.storage_share_name != null ? local.filenames : {}

name = regex("[^/]*$", each.value)
path = replace(each.value, "/[/]*[^/]*$/", "")
Expand Down
7 changes: 7 additions & 0 deletions modules/bootstrap/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ variable "files" {
type = map(string)
}

variable "bootstrap_files_dir" {
description = "Bootstrap file directory. If the variable has a value of `null` (default) - then it will not upload any other files other than the ones specified in the `files` variable. More information can be found at https://docs.paloaltonetworks.com/vm-series/9-1/vm-series-deployment/bootstrap-the-vm-series-firewall/bootstrap-package."
default = null
type = string
}


variable "files_md5" {
description = <<-EOF
Optional map of MD5 hashes of file contents.
Expand Down

0 comments on commit d210b07

Please sign in to comment.