Skip to content

Commit 1f08219

Browse files
committed
Add files related to argocd project session
1 parent a06e285 commit 1f08219

10 files changed

+283
-6
lines changed

.gitignore

-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
crash.log
1010
crash.*.log
1111

12-
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
13-
# password, private keys, and other secrets. These should not be part of version
14-
# control as they are data points which are potentially sensitive and subject
15-
# to change depending on the environment.
16-
*.tfvars
17-
*.tfvars.json
1812

1913
# Ignore override files as they are usually used to override resources locally and so
2014
# are not checked in
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: AppProject
3+
metadata:
4+
name: project-destination-restriction
5+
namespace: argocd
6+
spec:
7+
clusterResourceWhitelist:
8+
- group: '*'
9+
kind: '*'
10+
destinations:
11+
- namespace: '!dev' ## Use '!' to place namespace in BlackList, if we remove '!' the namespace will be placed in WhiteList
12+
server: '*' ## '*' means we are allowed to use any servers
13+
sourceRepos:
14+
- '*'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: AppProject
3+
metadata:
4+
name: project-resource-blacklist
5+
namespace: argocd
6+
spec:
7+
clusterResourceWhitelist:
8+
- group: '*' ## it means we are allowed to use any kinds of clusterscoped resources
9+
kind: '*'
10+
namespaceResourceBlacklist:
11+
- group: ''
12+
kind: 'ServiceAccount' ## it means we are NOT allowd to use 'serviceaccount' namespacescoped resource
13+
destinations:
14+
- namespace: '*'
15+
server: '*'
16+
sourceRepos:
17+
- '*'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: AppProject
3+
metadata:
4+
name: project-resource-whitelist
5+
namespace: argocd
6+
spec:
7+
clusterResourceWhitelist:
8+
- group: '*' ## it means we are allowed to use any kinds of clusterscoped resources
9+
kind: '*'
10+
namespaceResourceWhitelist:
11+
- group: ''
12+
kind: 'ServiceAccount' ## it means we are allowd to use 'serviceaccount' namespacescoped resource Only
13+
destinations:
14+
- namespace: '*'
15+
server: '*'
16+
sourceRepos:
17+
- '*'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: AppProject
3+
metadata:
4+
name: project-role
5+
namespace: argocd
6+
spec:
7+
clusterResourceWhitelist:
8+
- group: '*'
9+
kind: '*'
10+
namespaceResourceWhitelist:
11+
- group: '*'
12+
kind: '*'
13+
destinations:
14+
- namespace: '*'
15+
server: '*'
16+
sourceRepos:
17+
- '*'
18+
roles:
19+
- name: read-sync
20+
description: "this role can be used for reading applications"
21+
policies:
22+
- p, proj:project-role:read-sync, applications, get, project-role/*, allow
23+
- p, proj:project-role:read-sync, applications, sync, project-role/*, allow
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: AppProject
3+
metadata:
4+
name: project-source-restriction
5+
namespace: argocd
6+
spec:
7+
clusterResourceWhitelist:
8+
- group: '*'
9+
kind: '*'
10+
destinations:
11+
- namespace: '*'
12+
server: '*'
13+
sourceRepos:
14+
- '!https://github.com/devopshobbies/argocd-tutorial.git' ## Use '!' to place repo in BlackList, if we remove '!' the repo will be placed in WhiteList
15+
- '*' ## '*' means we are allowed to use any repos
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
locals {
2+
roles_count = length(var.roles)
3+
}
4+
5+
resource "argocd_project" "terraform-project" {
6+
metadata {
7+
name = var.project_name
8+
namespace = var.project_namespace
9+
labels = var.project_labels
10+
}
11+
12+
spec {
13+
description = var.project_description
14+
15+
source_namespaces = var.source_namespaces
16+
source_repos = var.source_repos
17+
18+
dynamic "destination" {
19+
for_each = var.destinations
20+
content {
21+
server = destination.value.server
22+
namespace = destination.value.namespace
23+
}
24+
}
25+
26+
dynamic "cluster_resource_whitelist" {
27+
for_each = var.cluster_resources_whitelist
28+
content {
29+
group = cluster_resource_whitelist.value.group
30+
kind = cluster_resource_whitelist.value.kind
31+
}
32+
}
33+
34+
dynamic "namespace_resource_whitelist" {
35+
for_each = var.namespace_resources_whitelist
36+
content {
37+
group = namespace_resource_whitelist.value.group
38+
kind = namespace_resource_whitelist.value.kind
39+
}
40+
}
41+
42+
dynamic "role" {
43+
for_each = var.roles
44+
content {
45+
name = role.value.name
46+
policies = role.value.policies
47+
}
48+
}
49+
}
50+
}
51+
52+
resource "argocd_project_token" "secret" {
53+
count = local.roles_count
54+
project = var.project_name
55+
role = var.roles[count.index]["name"]
56+
depends_on = [
57+
argocd_project.terraform-project
58+
]
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
terraform {
2+
required_providers {
3+
argocd = {
4+
source = "oboukili/argocd"
5+
version = "6.0.2"
6+
}
7+
}
8+
}
9+
10+
provider "argocd" {
11+
server_addr = var.server_addr
12+
username = var.username
13+
password = var.password
14+
insecure = var.insecure
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
server_addr = "localhost:32073"
2+
username = "admin"
3+
password = "O0Nk42qUhEOMK4q8"
4+
insecure = true
5+
project_name = "terraform-project"
6+
project_namespace = "argocd"
7+
project_labels = {
8+
acceptance = "true"
9+
}
10+
project_description = "this project has been created using terraform"
11+
source_namespaces = ["argocd"]
12+
source_repos = ["*"]
13+
destinations = {
14+
destination_one = {
15+
server = "*",
16+
namespace = "dev"
17+
},
18+
destination_two = {
19+
server = "*",
20+
namespace = "prod"
21+
}
22+
}
23+
cluster_resources_whitelist = {
24+
resource_one = {
25+
group = "*"
26+
kind = "*"
27+
}
28+
}
29+
namespace_resources_whitelist = {
30+
resource_one = {
31+
group = "apps"
32+
kind = "Deployment"
33+
},
34+
resource_two = {
35+
group = ""
36+
kind = "Service"
37+
}
38+
}
39+
roles = [
40+
{
41+
name = "read-only"
42+
policies = [
43+
"p, proj:terraform-project:read-only, applications, get, terraform-project/*, allow",
44+
]
45+
}
46+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
variable "server_addr" {
2+
type = string
3+
description = "The server address"
4+
}
5+
6+
variable "username" {
7+
type = string
8+
description = "The Username"
9+
}
10+
11+
variable "password" {
12+
type = string
13+
description = "The Password"
14+
}
15+
16+
variable "insecure" {
17+
type = bool
18+
description = "The Connection Insecure flag"
19+
}
20+
21+
variable "project_name" {
22+
type = string
23+
description = "The Name of the Project"
24+
}
25+
26+
variable "project_namespace" {
27+
type = string
28+
description = "The Namespace of the Project"
29+
}
30+
31+
variable "project_labels" {
32+
type = map(string)
33+
description = "The Labels of the Project"
34+
}
35+
36+
variable "project_description" {
37+
type = string
38+
description = "The Description of the Project"
39+
}
40+
41+
variable "source_namespaces" {
42+
type = list(string)
43+
description = "The Source Namespaces of the Project"
44+
}
45+
46+
variable "source_repos" {
47+
type = list(string)
48+
description = "The Source Repos of the Project"
49+
}
50+
51+
variable "destinations" {
52+
type = map(object({
53+
server = string,
54+
namespace = string
55+
}))
56+
}
57+
58+
variable "cluster_resources_whitelist" {
59+
type = map(object({
60+
group = string,
61+
kind = string
62+
}))
63+
}
64+
65+
variable "namespace_resources_whitelist" {
66+
type = map(object({
67+
group = string,
68+
kind = string
69+
}))
70+
}
71+
72+
variable "roles" {
73+
type = list(object({
74+
name = string,
75+
policies = list(string)
76+
}))
77+
}

0 commit comments

Comments
 (0)