Skip to content
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

Adding users and group bulk creation files #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kubernetes-ressources/terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.terraform
terraform.tfstate
terraform.tfstate.backup
ips
config/*
11 changes: 9 additions & 2 deletions kubernetes-ressources/terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ To achieve this, we create a terraform workspace per element.

## Pre-requisites

1. Create the GSuite users on **training.wecontrol.cloud** domain and place them in *k8s-training-niv-1* group and *kube-niv-1* OU. For that, ask an admin on the suite Domain.
2. Create the target GCP projects. For this, see https://gitlab.com/wescalefr/bootstrap-gcp-kube-training.
1. Create the target GCP projects. For this, see https://gitlab.com/wescalefr/bootstrap-gcp-kube-training.

## Get Terraform

Expand All @@ -40,6 +39,14 @@ Then:
bash tf-runner.sh provision
```

## (Optional) Create users to allow Web SSH Console

Create the GSuite users on **training.wecontrol.cloud** domain and place them in *k8s-training-niv-1* group and *kube-niv-1* OU. For that, ask an admin on the suite Domain.

Two files are generated by Terraform to allow bulk creation of users and group association:
- Upload config/users.csv on (User management)[https://admin.google.com/ac/users] of wecontrol.cloud management console.
- Upload conf/users_group.csv on (k8s-training-niv-1 group)[https://admin.google.com/ac/groups/01rvwp1q0sa51v1/members?hl=fr] management page.

## At the end of training, clean the GKE clusters


Expand Down
10 changes: 8 additions & 2 deletions kubernetes-ressources/terraform/tf-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

NB_PROJECTS=11 # can go to the value defined in https://gitlab.com/wescalefr/bootstrap-gcp-kube-training
NB_PROJECTS=12 # can go to the value defined in https://gitlab.com/wescalefr/bootstrap-gcp-kube-training

OPT=$1 # option

Expand All @@ -11,6 +11,9 @@ ROOT_DIR=$(pwd)
function provision(){
local project_id=0
rm -rf "${ROOT_DIR}/config/ips"
echo "First Name [Required],Last Name [Required],Email Address [Required],Password [Required],Password Hash Function [UPLOAD ONLY],Org Unit Path [Required]" > "${ROOT_DIR}/config/users.csv"
echo "Group Email [Required],Member Email,Member Type,Member Role" > "${ROOT_DIR}/config/users_group.csv"

while [ $project_id -lt $NB_PROJECTS ];do
echo "Create content for project ${project_id}"
set +e
Expand All @@ -19,8 +22,11 @@ function provision(){
terraform workspace select "wsc-kubernetes-training-${project_id}"
terraform apply -auto-approve

mkdir -p "${ROOT_DIR}/config/${w}"
terraform output -json bastion_ip |jq -r . >> "${ROOT_DIR}/config/ips"
userid=$(printf "%02d" "$project_id") # 2 digits, e.g. 01 for project 1
passwd=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 20) # 20 alpha-numeric chars
echo "trainee${userid},trainee${userid},trainee${userid}@training.wecontrol.cloud,${passwd},,/kube-niv1-trainee" >> "${ROOT_DIR}/config/users.csv"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mathieulaude : mettre les usersID et passwords en resources puis outputs terraform permettrait de les retrouver dans les TF statefile.

echo "[email protected],trainee${userid}@training.wecontrol.cloud,USER,MEMBER" >> "${ROOT_DIR}/config/users_group.csv"
project_id=$[$project_id+1]
done
}
Expand Down