git clone https://github.com/guillermotti/terraform-github-modules.git
cd terraform-github-modules
code .
Enter a name for the organization.
Add a contact email.
Select who will manage the organization.
Skip the step to add organization members, we are going to use this repo to add members.
Submit the last part adding whatever you want.
Click on Generate new token button.
Add a note, for example GitHubOrgTerraform
Select all scopes
Click on Generate token button.
Copy the generated token and keep it in a safe place.
Set up environment variables
Set your own GITHUB_TOKEN, GITHUB_ORG and BILLING_ACCOUNT as environment variables:
export BILLING_ACCOUNT=BILLING_ACCOUNT
export GITHUB_TOKEN=GITHUB_TOKEN
export GITHUB_ORG=GITHUB_ORG
Restrict repository creation
Open Member privileges tab under organization settings window.
Uncheck Private and Public for Repository creation section.
Click on Save button.
Create GCP project and bucket
Run gcloud config configurations list to verify you have an account ready.
Run the following commands:
terraform init
terraform plan -out=fit.plan -var=" billing_account=$BILLING_ACCOUNT "
terraform apply fit.plan
Uncomment the backend block setting the state_bucket output from the previous apply.
Run the following commands:
terraform init # type "yes"
terraform plan -out=fit.plan -var=" billing_account=$BILLING_ACCOUNT "
rm -rf * .state
Edit teams/teams.tf to create any team to the organization.
Run the following commands:
cd terraform-github-modules/teams
terraform init
terraform plan -out=fit.plan -var=" github_token=$GITHUB_TOKEN " -var=" github_organization=$GITHUB_ORG "
terraform apply fit.plan
Edit admins/admins.tf to create any admin to the organization.
Run the following commands:
cd ../admins
terraform init
terraform plan -out=fit.plan -var=" github_token=$GITHUB_TOKEN " -var=" github_organization=$GITHUB_ORG "
terraform apply fit.plan
Edit repos/back/repos.tf to create any repo to the back team in the organization.
Run the following commands:
cd ../repos/back
terraform init
terraform plan -out=fit.plan -var=" github_token=$GITHUB_TOKEN " -var=" github_organization=$GITHUB_ORG "
terraform apply fit.plan
Edit repos/admin/repos.tf to save this configuration in a repository inside the new organization.
cd ../admin
terraform init
terraform plan -out=fit.plan -var=" github_token=$GITHUB_TOKEN " -var=" github_organization=$GITHUB_ORG "
terraform apply fit.plan
git remote rename origin modules
git remote add origin git@github.com:$GITHUB_ORG /admin-terraform-github.git
git push -u origin main --force
cd ../..
git add * .gitignore
git commit -m " Adding TF code"
git push origin main
Edit users/users.tf to invite any user to the organization.
Run the following commands:
cd ../users
terraform init
terraform plan -out=fit.plan -var=" github_token=$GITHUB_TOKEN " -var=" github_organization=$GITHUB_ORG "
terraform apply fit.plan
Create a branch protection
Edit repos/front/repos.tf to create a new repository with a branch protection.
Run the following commands:
cd ../repos/front
terraform init
terraform plan -out=fit.plan -var=" github_token=$GITHUB_TOKEN " -var=" github_organization=$GITHUB_ORG "
terraform apply fit.plan
Pull Request Automation with Atlantis
GitHub Actions with Terraform Cloud
Custom solution with CI/CD tool of your choice