github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/deploy/dev/terraform/README.md (about) 1 # Terraform - AIS GCP Playground 2 3 AIS can be run in bare VM or bare metal cluster. Here you can find simple `terraform` configuration which allows you to spin-up an Ubuntu VM on GCP with AIStore deployed. 4 5 ## Prerequisites 6 1. [Terraform (>= 0.12)](https://learn.hashicorp.com/tutorials/terraform/install-cli) 7 2. [GCP Project & Credentials](https://console.cloud.google.com/home/dashboard) 8 3. [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) 9 10 ## Deployment 11 12 > **NOTE**: All commands should be executed from `deploy/dev/terraform` directory 13 14 ### Setting variables (terraform.tfvars) 15 1. Get the GCP `json` credentials [service account key page](https://console.cloud.google.com/apis/credentials/serviceaccountkey). 16 2. Update the `creds_file` variable to point to the downloaded `json` credentials file. 17 3. Set `project_id` to your GCP project ID. 18 4. Update the `ssh_private_file` and `ssh_public_file` to point to your `private` (e.g `~/.ssh/id_rsa`) and `public` (e.g `~/.ssh/id_rsa.pub`) keys. These are required to SSH into the deployed VM. If you wish to create a new ssh key pairs refer [this](https://www.ssh.com/ssh/keygen/) 19 5. Optionally, set the following variables: 20 - `region` (default: `us-central1`) : GCP deployment region 21 - `zone` (default: `us-central1-c`) : GCP deployment zone 22 - `ansible_file` (default: `ansible/setupnodes.yml`) : ansible playbook for setting up AIStore on VM 23 24 #### Sample Configuration 25 Below is a sample variables file (terraform.tfvars) 26 ``` 27 creds_file = "/home/ubuntu/creds/aistore-gcp.json" 28 project_id = "aistore-29227" 29 ssh_private_file = "~/.ssh/gcp" 30 ssh_public_file = "~/.ssh/gcp.pub" 31 ``` 32 33 ### Useful commands 34 35 After updating the variables execute the below commands: 36 37 #### Initialize the terraform workspace 38 (to download the required provider plugins) 39 ```console script 40 $ terraform init 41 Initializing the backend... 42 43 Initializing provider plugins... 44 - Using previously-installed hashicorp/google v3.5.0 45 - Using previously-installed hashicorp/null v2.1.2 46 47 Terraform has been successfully initialized! 48 $ 49 ``` 50 51 #### Provisioning VM and deploying AIStore 52 (this might take a few minutes) 53 ```console 54 $ terraform apply 55 google_compute_network.vpc_network: Creating... 56 google_compute_network.vpc_network: Still creating... [10s elapsed] 57 google_compute_network.vpc_network: Still creating... [20s elapsed] 58 google_compute_network.vpc_network: Still creating... [30s elapsed] 59 google_compute_network.vpc_network: Still creating... [40s elapsed] 60 google_compute_network.vpc_network: Creation complete after 47s [id=projects/aistore-291017/global/networks/terraform-network] 61 google_compute_firewall.allow-ssh: Creating... 62 google_compute_instance.vm_instance: Creating... 63 google_compute_firewall.allow-ssh: Creation complete after 7s [id=projects/aistore-291017/global/firewalls/fw-allow-ssh] 64 google_compute_instance.vm_instance: Provisioning with 'remote-exec'... 65 .... TRUCATED .... 66 google_compute_instance.vm_instance (local-exec): Executing: ["/bin/sh" "-c" "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u ubuntu -i '<IP>,' --private-key /root/.ssh/gcp ansible/setupnodes.yml"] 67 68 google_compute_instance.vm_instance (local-exec): PLAY [all] ********************************************************************* 69 70 google_compute_instance.vm_instance (local-exec): TASK [copy] ******************************************************************** 71 google_compute_instance.vm_instance (local-exec): changed: [<IP>] => (item=setupnodes.sh) 72 73 google_compute_instance.vm_instance (local-exec): TASK [Execute the command in remote shell; stdout goes to the specified file on the remote.] *** 74 75 google_compute_instance.vm_instance (local-exec): PLAY RECAP ********************************************************************* 76 google_compute_instance.vm_instance (local-exec): <IP> : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 77 78 google_compute_instance.vm_instance: Creation complete after 6m22s [id=projects/aistore-291017/zones/us-central1-c/instances/terraform-instance] 79 80 Apply complete! Resources: 3 added, 0 changed, 0 destroyed. 81 82 Outputs: 83 84 external_ip = <IP> 85 ``` 86 87 #### Getting external IP address 88 ```console 89 $ terraform output 90 external_ip = <IP> 91 ``` 92 93 `ssh` into the VM to check the installation 94 ```console 95 $ ssh -i <path-private-key> ubuntu@<EXTERNAL_IP> 96 ``` 97 98 #### Destroying the VM 99 ```console 100 $ terraform destroy 101 ```