0

I have more than 40 Terraform modules to register in a private Terraform Enterprise module registry.

It would be difficult to create 40 GitHub repositories for each of the 40 modules I am publishing.

Is it possible to have one GitHub repository and have one sub-directory per module (means 40 directories for 40 modules) ? This way, I need to manage only one repository and have all modules in its subdirectories.

Allan Xu
  • 7,998
  • 11
  • 51
  • 122

1 Answers1

1

You can use root module for the 40 modules and call submodule by //sub_module_folder at the end of source parameter.

but a better solution would be use Terraform to Automate the addition of the 40 modules using tfe_registry_module

basic usage:

resource "tfe_organization" "test-organization" {
  name  = "my-org-name"
  email = "admin@company.com"
}

resource "tfe_oauth_client" "test-oauth-client" {
  organization     = tfe_organization.test-organization.name
  api_url          = "https://api.github.com"
  http_url         = "https://github.com"
  oauth_token      = "my-vcs-provider-token"
  service_provider = "github"
}

resource "tfe_registry_module" "test-registry-module" {
  vcs_repo {
    display_identifier = "gh-org-name/terraform-provider-name"
    identifier         = "gh-org-name/terraform-provider-name"
    oauth_token_id     = tfe_oauth_client.test-oauth-client.oauth_token_id
  }
}
resource "tfe_registry_module" "test-registry-module-2" {
  vcs_repo {
    display_identifier = "gh-org-name/terraform-provider-name-2"
    identifier         = "gh-org-name/terraform-provider-name-2"
    oauth_token_id     = tfe_oauth_client.test-oauth-client.oauth_token_id
  }
}
  • In regards to this comment , "call submodule by //sub_module_folder at the end of source parameter." , what is the **source ** parameter? where does it apply? Would be able to ellaborate? – Allan Xu Feb 10 '21 at 19:23
  • 1
    for example you can use one repo for all modules, and point the source argument in module block to something like `git::https://example.com/network.git//modules/vpc` – Mohammed Almusaddar Feb 10 '21 at 20:17
  • Thanks so much. Doe this meant the answer to the title question is "Yes"? The title question is "Can I store a module’s source code in a subdirectory of an existing GitHub repository?" – Allan Xu Feb 10 '21 at 21:03
  • I am stuck and the answer to above question greatly helps.Thank you so much. – Allan Xu Feb 10 '21 at 21:04