diff --git a/fast/extras/0-cicd-github/README.md b/fast/extras/0-cicd-github/README.md
index fc4a30c6..f388c8db 100644
--- a/fast/extras/0-cicd-github/README.md
+++ b/fast/extras/0-cicd-github/README.md
@@ -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.
+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
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. | object({…})
| | {}
|
| [modules_config](variables.tf#L28) | Configure access to repository module via key, and replacement for modules sources in stage repositories. | object({…})
| | null
|
| [pull_request_config](variables.tf#L56) | Configure pull request metadata. | object({…})
| | {}
|
-| [repositories](variables.tf#L69) | Repositories to create. | map(object({…}))
| | {}
|
+| [repositories](variables.tf#L69) | Repositories to create. | map(object({…}))
| | {}
|
## Outputs
diff --git a/fast/extras/0-cicd-github/main.tf b/fast/extras/0-cicd-github/main.tf
index 37607435..35665763 100644
--- a/fast/extras/0-cicd-github/main.tf
+++ b/fast/extras/0-cicd-github/main.tf
@@ -20,11 +20,13 @@ locals {
for f in concat(
[for f in fileset(path.module, "${v.populate_from}/*.svg") : 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]
) : {
repository = k
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
])
@@ -139,7 +141,7 @@ resource "github_actions_secret" "default" {
resource "github_branch" "default" {
for_each = (
try(var.pull_request_config.create, null) == true
- ? local.repositories
+ ? github_repository.default
: {}
)
repository = each.key
@@ -150,7 +152,7 @@ resource "github_branch" "default" {
resource "github_repository_file" "default" {
for_each = local.modules_repo == null ? {} : local.repository_files
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
content = (
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_email = var.commmit_config.email
overwrite_on_create = true
-
- lifecycle {
- ignore_changes = [
- content,
- ]
- }
}
resource "github_repository_pull_request" "default" {
for_each = (
try(var.pull_request_config.create, null) == true
- ? local.repositories
+ ? github_repository.default
: {}
)
base_repository = each.key
title = var.pull_request_config.title
body = var.pull_request_config.body
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
+ ]
+}
\ No newline at end of file
diff --git a/fast/extras/0-cicd-github/variables.tf b/fast/extras/0-cicd-github/variables.tf
index 63854ffb..88187fc2 100644
--- a/fast/extras/0-cicd-github/variables.tf
+++ b/fast/extras/0-cicd-github/variables.tf
@@ -93,7 +93,8 @@ variable "repositories" {
}), {})
visibility = optional(string, "private")
}))
- populate_from = optional(string)
+ populate_from = optional(string)
+ populate_samples = optional(bool, false)
}))
default = {}
nullable = true