-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
129 lines (114 loc) · 3.78 KB
/
main.tf
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Configure the GitLab Provider
terraform {
required_providers {
gitlab = {
source = "gitlabhq/gitlab"
version = "3.18.0"
}
}
}
provider "gitlab" {
token = var.gitlab_token
base_url = var.gitlab_url
#insecure = true
}
# Add a group
resource "gitlab_group" "demo_group" {
name = "Demo Content"
path = "demo-content"
description = "A group for demo content"
visibility_level = "public"
}
# Add a project
resource "gitlab_project" "java_hello" {
name = "java-hello"
namespace_id = gitlab_group.demo_group.id
description = "Java Hello World App"
visibility_level = "public"
default_branch = "main"
initialize_with_readme = false
container_registry_enabled = true
issues_enabled = true
merge_requests_enabled = true
packages_enabled = true
pipelines_enabled = true
wiki_enabled = true
wiki_access_level = "enabled"
}
# Add branch protection to the project
resource "gitlab_branch_protection" "java_hello_branch_protection" {
project = gitlab_project.java_hello.id
branch = "main"
push_access_level = "maintainer"
merge_access_level = "maintainer"
unprotect_access_level = "maintainer"
}
# Add a milestone to the project
resource "gitlab_project_milestone" "java_hello_mvp_milestone" {
project = gitlab_project.java_hello.id
title = "Java Hello World MVP milestone"
description = "This is a milestone for MVP of Java Hello World App"
}
# Add a few issues to the project
resource "gitlab_project_issue" "java_hello_design_issue" {
project = gitlab_project.java_hello.id
title = "Hello World Design"
description = "Write the design details for a super amazing hello world app"
milestone_id = gitlab_project_milestone.java_hello_mvp_milestone.milestone_id
state = "closed"
}
resource "gitlab_project_issue" "java_hello_mvp_issue" {
depends_on = [
gitlab_project_issue.java_hello_design_issue
]
project = gitlab_project.java_hello.id
title = "Hello World MVP"
description = "Build a Java Hello World App"
milestone_id = gitlab_project_milestone.java_hello_mvp_milestone.milestone_id
state = "opened"
}
# Add a branch
resource "gitlab_branch" "java_hello_branch" {
project = gitlab_project.java_hello.id
name = "java-hello-mvp"
ref = "main"
}
## Add repository files in for_each loop
#resource "gitlab_repository_file" "java_hello_files" {
# for_each = fileset(path.module, "files/**")
#
# project = gitlab_project.java_hello.id
# branch = gitlab_branch.java_hello_branch.name
# file_path = trimprefix(each.key, "files/")
# content = each.value ## This is wrong
#
# author_email = "[email protected]"
# author_name = "Gitlab"
# commit_message = "feature: java hello world mvp"
#}
# Add a project
resource "gitlab_project" "python_hello" {
name = "python-hello"
namespace_id = gitlab_group.demo_group.id
description = "Python Hello World App"
visibility_level = "public"
default_branch = "main"
container_registry_enabled = true
issues_enabled = true
merge_requests_enabled = true
packages_enabled = true
pipelines_enabled = true
wiki_enabled = true
wiki_access_level = "enabled"
}
resource "null_resource" "populate_repo" {
depends_on = [
gitlab_project.java_hello,
gitlab_branch.java_hello_branch
]
provisioner "local-exec" {
command = "export GITLAB_TOKEN=\"${var.gitlab_token}\" && bash ${path.module}/scripts/java_hello_automation.sh"
interpreter = ["/bin/bash", "-c"]
working_dir = path.module
}
}