cryptiklemur/terraform-provider-discord

Managing discord_member_roles

Opened this issue · 2 comments

When trying to reference a user_id in a discord_member_roles, there seems to be no handling for discord_members that are not part of the discord server?

Sample terraform:

variable "discord_token" {
  description = "Discord token"
  type        = string
  default     = "<SECRET TOKEN GOES HERE>"
}

terraform {
  required_version = ">= 0.13"
}

terraform {
  required_providers {
    discord = {
      source = "aequasi/discord"
      version = "0.0.4"
    }
  }
}

provider discord {
  token = var.discord_token
}

resource discord_server my_server {
  name = "test"
  default_message_notifications = 0
}

data discord_permission serveradmin {
  administrator = "allow"
}

resource discord_role serveradmin {
  server_id = discord_server.my_server.id
  name = "Server Admin"
  permissions = data.discord_permission.serveradmin.allow_bits
  position = 0
}

resource discord_member_roles warfront1 {
  user_id = "1234"
  server_id = discord_server.my_server.id
  role {
    role_id = discord_role.serveradmin.id
  }
}

Ouput:

Error: Could not get member 1234 in 123456: Unknown Member
{"message": "Unknown Member", "code": 10007}
GET:/guilds/123456/members/{id} => []

This becomes problematic especially when first creating your discord server, as you can't assign roles prior to having a member join the newly created server.
In addition, your apply could easily break if the user you are attempting to modify a role for leaves the server themselves.

You can't add members to a role when they aren't in the server.

Imagine you're setting file permissions, what do you think would happen if you tried to set the owner of a file to a user that doesn't exist?

You can't add members to a role when they aren't in the server.

Imagine you're setting file permissions, what do you think would happen if you tried to set the owner of a file to a user that doesn't exist?

To answer your question, the user creation would scripted out, and set as a dependency of the file permission.

The use case I provided is very common, and causes for a very broken terraform automation process.
At the very least, I am looking for the intended guidance on what to do in such a situation.

For example, is the recommendation that you:

  • Run your terraform once to create the server, creating the core server component, but bombing/failing all user specific configurations
    • This would even be relevant for yourself specifically, as you have not joined the server yet.
  • Then have each of the users that need configuration join (manually invite, ask to them join; could take days)
  • Make sure everyone is accounted for (manually take account)
  • Re-run the terraform hoping all was accounted for