-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify github_team to accept slug as a valid parent_team_id #802
Conversation
Co-authored-by: Usman <akeju00+github@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks accurate, but I have concerns about how existing state would migrate to a different data type. This is potentially disruptive for existing callers of parent_team_id
as they may need to rewrite their HCL to align to this update.
Would a new string field like parent_team_slug
satisfy your use case? Or is parent_team_id
required?
thx, Sure it can be another field, as soon as we can set parent as name it will match our case. |
Ok so I did some manual tests by creating teams with parent on v4.10.1 and switches to my PR version. |
Ran into the following when validating this:
See 7672edb for a test that can be cherry-picked in. 🤔 there seems to be something up with how we set the value of
|
@usmonster @jcudit do you have a schedule to work on this? This change simplifies team creation with TF hugely. @n0rad thanks for the PR 👍 , we're currently playing around with your changes and have released it (only linux-amd64 and darwin-amd64 though) |
@n0rad I found an issue with this current slug name approach (instead of using ID's). When changing the team name of a parent (and also adjusting their parent name at the same time) and then trying to apply everything, it usually leads to a 404 error. This is due to the fact that the child team wants to update their parent team and fetches this via the slug, however if the parent name has not changed yet, it will result in a 404 not found and everything will fail. A workaround that I am currently using (and it seems to be working fine) is to loop multiple times (and also wait in between) around fetching the parent id when failed. In the meantime (during sleep and retry) the parent team name eventually gets updated. I am pretty new to golang and have created a PoC PR on the provider that we're using at flaconi. I am pretty sure that there is a better more elegant solution to it. You can find my code changes here: Flaconi#3 I would suggest to have something like this or an alternative solution also implemented into this PR to mitigate this issue (CC @jcudit @usmonster ) How to reproduce:
Root module
teams = [
# ------------------------------------------------------------
# DevOps
# ------------------------------------------------------------
{
ident = "devops"
name = "DevOps"
description = "The DevOps Team"
privacy = "closed"
parent_name = null
members = []
},
# ------------------------------------------------------------
# Engineering
# ------------------------------------------------------------
{
ident = "engineering"
name = "Engineering"
description = "The Engineering Team"
privacy = "closed"
parent_name = null
members = []
},
{
ident = "eng-sub-1"
name = "Sub-1"
description = "Team Sub-1"
privacy = "closed"
parent_name = "Engineering"
members = []
},
{
ident = "eng-sub-2"
name = "Sub-2"
description = "Team Sub-2"
privacy = "closed"
parent_name = "Engineering"
members = []
},
{
ident = "eng-sub-3"
name = "Sub-3"
description = "Team Sub-3"
privacy = "closed"
parent_name = "Engineering"
members = []
},
]
variable "token" {
description = "Github token to use when adding membership"
type = string
}
variable "owner" {
description = "Github organization name"
type = string
}
variable "teams" {
description = "GitHub teams to manage."
type = list(object({
ident = string
name = string
description = string
privacy = string
parent_name = string
members = list(string)
}))
}
locals {
teams = { for index, team in var.teams : team.ident => team }
}
module "team" {
for_each = local.teams
source = "./modules/team"
name = each.value.name
description = each.value.description
privacy = each.value.privacy
parent_name = each.value.parent_name
members = each.value.members
} team module
variable "name" {
description = "GitHub team name"
type = string
}
variable "description" {
description = "GitHub team description"
type = string
default = ""
}
variable "privacy" {
description = "GitHub team privacy (closed / secret)"
type = string
default = "closed"
}
variable "parent_name" {
description = "GitHub team parent team name"
type = string
default = null
}
variable "members" {
description = "GitHub team members"
type = list(string)
default = []
}
resource "github_team" "team" {
name = var.name
description = var.description
privacy = var.privacy
create_default_maintainer = false
parent_team_id = var.parent_name != null ? replace(lower(var.parent_name), " ", "-") : null
} |
Hi @cytopia, Thx for continuing the effort on this change. Feel free to open another PR that bring your improvement (on top of mine, or not) to propose them to the provider maintainers. |
I apologise if adding this to a PR is a spam but I haven't found an issue for this and it might help someone else - my workaround is simple and it seems to work well.
Create
Lookup ID from slug in the resource (I pull the slug from a json file which I use to create teams with
|
👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the |
Status: Pinned |
This is done by #1664 now |
Inspired by #693, This PR add support for declaring
parent_team_id
as a string ongithub_team
.This is especially useful when declaring teams in a loop and so cannot reference the other team object .