cryptiklemur / terraform-provider-discord

Discord Provider for Terraform
GNU General Public License v3.0
42 stars 33 forks source link

Managing discord_member_roles #14

Open Warfront1 opened 2 years ago

Warfront1 commented 2 years ago

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.

tigattack commented 2 years ago

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?

Warfront1 commented 2 years ago

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: