Important
You must follow this guide using this script.
Name | Description | Type | Default | Required |
---|---|---|---|---|
ssh_file | SSH public key path | string | "../.ssh/id_ed25519.pub" | yes |
ssh_file_private | SSH private key path | string | "../.ssh/id_ed25519" | yes |
env_file | Environment file path | string | "../.env" | yes |
credentials_file | GCP credentials file path | string | "../credentials.json" | yes |
project | GCP project name | string | "optimap-438115" | yes |
region | GCP region name | string | "asia-east1" | yes |
zone | GCP zone name | string | "asia-east1-c" | yes |
machine_type | GCP machine type | string | "n1-standard-8" | yes |
gpu_type | GPU type | string | "nvidia-tesla-t4" | yes |
gpu_count | GPU count | number | 1 | yes |
username | Google email ID | string | "sangyleegcp1" | yes |
dockerhub_id | Docker Hub username | string | n/a | yes |
dockerhub_pwd | Docker Hub password | string | n/a | yes |
Warning
The dockerhub_id
and dockerhub_pwd
variables have no default values and must be provided when applying the Terraform configuration.
-
create aws account
-
install aws cli For detailed installation instructions, please refer to the official AWS CLI documentation here.
- create google account
- add billing account to google cloud platform (for getting 300$ credits)
- Upgrade free trial account to paid Cloud Billing account. (for using GPU resources)
- Create new project
- Create Service account
Caution
You must set appropriate authority. IF you was confused which authority was better, Set the owner option.
Important
You must save this json file. This file will be used soon.
Important
IF you do not increase gpu quota, you will not get gpu resource when creating compute engine with gpu.
- create dockerhub account
- install terraform cli
Important
this section save terraform.tfstate file to aws s3 for collaborating. If you want to create own server locally, scroll down and follow Without Aws backend case.
aws configure --profile [your_profile_name]
> AWS Access Key ID [None]: [your id]
> AWS Secret Access Key [None]: [your secret key]
if Your setting is correct, you will show this screen
☁ ComputeEngineGPU-Terraform [main] cat ~/.aws/credentials
[your_profile_name]
aws_access_key_id = [your id]
aws_secret_access_key = [your secret key]
gcloud auth activate-service-account --key-file=./credentials.json
if Your setting is correct, you will show this screen
☁ ComputeEngineGPU-Terraform [main] gcloud auth list
Credentialed Accounts
ACTIVE ACCOUNT
* [email protected]
Important
your credentials.json must be root directory and must follow that name.
set project to glcoud cli
glcoud config set project ${project-name}
In previous setting section, move root directory to create pub key and private key wrapping .ssh directory in chapter 4
☁ ComputeEngineGPU-Terraform [main] ll .ssh
total 8.0K
-rw------- 1 sangylee sangylee 419 Oct 11 00:18 id_ed25519
-rw-r--r-- 1 sangylee sangylee 104 Oct 11 00:18 id_ed25519.pub
Important
your .ssh must be root directory and must follow that name.
Open ./variables.tf, change default value (project, username) to your own enviroment
Caution
project name must specify numbers after project name dash (-)
create terraform.prod.tfvars
in root directory and contents is following
dockerhub_id = "your docker hub id"
dockerhub_pwd = "yout docker hub pwd"
Important
terraform.prod.tfvars
is secret file. so you must not upload that files. I already add terraform.prod.tfvars
files in gitignore
You must change your aws profile name following downscript
./main.tf
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "4.49.0"
}
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
backend s3 {
bucket = "sangylee-s3-bucket-tfstate" # S3 버킷 이름
key = "terraform.tfstate" # tfstate 저장 경로
region = "ap-northeast-2"
dynamodb_table = "terraform-tfstate-lock" # dynamodb table 이름
profile = "(your aws profile name)" <--- change
}
}
`./provider.tf
provider "google" {
credentials = file(var.credentials_file)
project = var.project
region = var.region
zone = var.zone
}
provider "aws" {
region = "ap-northeast-2"
profile = "(your aws profile name)" <--- change
}
`./s3_init/provider.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
provider "aws" {
region = "ap-northeast-2"
profile = "(your aws profile name)" <--- change
}
make init
this command init s3 and dynamoDB with terraform backend
sudo chmod +x create_server_with_dynamic_zones.sh
bash ./create_server_with_dynamic_zones.sh
gcloud auth activate-service-account --key-file=./credentials.json
if Your setting is correct, you will show this screen
☁ ComputeEngineGPU-Terraform [main] gcloud auth list
Credentialed Accounts
ACTIVE ACCOUNT
* [email protected]
Important
your credentials.json must be root directory and must follow that name.
In previous setting section, move root directory to create pub key and private key wrapping .ssh directory in chapter 4
☁ ComputeEngineGPU-Terraform [main] ll .ssh
total 8.0K
-rw------- 1 sangylee sangylee 419 Oct 11 00:18 id_ed25519
-rw-r--r-- 1 sangylee sangylee 104 Oct 11 00:18 id_ed25519.pub
Important
your .ssh must be root directory and must follow that name.
Open ./variables.tf, change default value (project, username) to your own enviroment
Caution
project name must specify numbers after project name dash (-)
set project to glcoud cli
glcoud config set project ${project-name}
create terraform.prod.tfvars
in root directory and contents is following
dockerhub_id = "your docker hub id"
dockerhub_pwd = "yout docker hub pwd"
Important
terraform.prod.tfvars
is secret file. so you must not upload that files. I already add terraform.prod.tfvars
files in gitignore
Open src/provider.tf
, take a comment about aws provider
provider "google" {
credentials = file(var.credentials_file)
project = var.project
region = var.region
zone = var.zone
}
# comment this
# provider "aws" {
# region = "ap-northeast-2"
# profile = "falconlee236"
# }
Open src/main.tf
, take a comment about aws backend
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "4.49.0"
}
# take comment
# aws = {
# source = "hashicorp/aws"
# version = "~> 4.0"
# }
}
# take comment
# backend s3 {
# bucket = "sangylee-s3-bucket-tfstate" # S3 버킷 이름
# key = "terraform.tfstate" # tfstate 저장 경로
# region = "ap-northeast-2"
# dynamodb_table = "terraform-tfstate-lock" # dynamodb table 이름
# profile = "falconlee236"
# }
}
Important
this section save terraform.tf.state
file to local computer. So that you have to manage terraform state file.
sudo chmod +x create_server_with_dynamic_zones.sh
bash ./create_server_with_dynamic_zones.sh
If you want to change the following configurations, please refer to the information below:
- GPU Type
- CPU Type
in
create_server_with_dynamic_zones.sh
change outside of for statement in bash shell script. So you can change following option
export TF_VAR_machine_type="n1-standard-8"
export TF_VAR_gpu_type="nvidia-tesla-t4"
export TF_VAR_gpu_count=2
For more information, please visit Dynamic GPU Provisioning Script for Terraform.