Skip to content

Commit cf24c1b

Browse files
committed
Use PAT to push
1 parent 18e74d1 commit cf24c1b

3 files changed

Lines changed: 23 additions & 18 deletions

File tree

modules/github/main.tf

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,31 @@ terraform {
1414
}
1515

1616
resource "github_repository" "dbt_repo" {
17-
name = "dbt_${var.project_slug}"
18-
description = "Code for the dbt project ${var.project_name}"
17+
name = "dbt_${var.project_slug}"
18+
description = "Code for the dbt project ${var.project_name}"
1919

20-
visibility = "public"
21-
auto_init = false
20+
visibility = "public"
21+
auto_init = false
2222
}
2323

2424

2525
resource "github_branch_protection" "dbt_repo" {
26-
repository_id = github_repository.dbt_repo.node_id
27-
pattern = "main"
28-
enforce_admins = false
26+
repository_id = github_repository.dbt_repo.node_id
27+
pattern = "main"
28+
enforce_admins = false
2929

3030
required_pull_request_reviews {
31-
restrict_dismissals = false
31+
restrict_dismissals = false
3232
required_approving_review_count = 1
3333

3434
}
3535
}
3636

37+
locals {
38+
https_url = github_repository.dbt_repo.http_clone_url
39+
https_url_with_pat = replace(local.https_url, "https://", "https://${var.github_token}@")
40+
}
41+
3742
# this will happen only when the repo is created
3843
resource "null_resource" "post_repo_creation" {
3944
provisioner "local-exec" {
@@ -51,7 +56,7 @@ resource "null_resource" "post_repo_creation" {
5156
git add *
5257
git commit -m "Initial commit from Terraform and cruft"
5358
git branch -M main
54-
git remote add origin ${github_repository.dbt_repo.http_clone_url}
59+
git remote add origin ${local.https_url_with_pat}
5560
git push -u origin main
5661
cd ../..
5762
rm -rf cruft-template

modules/github/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
output "github_repo_remote_url" {
2-
value = github_repository.dbt_repo.ssh_clone_url
2+
value = github_repository.dbt_repo.ssh_clone_url
33
}

modules/github/variables.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
variable "github_token" {
2-
description = "GitHub token to crate repos"
3-
type = string
2+
description = "GitHub token to crate repos"
3+
type = string
44
}
55

66
variable "project_slug" {
7-
description = "Slug for the project"
8-
type = string
7+
description = "Slug for the project"
8+
type = string
99
}
1010

1111
variable "project_name" {
12-
description = "Project Name"
13-
type = string
12+
description = "Project Name"
13+
type = string
1414
}
1515

1616
variable "cruft_template_url" {
17-
description = "URL for the Cruft template"
18-
type = string
17+
description = "URL for the Cruft template"
18+
type = string
1919
}

0 commit comments

Comments
 (0)