Skip to content

Instantly share code, notes, and snippets.

@devops-adeel
Created May 4, 2022 13:28
Show Gist options
  • Save devops-adeel/3adf4395a91d45cbccbc89aecafb3cd4 to your computer and use it in GitHub Desktop.
Save devops-adeel/3adf4395a91d45cbccbc89aecafb3cd4 to your computer and use it in GitHub Desktop.
series of code to automate tf-module-setup
/**
* Usage:
*
* ```hcl
*
* module "github_repo" {
* source = "hashicorp/github_terraform_module"
* application_name = "foo"
* tfc_token = vault_terraform_cloud_secret_creds.default.token
* }
* ```
*/
resource "github_repository" "default" {
name = var.application_name
description = format("Terraform Module for %s", var.application_name)
visibility = "private"
template {
owner = "github_org"
repository = "terraform-module-template"
}
resource "github_branch_default" "default" {
repository = github_repository.default.name
branch = "main"
}
resource "github_actions_secret" "default" {
repository = github_repository.default.name
secret_name = "tfc_token"
plaintext_value = var.tfc_token
}
module "github" {
source = "hashicorp/github_repo"
application_name = var.application_name
tfc_token = module.tfc.token
}
module "tfc" {
source = "hashicorp/terraform_workspace"
application_name = var.application_name
email = var.email
username = var.username
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment