Fix Terraform formatting and add module_prefix attribute to modules_config (#1162)
* Fix Terraform formatting and add module/ prefix to path in 0-cicd-github repository population fix the formatting of Terraform files and adds the module/ prefix to the module path in 0-cicd-github under repository population. Without proper formatting and module path, generated repositories may show formatting mismatches and examples in the README.md file may not run as expected. The changes include updating the replace function with a new regular expression pattern to correctly apply the git source for modules and updating the each.value.file attribute to include the module/ prefix in the Terraform file path. This ensures that the examples in the README.md file work as intended and that the generated repositories follow best practices for Terraform code. * revert modules/ prefix change * Add module_prefix to modules_config - Add module_prefix to modules_config - Add example to Readme.md - use module_prefix variable to specify the path * fix tfdoc
This commit is contained in:
parent
0d0a2b4f81
commit
5cf60cbcf4
|
@ -39,6 +39,16 @@ modules_config = {
|
||||||
# tftest skip
|
# tftest skip
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If the modules are located in a non modules only repository, use the module_prefix attribute to set the location of your modules within the repository:
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
modules_config = {
|
||||||
|
repository_name = "GoogleCloudPlatform/cloud-foundation-fabric"
|
||||||
|
module_prefix = "modules/"
|
||||||
|
}
|
||||||
|
# tftest skip
|
||||||
|
```
|
||||||
|
|
||||||
In the above example, no key options are set so it's assumed modules will be fetched from a public repository. If modules repository authentication is needed the `key_config` attribute also needs to be set.
|
In the above example, no key options are set so it's assumed modules will be fetched from a public repository. If modules repository authentication is needed the `key_config` attribute also needs to be set.
|
||||||
|
|
||||||
If no keypair path is specified an internally generated key will be stored as an access key in the modules repository, and as secrets in the stage repositories:
|
If no keypair path is specified an internally generated key will be stored as an access key in the modules repository, and as secrets in the stage repositories:
|
||||||
|
@ -125,10 +135,10 @@ Finally, a `commit_config` variable is optional: it can be used to configure aut
|
||||||
|
|
||||||
| name | description | type | required | default |
|
| name | description | type | required | default |
|
||||||
|---|---|:---:|:---:|:---:|
|
|---|---|:---:|:---:|:---:|
|
||||||
| [organization](variables.tf#L50) | GitHub organization. | <code>string</code> | ✓ | |
|
| [organization](variables.tf#L51) | GitHub organization. | <code>string</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> |
|
| [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) 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> |
|
||||||
| [repositories](variables.tf#L55) | 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#L56) | 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> |
|
||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ locals {
|
||||||
_repository_files = flatten([
|
_repository_files = flatten([
|
||||||
for k, v in var.repositories : [
|
for k, v in var.repositories : [
|
||||||
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}/*.md") : f],
|
[for f in fileset(path.module, "${v.populate_from}/*.md") : f],
|
||||||
[for f in fileset(path.module, "${v.populate_from}/*.tf") : f]
|
[for f in fileset(path.module, "${v.populate_from}/*.tf") : f]
|
||||||
) : {
|
) : {
|
||||||
|
@ -143,8 +144,8 @@ resource "github_repository_file" "default" {
|
||||||
endswith(each.value.name, ".tf") && local.modules_repo != null
|
endswith(each.value.name, ".tf") && local.modules_repo != null
|
||||||
? replace(
|
? replace(
|
||||||
file(each.value.file),
|
file(each.value.file),
|
||||||
"/source\\s*=\\s*\"../../../modules/([^/\"]+)\"/",
|
"/source(\\s*)=\\s*\"../../../modules/([^/\"]+)\"/",
|
||||||
"source = \"git@github.com:${local.modules_repo}.git//$1${local.modules_ref}\"" # "
|
"source$1= \"git@github.com:${local.modules_repo}.git//${local.module_prefix}$2${local.modules_ref}\"" # "
|
||||||
)
|
)
|
||||||
: file(each.value.file)
|
: file(each.value.file)
|
||||||
)
|
)
|
||||||
|
|
|
@ -30,6 +30,7 @@ variable "modules_config" {
|
||||||
type = object({
|
type = object({
|
||||||
repository_name = string
|
repository_name = string
|
||||||
source_ref = optional(string)
|
source_ref = optional(string)
|
||||||
|
module_prefix = optional(string, "")
|
||||||
key_config = optional(object({
|
key_config = optional(object({
|
||||||
create_key = optional(bool, false)
|
create_key = optional(bool, false)
|
||||||
create_secrets = optional(bool, false)
|
create_secrets = optional(bool, false)
|
||||||
|
|
Loading…
Reference in New Issue