Skip to content

Commit

Permalink
Use PAT to push
Browse files Browse the repository at this point in the history
  • Loading branch information
b-per committed Oct 5, 2023
1 parent 18e74d1 commit cf24c1b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
23 changes: 14 additions & 9 deletions modules/github/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,31 @@ terraform {
}

resource "github_repository" "dbt_repo" {
name = "dbt_${var.project_slug}"
description = "Code for the dbt project ${var.project_name}"
name = "dbt_${var.project_slug}"
description = "Code for the dbt project ${var.project_name}"

visibility = "public"
auto_init = false
visibility = "public"
auto_init = false
}


resource "github_branch_protection" "dbt_repo" {
repository_id = github_repository.dbt_repo.node_id
pattern = "main"
enforce_admins = false
repository_id = github_repository.dbt_repo.node_id
pattern = "main"
enforce_admins = false

required_pull_request_reviews {
restrict_dismissals = false
restrict_dismissals = false
required_approving_review_count = 1

}
}

locals {
https_url = github_repository.dbt_repo.http_clone_url
https_url_with_pat = replace(local.https_url, "https://", "https://${var.github_token}@")
}

# this will happen only when the repo is created
resource "null_resource" "post_repo_creation" {
provisioner "local-exec" {
Expand All @@ -51,7 +56,7 @@ resource "null_resource" "post_repo_creation" {
git add *
git commit -m "Initial commit from Terraform and cruft"
git branch -M main
git remote add origin ${github_repository.dbt_repo.http_clone_url}
git remote add origin ${local.https_url_with_pat}
git push -u origin main
cd ../..
rm -rf cruft-template
Expand Down
2 changes: 1 addition & 1 deletion modules/github/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "github_repo_remote_url" {
value = github_repository.dbt_repo.ssh_clone_url
value = github_repository.dbt_repo.ssh_clone_url
}
16 changes: 8 additions & 8 deletions modules/github/variables.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
variable "github_token" {
description = "GitHub token to crate repos"
type = string
description = "GitHub token to crate repos"
type = string
}

variable "project_slug" {
description = "Slug for the project"
type = string
description = "Slug for the project"
type = string
}

variable "project_name" {
description = "Project Name"
type = string
description = "Project Name"
type = string
}

variable "cruft_template_url" {
description = "URL for the Cruft template"
type = string
description = "URL for the Cruft template"
type = string
}

0 comments on commit cf24c1b

Please sign in to comment.