-
Notifications
You must be signed in to change notification settings - Fork 746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] Manage Organization IP Allow Lists #1067
Comments
Sid Palas suggested a workaround by using the sullivtr/graphql provider, which worked for me. For anyone else wanting to do this, here's the setup I used: terraform {
required_version = "1.1.5"
required_providers {
github = {
source = "integrations/github"
version = "4.20.0"
}
graphql = {
source = "sullivtr/graphql"
version = "2.5.0"
}
}
backend "pg" {
}
}
variable "GITHUB_TOKEN" {
description = "Your personal access token. Needs scopes: repo, admin:org, delete_repo"
type = string
sensitive = true
}
variable "GITHUB_OWNER" {
description = "The target GitHub organization or individual user account to manage"
type = string
}
provider "github" {
token = var.GITHUB_TOKEN
owner = var.GITHUB_OWNER
}
provider "graphql" {
url = "https://api.github.com/graphql"
headers = {
"Authorization" : "token ${var.GITHUB_TOKEN}"
}
}
data "graphql_query" "organization" {
query_variables = {
login : var.GITHUB_OWNER
}
query = file("./graphql/organization_read.gql")
}
locals {
# Map of CIDR IP range to graphql properties of the IpAllowListEntry
cidr_allow_list = {
"127.0.0.1/8": {
name = "Description shown at https://github.com/organizations/{org}/settings/security"
# you could also set isActive or ownerId
}
}
}
resource "graphql_mutation" "ip_allow_list" {
for_each = local.cidr_allow_list
mutation_variables = {
name = each.value.name
allowListValue = each.key
isActive = true
ownerId = jsondecode(data.graphql_query.organization.query_response).data.organization.id
}
compute_from_create = true
compute_mutation_keys = {
ipAllowListEntryId = "data.createIpAllowListEntry.ipAllowListEntry.id"
}
create_mutation = file("./graphql/ip_allow_list_create.gql")
update_mutation = file("./graphql/ip_allow_list_update.gql")
delete_mutation = file("./graphql/ip_allow_list_delete.gql")
read_query = file("./graphql/ip_allow_list_read.gql")
} And the files referenced above./graphql/organization_read.gql query Organization($login: String!) {
organization(login: $login) {
id
name
url
}
} ./graphql/ip_allow_list_read.gql query IpAllowListEntry($ipAllowListEntryId: ID!) {
node(id: $ipAllowListEntryId) {
... on IpAllowListEntry {
id
name
isActive
allowListValue
owner {
... on Organization {
id
}
}
}
}
} ./graphql/ip_allow_list_create.gql mutation CreateIpAllowListEntry(
$name: String!,
$isActive: Boolean!,
$allowListValue: String!,
$ownerId: ID!
) {
createIpAllowListEntry(input: {
name: $name,
isActive: $isActive,
allowListValue: $allowListValue,
ownerId: $ownerId
}) {
ipAllowListEntry {
id
name
isActive
allowListValue
owner {
... on Organization {
id
}
}
}
}
} ./graphql/ip_allow_list_update.gql mutation UpdateIpAllowListEntry(
$ipAllowListEntryId: ID!,
$name: String!,
$isActive: Boolean!,
$allowListValue: String!
) {
updateIpAllowListEntry(input: {
ipAllowListEntryId: $ipAllowListEntryId,
name: $name,
isActive: $isActive,
allowListValue: $allowListValue,
}) {
ipAllowListEntry {
id
name
isActive
allowListValue
owner {
... on Organization {
id
}
}
}
}
} ./graphql/ip_allow_list_delete.gql mutation DeleteIpAllowListEntry($ipAllowListEntryId: ID!) {
deleteIpAllowListEntry(input: {
ipAllowListEntryId: $ipAllowListEntryId
}) {
ipAllowListEntry {
id
}
}
} |
Thanks for sharing this code snippet! |
👋 Hey Friends, this issue has been automatically marked as |
Can we reopen this issue ? |
Request
Hello, I would like to manage the IP allow list for my GitHub organizations via Terraform. On the web I can do this at
https://github.com/organizations/<organization>/settings/security
.What I've checked so far
Desired Configuration
As an example, it would be nice to manage the IP allow lists for an organization something like the following.
Thank you!
The text was updated successfully, but these errors were encountered: