From cf24c1bbaec207f6be7e81d8a9144296f5fb2450 Mon Sep 17 00:00:00 2001 From: Benoit Perigaud <8754100+b-per@users.noreply.github.com> Date: Thu, 5 Oct 2023 12:47:23 +0200 Subject: [PATCH] Use PAT to push --- modules/github/main.tf | 23 ++++++++++++++--------- modules/github/outputs.tf | 2 +- modules/github/variables.tf | 16 ++++++++-------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/modules/github/main.tf b/modules/github/main.tf index 680a45d..293d487 100644 --- a/modules/github/main.tf +++ b/modules/github/main.tf @@ -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" { @@ -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 diff --git a/modules/github/outputs.tf b/modules/github/outputs.tf index 21c5934..a8e3ed6 100644 --- a/modules/github/outputs.tf +++ b/modules/github/outputs.tf @@ -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 } \ No newline at end of file diff --git a/modules/github/variables.tf b/modules/github/variables.tf index 05df4a6..ee88f58 100644 --- a/modules/github/variables.tf +++ b/modules/github/variables.tf @@ -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 } \ No newline at end of file