From 402211338bfa2c4a0d731cf1266699fb84932871 Mon Sep 17 00:00:00 2001 From: Daniel M Date: Mon, 2 Sep 2024 08:25:43 -0600 Subject: [PATCH] Import repo action (#39) --- README.md | 9 ++------- terraform/production/repositories.tfvars | 15 ++++++++++++--- terraform/resources-repos.tf | 8 ++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b17478f..cef3d80 100644 --- a/README.md +++ b/README.md @@ -158,15 +158,10 @@ repositories = { } ``` -2. Import the repository into the terraform state by - running `terraform import -var-file=production/org.tfvars -var-file=production/repositories.tfvars -var github_token=... 'github_repository.this["repo-name"]' repo-name` -3. Run `terraform plan -var-file=production/org.tfvars -var-file=production/repositories.tfvars -var github_token=...` - to see the changes that will be made. - -4. Create a pull-request to `main` branch. This will trigger terraform to plan the changes in the organization to be +2. Create a pull-request to `main` branch. This will trigger terraform to plan the changes in the organization to be executed. Review the changes and make sure they align with the request. -5. Merge the pull request. This will trigger terraform to apply the changes in the organization. +3. Merge the pull request. This will trigger terraform to apply the changes in the organization. The expected changes: diff --git a/terraform/production/repositories.tfvars b/terraform/production/repositories.tfvars index 43a0910..211aba5 100644 --- a/terraform/production/repositories.tfvars +++ b/terraform/production/repositories.tfvars @@ -1,6 +1,5 @@ # Organization repositories repositories = { - # Keep the following repositories in alphabetical order ".github" = { description = "A Special Repository." @@ -54,8 +53,18 @@ repositories = { } "django-tasks-scheduler" = { - description = "Schedule async tasks using redis pub/sub." - homepage_url = "https://django-tasks-scheduler.readthedocs.io/" + description = "Schedule async tasks using redis pub/sub." + homepage_url = "https://django-tasks-scheduler.readthedocs.io/" + allow_merge_commit = true + admins = [ + "cunla", + ] + committers = [] + members = [] + } + + "playground2" = { + description = "Tests" admins = [ "cunla", diff --git a/terraform/resources-repos.tf b/terraform/resources-repos.tf index dad9bf9..e9c8afc 100644 --- a/terraform/resources-repos.tf +++ b/terraform/resources-repos.tf @@ -1,6 +1,14 @@ # Github Repository Resource # https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository +# Try to import the repository if it already exists +import { + for_each = var.repositories + + id = each.key + to = github_repository.this[each.key] +} + resource "github_repository" "this" { for_each = var.repositories