- Install Terraform
- Create GitHub account
- Create GCP account and setup gcloud CLI
git clone https://github.com/guillermotti/terraform-github-modules.git
cd terraform-github-modules
code .Create a GitHub organization
- 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.
Create a token
- 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 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- Open
Member privilegestab under organization settings window. - Uncheck
PrivateandPublicforRepository creationsection. - Click on Save button.
- Run
gcloud config configurations listto 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
backendblock setting thestate_bucketoutput 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- 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