Comments (5)
You can solve this by running terraform apply -target github_team.all
first as per the documentation
from learn-terraform-github-user-teams.
I am also facing the same issue and terraform apply -target is definitely not a recommended way. Is there any other way to achieve this as it needs to be run through pipelines.
from learn-terraform-github-user-teams.
Use count instead for_each working.
from learn-terraform-github-user-teams.
@PrinceAgrawal89 @grantbevis I solved this, by creating a module, that creates the team and adds the members. This way it's easier to access the team ids.
A quick and dirty example :
# modules/team/main.tf
terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 5.0"
}
}
}
variable "name" {}
variable "description" {}
variable "privacy" {}
variable "create_default_maintainer" {
type = bool
}
variable "members" {
type = list(object({
username = string
role = string
}))
}
resource "github_team" "team" {
name = var.name
description = var.description
privacy = var.privacy
create_default_maintainer = var.create_default_maintainer
}
resource "github_team_membership" "members" {
count = length(var.members)
team_id = github_team.team.id
username = element(var.members.*.username, count.index )
role = element(var.members.*.role, count.index )
}
And the main script:
# main file
module "dev_team" {
source = "./modules/team"
create_default_maintainer = false
description = "Developers"
name = "devs"
privacy = "closed"
members = [
{
username = "user_a",
role = "maintainer"
},
{
username = "user_b",
role = "member"
}
]
}
all you have to do, is to change the locals so they're not using resources directly and then use them instead of the hardcoded values
from learn-terraform-github-user-teams.
Use count instead for_each working.
@devfalcon3 I tried with following code which didnt help and I got the same error message as before.
# teams.tf
...
resource "github_team_membership" "members" {
count = { for tm in local.team_members : tm.name => tm }
team_id = local.team_members.team_id[count.index]
username = local.team_members.username[count.index]
role = local.team_members.role[count.index]
}
from learn-terraform-github-user-teams.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learn-terraform-github-user-teams.