This repository was archived by the owner on Apr 15, 2026. It is now read-only.
forked from integrations/terraform-provider-github
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.tf
More file actions
115 lines (95 loc) · 3.36 KB
/
main.tf
File metadata and controls
115 lines (95 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 6.11"
}
}
}
provider "github" {
token = var.github_token
owner = var.enterprise_slug
}
variable "github_token" {
description = "GitHub classic personal access token (PAT) for an enterprise admin"
type = string
sensitive = true
}
variable "enterprise_slug" {
description = "The GitHub Enterprise slug"
type = string
}
variable "cost_center_name" {
description = "Name for the cost center"
type = string
}
variable "users" {
description = "Usernames to assign to the cost center"
type = list(string)
default = []
}
variable "organizations" {
description = "Organization logins to assign to the cost center"
type = list(string)
default = []
}
variable "repositories" {
description = "Repositories (full name, e.g. org/repo) to assign to the cost center"
type = list(string)
default = []
}
# The cost center resource manages only the cost center entity itself.
resource "github_enterprise_cost_center" "example" {
enterprise_slug = var.enterprise_slug
name = var.cost_center_name
}
# Use separate authoritative resources for assignments.
# These are optional - only create them if you have items to assign.
resource "github_enterprise_cost_center_users" "example" {
count = length(var.users) > 0 ? 1 : 0
enterprise_slug = var.enterprise_slug
cost_center_id = github_enterprise_cost_center.example.id
usernames = var.users
}
resource "github_enterprise_cost_center_organizations" "example" {
count = length(var.organizations) > 0 ? 1 : 0
enterprise_slug = var.enterprise_slug
cost_center_id = github_enterprise_cost_center.example.id
organization_logins = var.organizations
}
resource "github_enterprise_cost_center_repositories" "example" {
count = length(var.repositories) > 0 ? 1 : 0
enterprise_slug = var.enterprise_slug
cost_center_id = github_enterprise_cost_center.example.id
repository_names = var.repositories
}
# Data sources for reading cost center information
data "github_enterprise_cost_center" "by_id" {
enterprise_slug = var.enterprise_slug
cost_center_id = github_enterprise_cost_center.example.id
}
data "github_enterprise_cost_centers" "active" {
enterprise_slug = var.enterprise_slug
state = "active"
depends_on = [github_enterprise_cost_center.example]
}
output "cost_center" {
description = "Created cost center"
value = {
id = github_enterprise_cost_center.example.id
name = github_enterprise_cost_center.example.name
state = github_enterprise_cost_center.example.state
azure_subscription = github_enterprise_cost_center.example.azure_subscription
}
}
output "cost_center_from_data_source" {
description = "Cost center fetched by data source (includes all assignments)"
value = {
id = data.github_enterprise_cost_center.by_id.cost_center_id
name = data.github_enterprise_cost_center.by_id.name
state = data.github_enterprise_cost_center.by_id.state
users = sort(tolist(data.github_enterprise_cost_center.by_id.users))
organizations = sort(tolist(data.github_enterprise_cost_center.by_id.organizations))
repositories = sort(tolist(data.github_enterprise_cost_center.by_id.repositories))
}
}