Skip to content

Commit

Permalink
test 1
Browse files Browse the repository at this point in the history
  • Loading branch information
neoandmatrix committed Jan 27, 2025
1 parent e5b3468 commit c90504e
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/slack-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "^1.3.7"
terraform_wrapper: false
- name: Deploy changes to Slack
run: |
cd .github/workflows/slack
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/slack/channels/channels.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
terraform {
required_providers {
slack = {
source = "pablovarela/slack"
version = "~> 1.0"
}
}
}

variable "data_sources" {
default = {
tsc_members_user_ids = []
maintainers_user_ids = []
repo_maintainers = {}
}
description = "Data sources for the slack channels from the users module"
}

locals {
channel_data = yamldecode(file("${path.module}/channels.yaml"))
channels = {
for channel in local.channel_data : channel.name => {
name = channel.name
topic = channel.topic
purpose = channel.purpose

# if permanent_members is not provided, then it wil be taken from local with the name in data sources
permanent_members = lookup(channel, "permanent_members", lookup(var.data_sources, lookup(channel, "data_source", channel.name), []))
is_private = channel.is_private
action_on_destroy = channel.action_on_destroy

# if private channel, then kick all users on update else none
action_on_update_permanent_members = channel.is_private ? "kick" : "none"
adopt_existing_channel = true
}
}
}

resource "slack_conversation" "channels" {
for_each = local.channels
name = each.value.name
topic = each.value.topic
purpose = each.value.purpose
permanent_members = each.value.permanent_members

is_private = each.value.is_private
action_on_destroy = each.value.action_on_destroy
action_on_update_permanent_members = each.value.action_on_update_permanent_members
adopt_existing_channel = each.value.adopt_existing_channel
}
28 changes: 28 additions & 0 deletions .github/workflows/slack/channels/channels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- name: channel_1
topic: both members.
purpose: test channel_1.
is_private: false
is_archived: false
action_on_destroy: archive
permanent_members:
- "U08A1GT9AP7"
- "U08A4BEKM50"

- name: channel_2
topic: single member.
purpose: test channel_2.
is_private: false
is_archived: false
action_on_destroy: archive
permanent_members:
- "U08A1GT9AP7"

- name: channel_3
topic: single member.
purpose: test channel_3.
is_private: false
is_archived: false
action_on_destroy: archive
permanent_members:
- "U08A4BEKM50"

29 changes: 29 additions & 0 deletions .github/workflows/slack/slack.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
terraform {
required_providers {
slack = {
source = "pablovarela/slack"
version = "~> 1.0"
}
}
required_version = ">= 0.13"
}

variable "slack_token" {
description = "The Slack API token with the channels:manage, channels:read, channels:write.invites, groups:read, groups:write, groups:write.invites, users:read scopes"
nullable = false
type = string
}

provider "slack" {
token = var.slack_token
}

module "users" {
source = "./users"
}

module "channels" {
source = "./channels"
depends_on = [ module.users ]
data_sources = module.users.data_sources
}
30 changes: 30 additions & 0 deletions .github/workflows/slack/users/users.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
terraform {
required_providers {
slack = {
source = "pablovarela/slack"
version = "~> 1.0"
}
}
}

locals {
maintainers_data = yamldecode(file("${path.root}/../../../MAINTAINERS.yaml"))

# maintainers with isTscMember = true are added to the tsc_members group
tsc_members_data = [for maintainer in local.maintainers_data : maintainer if lookup(maintainer, "isTscMember", false) == true]

# Make a map of repo maintainers with their slack user id with repo name as key
repos = setunion(flatten([for maintainer in local.maintainers_data : maintainer.repos]))
repo_maintainers = {
for repo in local.repos : repo =>
[for maintainer in local.maintainers_data : maintainer.slack if contains(maintainer.repos, repo)]
}
}

output "data_sources" {
value = {
maintainers_user_ids = [for maintainer in local.maintainers_data : maintainer.slack]
tsc_members_user_ids = [for tsc_member in local.tsc_members_data : tsc_member.slack]
repo_maintainers = local.repo_maintainers
}
}
19 changes: 19 additions & 0 deletions MAINTAINERS.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- name: Tushar Anand
github: neoandmatrix
linkedin: tushar-anand-neo
slack: U08A4BEKM50
availableForHire: false
isTscMember: true
repos:
- some-repo
githubID: 141230066

- name: Other member
github: no-github
linkedin: no-linkedin
slack: U08A1GT9AP7
availableForHire: false
isTscMember: true
repos:
- some-repo
githubID: 141230063

0 comments on commit c90504e

Please sign in to comment.