You've already forked devops-exercises
Update
This commit is contained in:
13
topics/gcp/exercises/assign_roles/exercise.md
Normal file
13
topics/gcp/exercises/assign_roles/exercise.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Assign Roles
|
||||
|
||||
## Objectives
|
||||
|
||||
1. Assign the following roles to a member in your organization
|
||||
1. Compute Storage Admin
|
||||
2. Compute Network Admin
|
||||
3. Compute Security Admin
|
||||
2. Verify roles were assigned
|
||||
|
||||
## Solution
|
||||
|
||||
Click [here](solution.md) to view the solution
|
||||
19
topics/gcp/exercises/assign_roles/main.tf
Normal file
19
topics/gcp/exercises/assign_roles/main.tf
Normal file
@@ -0,0 +1,19 @@
|
||||
locals {
|
||||
roles = [
|
||||
"roles/compute.storageAdmin",
|
||||
"roles/compute.networkAdmin",
|
||||
"roles/compute.securityAdmin"
|
||||
]
|
||||
}
|
||||
|
||||
resource "google_service_account" "some_member" {
|
||||
account_id = "${substr(var.env_id, 0, min(length(var.env_id), 10))}-some-member"
|
||||
display_name = "${var.env_id} some-member"
|
||||
}
|
||||
|
||||
resource "google_project_iam_member" "storageAdminMaster" {
|
||||
for_each = toset(concat(local.roles))
|
||||
project = "${var.project_id}"
|
||||
role = each.key
|
||||
member = "serviceAccount:${google_service_account.some_member.email}"
|
||||
}
|
||||
23
topics/gcp/exercises/assign_roles/solution.md
Normal file
23
topics/gcp/exercises/assign_roles/solution.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Assign Roles
|
||||
|
||||
## Objectives
|
||||
|
||||
1. Assign the following roles to a member in your organization
|
||||
1. Compute Storage Admin
|
||||
2. Compute Network Admin
|
||||
3. Compute Security Admin
|
||||
2. Verify roles were assigned
|
||||
|
||||
## Solution
|
||||
|
||||
### Console
|
||||
|
||||
1. Go to IAM & Admin
|
||||
2. Click on IAM and then on the "Add" button
|
||||
1. Choose the member account to whom the roles will be added
|
||||
2. Under select role, search for the specified roles under "Objectives" and click on "Save"
|
||||
2. The member should now be able to go to the compute engine API and see the resources there.
|
||||
|
||||
### Terraform
|
||||
|
||||
Click [here](main.tf) to view the Terraform main.tf file
|
||||
7
topics/gcp/exercises/assign_roles/vars.tf
Normal file
7
topics/gcp/exercises/assign_roles/vars.tf
Normal file
@@ -0,0 +1,7 @@
|
||||
variable "project_id" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "env_id" {
|
||||
type = string
|
||||
}
|
||||
10
topics/gcp/exercises/assign_roles/versions.tf
Normal file
10
topics/gcp/exercises/assign_roles/versions.tf
Normal file
@@ -0,0 +1,10 @@
|
||||
terraform {
|
||||
required_version = ">=1.3.0"
|
||||
|
||||
required_providers {
|
||||
google = {
|
||||
source = "hashicorp/google"
|
||||
version = ">= 4.10.0, < 5.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
topics/gcp/exercises/create_project/exercise.md
Normal file
9
topics/gcp/exercises/create_project/exercise.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Create a Project
|
||||
|
||||
## Objectives
|
||||
|
||||
1. Create a project with a unique name
|
||||
|
||||
## Solution
|
||||
|
||||
Click [here](solution.md) to view the solution
|
||||
10
topics/gcp/exercises/create_project/main.tf
Normal file
10
topics/gcp/exercises/create_project/main.tf
Normal file
@@ -0,0 +1,10 @@
|
||||
resource "google_project" "gcp_project" {
|
||||
name = "Some Project"
|
||||
project_id = "some-unique-project-id"
|
||||
folder_id = google_folder.some_folder.name
|
||||
}
|
||||
|
||||
resource "google_folder" "some_folder" {
|
||||
display_name = "Department 1"
|
||||
parent = "organizations/some-organization"
|
||||
}
|
||||
19
topics/gcp/exercises/create_project/solution.md
Normal file
19
topics/gcp/exercises/create_project/solution.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Create a Project
|
||||
|
||||
## Objectives
|
||||
|
||||
1. Create a project with a unique name
|
||||
|
||||
## Solution
|
||||
|
||||
### Console
|
||||
|
||||
1. Click in the top bar on "New Project" (if you already have a project then, click on the project name and then "New Project") or in the search bar insert "Create Project".
|
||||
2. Insert a globally unique project name
|
||||
3. Optionally choose an organization
|
||||
4. Optionally put it under a specific folder
|
||||
5. Click on "Create" :)
|
||||
|
||||
### Terraform
|
||||
|
||||
Click [here](main.tf) to view the solution
|
||||
10
topics/gcp/exercises/create_project/versions.tf
Normal file
10
topics/gcp/exercises/create_project/versions.tf
Normal file
@@ -0,0 +1,10 @@
|
||||
terraform {
|
||||
required_version = ">=1.3.0"
|
||||
|
||||
required_providers {
|
||||
google = {
|
||||
source = "hashicorp/google"
|
||||
version = ">= 4.10.0, < 5.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
17
topics/gcp/exercises/instance_101/exercise.md
Normal file
17
topics/gcp/exercises/instance_101/exercise.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Create an Instance
|
||||
|
||||
## Objectives
|
||||
|
||||
1. Create a VM instance with the following properties
|
||||
1. name: instance-1
|
||||
2. type: e2-micro
|
||||
3. labels:
|
||||
1. app: web
|
||||
2. env: dev
|
||||
2. Using the CLI (gcloud) perform the following operations:
|
||||
1. Update "app" label to "db"
|
||||
2. Remove "env" label
|
||||
|
||||
## Solution
|
||||
|
||||
Click [here](solution.md) to view the solution
|
||||
21
topics/gcp/exercises/instance_101/main.tf
Normal file
21
topics/gcp/exercises/instance_101/main.tf
Normal file
@@ -0,0 +1,21 @@
|
||||
resource "google_compute_network" "vpc_network" {
|
||||
name = "my-custom-mode-network"
|
||||
auto_create_subnetworks = false
|
||||
mtu = 1460
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "default" {
|
||||
name = "my-custom-subnet"
|
||||
ip_cidr_range = "10.0.1.0/24"
|
||||
region = "us-west1"
|
||||
network = google_compute_network.vpc_network.id
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "default" {
|
||||
name = "instance-1"
|
||||
machine_type = "e2-micro"
|
||||
zone = "us-west1-a"
|
||||
labels = {
|
||||
app = "db"
|
||||
}
|
||||
}
|
||||
45
topics/gcp/exercises/instance_101/solution.md
Normal file
45
topics/gcp/exercises/instance_101/solution.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# Create an Instance
|
||||
|
||||
## Objectives
|
||||
|
||||
1. Create a VM instance with the following properties
|
||||
1. name: instance-1
|
||||
2. type: e2-micro
|
||||
3. labels:
|
||||
1. app: web
|
||||
2. env: dev
|
||||
2. Using the CLI (gcloud) perform the following operations:
|
||||
1. Update "app" label to "db"
|
||||
2. Remove "env" label
|
||||
|
||||
## Solution
|
||||
|
||||
### Console
|
||||
|
||||
1. Go to Compute Engine -> VM instances
|
||||
2. Click on "Create Instance"
|
||||
1. Insert the name "instance-1"
|
||||
2. Click on "Add label" and add the following labels:
|
||||
1. app: web
|
||||
2. env: dev
|
||||
3. Choose machine type: e2-micro
|
||||
3. Click on "Create"
|
||||
4. Selected the created instance and click on "show info panel"
|
||||
1. Click on "labels" tab and change the value of "app" label to "db"
|
||||
2. Remove the "env" label
|
||||
|
||||
### Shell
|
||||
|
||||
```
|
||||
gcloud config set project <PROJECT_ID>
|
||||
gcloud config set compute/region <REGION NAME>
|
||||
gcloud config set compute/zone <ZONE NAME>
|
||||
|
||||
gcloud compute instances create instance-1 --labels app=web,env=dev --machine-type=e2-micro
|
||||
gcloud compute instances update instance-1 --update-labels app=db
|
||||
gcloud compute instances update instance-1 --remove-labels env
|
||||
```
|
||||
|
||||
### Terraform
|
||||
|
||||
Click [here](main.tf) to view the main.tf file
|
||||
10
topics/gcp/exercises/instance_101/versions.tf
Normal file
10
topics/gcp/exercises/instance_101/versions.tf
Normal file
@@ -0,0 +1,10 @@
|
||||
terraform {
|
||||
required_version = ">=1.3.0"
|
||||
|
||||
required_providers {
|
||||
google = {
|
||||
source = "hashicorp/google"
|
||||
version = ">= 4.10.0, < 5.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user