Merge pull request #1240 from antonkovach/feature/fast-cicd-github-enable-populating-of-data-directory-sample-files-and-update-dependencies
feat: Enable populating of data directory and .sample files and update dependencies in 0-cicd-github
This commit is contained in:
commit
d7991709c3
|
@ -114,6 +114,39 @@ The `create_options` repository attribute controls creation: if the attribute is
|
||||||
|
|
||||||
Initial population depends on a modules repository being configured in the `modules_config` variable described in the preceding section and on the`populate_from` attributes in each repository where population is required, which point to the folder holding the files to be committed.
|
Initial population depends on a modules repository being configured in the `modules_config` variable described in the preceding section and on the`populate_from` attributes in each repository where population is required, which point to the folder holding the files to be committed.
|
||||||
|
|
||||||
|
Each repository may contain some sample tfvars and data files that can be used as a starting point for your own files. By default, the samples are not populate. However, you can enable this by setting the `populate_samples` attribute to `true`. Here's an updated example:
|
||||||
|
|
||||||
|
```tfvars
|
||||||
|
repositories = {
|
||||||
|
fast_00_bootstrap = {
|
||||||
|
create_options = {
|
||||||
|
description = "FAST bootstrap."
|
||||||
|
features = {
|
||||||
|
issues = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
populate_from = "../../stages/0-bootstrap"
|
||||||
|
populate_samples = true
|
||||||
|
}
|
||||||
|
fast_01_resman = {
|
||||||
|
create_options = {
|
||||||
|
description = "FAST resource management."
|
||||||
|
features = {
|
||||||
|
issues = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
populate_from = "../../stages/1-resman"
|
||||||
|
populate_samples = true
|
||||||
|
}
|
||||||
|
fast_02_networking = {
|
||||||
|
populate_from = "../../stages/2-networking-peering"
|
||||||
|
populate_samples = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# tftest skip
|
||||||
|
|
||||||
|
Please note that setting `populate_samples` to `true` will populate the sample files to the repository, potentially overwriting any existing files with the same name. To minimize the risk of overwriting existing files, we populate the original `data` directory to a `data.sample` directory. In any case, be careful when enabling this option and review commit history to check any changes made to the sample files.
|
||||||
|
|
||||||
### Commit configuration
|
### Commit configuration
|
||||||
|
|
||||||
An optional variable `commit_config` can be used to configure the author, email, and message used in commits for the initial population of files. Its defaults are probably fine for most use cases.
|
An optional variable `commit_config` can be used to configure the author, email, and message used in commits for the initial population of files. Its defaults are probably fine for most use cases.
|
||||||
|
@ -158,7 +191,7 @@ terraform state list | grep github_repository_file | awk '{print "terraform stat
|
||||||
| [commmit_config](variables.tf#L17) | Configure commit metadata. | <code title="object({ author = optional(string, "FAST loader") email = optional(string, "fast-loader@fast.gcp.tf") message = optional(string, "FAST initial loading") })">object({…})</code> | | <code>{}</code> |
|
| [commmit_config](variables.tf#L17) | Configure commit metadata. | <code title="object({ author = optional(string, "FAST loader") email = optional(string, "fast-loader@fast.gcp.tf") message = optional(string, "FAST initial loading") })">object({…})</code> | | <code>{}</code> |
|
||||||
| [modules_config](variables.tf#L28) | Configure access to repository module via key, and replacement for modules sources in stage repositories. | <code title="object({ repository_name = string source_ref = optional(string) module_prefix = optional(string, "") key_config = optional(object({ create_key = optional(bool, false) create_secrets = optional(bool, false) keypair_path = optional(string) }), {}) })">object({…})</code> | | <code>null</code> |
|
| [modules_config](variables.tf#L28) | Configure access to repository module via key, and replacement for modules sources in stage repositories. | <code title="object({ repository_name = string source_ref = optional(string) module_prefix = optional(string, "") key_config = optional(object({ create_key = optional(bool, false) create_secrets = optional(bool, false) keypair_path = optional(string) }), {}) })">object({…})</code> | | <code>null</code> |
|
||||||
| [pull_request_config](variables.tf#L56) | Configure pull request metadata. | <code title="object({ create = optional(bool, false) title = optional(string, "FAST: initial loading or update") body = optional(string, "") base_ref = optional(string, "main") head_ref = optional(string, "fast-loader") })">object({…})</code> | | <code>{}</code> |
|
| [pull_request_config](variables.tf#L56) | Configure pull request metadata. | <code title="object({ create = optional(bool, false) title = optional(string, "FAST: initial loading or update") body = optional(string, "") base_ref = optional(string, "main") head_ref = optional(string, "fast-loader") })">object({…})</code> | | <code>{}</code> |
|
||||||
| [repositories](variables.tf#L69) | Repositories to create. | <code title="map(object({ create_options = optional(object({ allow = optional(object({ auto_merge = optional(bool) merge_commit = optional(bool) rebase_merge = optional(bool) squash_merge = optional(bool) })) auto_init = optional(bool) description = optional(string) features = optional(object({ issues = optional(bool) projects = optional(bool) wiki = optional(bool) })) templates = optional(object({ gitignore = optional(string, "Terraform") license = optional(string) repository = optional(object({ name = string owner = string })) }), {}) visibility = optional(string, "private") })) populate_from = optional(string) }))">map(object({…}))</code> | | <code>{}</code> |
|
| [repositories](variables.tf#L69) | Repositories to create. | <code title="map(object({ create_options = optional(object({ allow = optional(object({ auto_merge = optional(bool) merge_commit = optional(bool) rebase_merge = optional(bool) squash_merge = optional(bool) })) auto_init = optional(bool) description = optional(string) features = optional(object({ issues = optional(bool) projects = optional(bool) wiki = optional(bool) })) templates = optional(object({ gitignore = optional(string, "Terraform") license = optional(string) repository = optional(object({ name = string owner = string })) }), {}) visibility = optional(string, "private") })) populate_from = optional(string) populate_samples = optional(bool, false) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,13 @@ locals {
|
||||||
for f in concat(
|
for f in concat(
|
||||||
[for f in fileset(path.module, "${v.populate_from}/*.svg") : f],
|
[for f in fileset(path.module, "${v.populate_from}/*.svg") : f],
|
||||||
[for f in fileset(path.module, "${v.populate_from}/*.md") : f],
|
[for f in fileset(path.module, "${v.populate_from}/*.md") : f],
|
||||||
|
(v.populate_samples ? [for f in fileset(path.module, "${v.populate_from}/*.sample") : f] : []),
|
||||||
|
(v.populate_samples ? [for f in fileset(path.module, "${v.populate_from}/data/**/*.*") : f] : []),
|
||||||
[for f in fileset(path.module, "${v.populate_from}/*.tf") : f]
|
[for f in fileset(path.module, "${v.populate_from}/*.tf") : f]
|
||||||
) : {
|
) : {
|
||||||
repository = k
|
repository = k
|
||||||
file = f
|
file = f
|
||||||
name = replace(f, "${v.populate_from}/", "")
|
name = replace(replace(f, "${v.populate_from}/", ""), (v.populate_samples ? "data/" : ""), (v.populate_samples ? "data.sample/" : ""))
|
||||||
}
|
}
|
||||||
] if v.populate_from != null
|
] if v.populate_from != null
|
||||||
])
|
])
|
||||||
|
@ -139,7 +141,7 @@ resource "github_actions_secret" "default" {
|
||||||
resource "github_branch" "default" {
|
resource "github_branch" "default" {
|
||||||
for_each = (
|
for_each = (
|
||||||
try(var.pull_request_config.create, null) == true
|
try(var.pull_request_config.create, null) == true
|
||||||
? local.repositories
|
? github_repository.default
|
||||||
: {}
|
: {}
|
||||||
)
|
)
|
||||||
repository = each.key
|
repository = each.key
|
||||||
|
@ -150,7 +152,7 @@ resource "github_branch" "default" {
|
||||||
resource "github_repository_file" "default" {
|
resource "github_repository_file" "default" {
|
||||||
for_each = local.modules_repo == null ? {} : local.repository_files
|
for_each = local.modules_repo == null ? {} : local.repository_files
|
||||||
repository = local.repositories[each.value.repository]
|
repository = local.repositories[each.value.repository]
|
||||||
branch = try(var.pull_request_config.head_ref, "main")
|
branch = var.pull_request_config.create == true ? github_branch.default[each.value.repository].branch : "main"
|
||||||
file = each.value.name
|
file = each.value.name
|
||||||
content = (
|
content = (
|
||||||
endswith(each.value.name, ".tf") && local.modules_repo != null
|
endswith(each.value.name, ".tf") && local.modules_repo != null
|
||||||
|
@ -165,23 +167,21 @@ resource "github_repository_file" "default" {
|
||||||
commit_author = var.commmit_config.author
|
commit_author = var.commmit_config.author
|
||||||
commit_email = var.commmit_config.email
|
commit_email = var.commmit_config.email
|
||||||
overwrite_on_create = true
|
overwrite_on_create = true
|
||||||
|
|
||||||
lifecycle {
|
|
||||||
ignore_changes = [
|
|
||||||
content,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "github_repository_pull_request" "default" {
|
resource "github_repository_pull_request" "default" {
|
||||||
for_each = (
|
for_each = (
|
||||||
try(var.pull_request_config.create, null) == true
|
try(var.pull_request_config.create, null) == true
|
||||||
? local.repositories
|
? github_repository.default
|
||||||
: {}
|
: {}
|
||||||
)
|
)
|
||||||
base_repository = each.key
|
base_repository = each.key
|
||||||
title = var.pull_request_config.title
|
title = var.pull_request_config.title
|
||||||
body = var.pull_request_config.body
|
body = var.pull_request_config.body
|
||||||
base_ref = var.pull_request_config.base_ref
|
base_ref = var.pull_request_config.base_ref
|
||||||
head_ref = var.pull_request_config.head_ref
|
head_ref = github_branch.default[each.key].branch
|
||||||
|
|
||||||
|
depends_on = [
|
||||||
|
github_repository_file.default
|
||||||
|
]
|
||||||
}
|
}
|
|
@ -93,7 +93,8 @@ variable "repositories" {
|
||||||
}), {})
|
}), {})
|
||||||
visibility = optional(string, "private")
|
visibility = optional(string, "private")
|
||||||
}))
|
}))
|
||||||
populate_from = optional(string)
|
populate_from = optional(string)
|
||||||
|
populate_samples = optional(bool, false)
|
||||||
}))
|
}))
|
||||||
default = {}
|
default = {}
|
||||||
nullable = true
|
nullable = true
|
||||||
|
|
Loading…
Reference in New Issue