GithubHelp home page GithubHelp logo

Comments (5)

grantbevis avatar grantbevis commented on June 16, 2024 3

You can solve this by running terraform apply -target github_team.all first as per the documentation

https://learn.hashicorp.com/tutorials/terraform/github-user-teams?in=terraform/it-saas#apply-configuration

from learn-terraform-github-user-teams.

PrinceAgrawal89 avatar PrinceAgrawal89 commented on June 16, 2024

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.

devfalcon3 avatar devfalcon3 commented on June 16, 2024

Use count instead for_each working.

from learn-terraform-github-user-teams.

bctosc avatar bctosc commented on June 16, 2024

@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.

pmcpg avatar pmcpg commented on June 16, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.