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

New example for a data playground Terraform setup #655

Merged
merged 21 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9300f32
Initial commit for adding a sample data playground
aymanfarhat May 19, 2022
b1693ac
Update README
aymanfarhat May 19, 2022
2ed1111
Add license boilerplate to variables.tf
aymanfarhat May 19, 2022
92d6cac
Apply linting rules
aymanfarhat May 19, 2022
0830855
rename var to ptoject_id, create prefix var, remove extra zone var
aymanfarhat Jun 18, 2022
bb9b82d
Merge branch 'master' into example/data-playground
aymanfarhat Jun 18, 2022
85f47d0
Adds the option for using an existing project by default
aymanfarhat Jun 18, 2022
f74eabb
Bundles all VPC related variables in a single vpc_config variable of …
aymanfarhat Jun 18, 2022
9b13abb
Merge branch 'master' into example/data-playground
ludoo Jun 18, 2022
184fef2
Merge branch 'master' into example/data-playground
aymanfarhat Jun 24, 2022
44757d3
Add encryption_key usage example + policy_boolean
aymanfarhat Jun 24, 2022
ce447cb
Add tests, apply linting and todos for upcoming PRs
aymanfarhat Jun 24, 2022
1e14c5c
Update variables in readme
aymanfarhat Jun 24, 2022
ebd6e51
Fix formatting via fmt
aymanfarhat Jun 24, 2022
986dd71
Rename test dir to fix module conflict issue
aymanfarhat Jun 24, 2022
91f3abd
Add high level diagram and sort vars/outputs by alphabetical
aymanfarhat Jun 25, 2022
9fe867d
Modify diagram and update main README under data examples with link /…
aymanfarhat Jun 25, 2022
66c07af
Line break
aymanfarhat Jun 25, 2022
1e1e677
Use png in diagram
aymanfarhat Jun 25, 2022
392d2d0
Merge branch 'master' into example/data-playground
ludoo Jul 10, 2022
6d6e1cd
Merge branch 'master' into example/data-playground
ludoo Jul 10, 2022
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
42 changes: 42 additions & 0 deletions examples/data-solutions/data-playground/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Data Playground

This example creates a minimum viable template for a data experimentation project with the needed APIs enabled, basic VPC and Firewall set in place, GCS bucket and an AI notebook to get started.

## Managed resources and services

This sample creates several distinct groups of resources:

- projects
- Service Project configured for GCE instances and GCS buckets
- networking
- VPC network
- One default subnet
- Firewall rules for [SSH access via IAP](https://cloud.google.com/iap/docs/using-tcp-forwarding) and open communication within the VPC
- Vertex AI notebook
- One Jupyter lab notebook instance with public access
- GCS
- One bucket initial bucket



## Variables
| name | description | type | required | default |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------ | ------ | -------- | ------------------- |
| billing\_account | Billing account id used as default for new projects. | string | ✓ | |
| project\_service\_name | Name for the project. | string | ✓ | |
| root\_node | The resource name of the parent Folder or Organization. Must be of the form folders/folder\_id or organizations/org\_id. | string | ✓ | |
| location | The location where resources will be deployed | string | | europe |
| region | The region where resources will be deployed. | string | | europe-west1 |
| zone | The zone where resources will be deployed. | string | | b |
| vpc\_ip\_cidr\_range | Ip range used in the subnet deployed in the project | string | | 10.0.0.0/20 |
| vpc\_name | Name of the VPC created in the project. | string | | data-playground-vpc |
| vpc\_subnet\_name | Name of the subnet created in the project | string | | default-subnet |


## Outputs
| Name | Description |
| ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
| bucket | GCS Bucket URL. |
| project | Project id |
| vpc | VPC Network name |
| notebook | Vertex AI notebook name |
101 changes: 101 additions & 0 deletions examples/data-solutions/data-playground/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

###############################################################################
# Project #
###############################################################################

module "project" {
source = "../../../modules/project"
billing_account = var.billing_account
name = var.project_name
parent = var.root_node
prefix = "data-playground"

services = [
"stackdriver.googleapis.com",
"compute.googleapis.com",
"storage-component.googleapis.com",
"storage.googleapis.com",
"servicenetworking.googleapis.com",
"bigquery.googleapis.com",
"bigquerystorage.googleapis.com",
"bigqueryreservation.googleapis.com",
"dataflow.googleapis.com",
"notebooks.googleapis.com",
"composer.googleapis.com"
]
}

###############################################################################
# Networking #
###############################################################################

module "vpc" {
source = "../../../modules/net-vpc"
project_id = module.project.project_id
name = var.vpc_name
subnets = [
{
ip_cidr_range = var.vpc_ip_cidr_range
name = var.vpc_subnet_name
region = var.region
secondary_ip_range = {}
}
]
}

module "vpc-firewall" {
source = "../../../modules/net-vpc-firewall"
project_id = module.project.project_id
network = module.vpc.name
admin_ranges = [var.vpc_ip_cidr_range]
}

###############################################################################
# GCS #
###############################################################################

module "base-gcs-bucket" {
source = "../../../modules/gcs"
project_id = module.project.project_id
prefix = module.project.project_id
name = "base"
}

###############################################################################
# Vertex AI Notebook #
###############################################################################

resource "google_notebooks_instance" "playground" {
name = "data-play-notebook"
location = format("%s-%s", var.region, var.zone)
machine_type = "e2-medium"
project = module.project.project_id

container_image {
repository = "gcr.io/deeplearning-platform-release/base-cpu"
tag = "latest"
}

install_gpu_driver = true
boot_disk_type = "PD_SSD"
boot_disk_size_gb = 110

no_public_ip = false
no_proxy_access = false

network = module.vpc.network.id
subnet = module.vpc.subnets[format("%s/%s", var.region, var.vpc_subnet_name)].id
}
33 changes: 33 additions & 0 deletions examples/data-solutions/data-playground/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

output "bucket" {
description = "GCS Bucket URL."
value = module.base-gcs-bucket.url
}

output "project" {
description = "Project id"
value = module.project.project_id
}

output "vpc" {
description = "VPC Network"
value = module.vpc.name
}

output "notebook" {
description = "Vertex AI notebook"
value = resource.google_notebooks_instance.playground.name
}
64 changes: 64 additions & 0 deletions examples/data-solutions/data-playground/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

variable "billing_account" {
description = "Billing account id used as default for new projects."
type = string
}

variable "location" {
description = "The location where resources will be deployed."
type = string
default = "europe"
}

variable "project_name" {
ludoo marked this conversation as resolved.
Show resolved Hide resolved
description = "Name for the project."
type = string
}

variable "region" {
description = "The region where resources will be deployed."
type = string
default = "europe-west1"
}

variable "zone" {
ludoo marked this conversation as resolved.
Show resolved Hide resolved
description = "The zone where resources will be deployed."
type = string
default = "b"
}

variable "root_node" {
description = "The resource name of the parent Folder or Organization. Must be of the form folders/folder_id or organizations/org_id."
type = string
}

variable "vpc_ip_cidr_range" {
ludoo marked this conversation as resolved.
Show resolved Hide resolved
description = "Ip range used in the subnet deployed in the project."
type = string
default = "10.0.0.0/20"
}

variable "vpc_name" {
description = "Name of the VPC created in the project."
type = string
default = "data-playground-vpc"
}

variable "vpc_subnet_name" {
description = "Name of the subnet created in the project."
type = string
default = "default-subnet"
}
27 changes: 27 additions & 0 deletions examples/data-solutions/data-playground/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

terraform {
required_version = ">= 1.1.0"
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.17.0"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.17.0"
}
}
}