Power User Method for Launching a VM Instance: Terraform

Terraform enables you to safely and predictably create, change, and improve production infrastructure - and in this case easily get an AWS instance running. Instructions for installing Terraform on multiple platforms are in the Terraform Getting Started along with an overview of Terraform concepts.

Setting Up a Security Group

Use the AWS Console to set up a security group as explained in the Preliminary Setup section.

Launching Your VM Instance

Get the Terraform configuration files (a Terraform config is a directory with several .tf files) from https://github.com/nvidia/ngc-examples. Once you clone that git repo to an ngc-examples directory on your system, you will find the Terraform files in ngc-examples/aws/terraform.

You will also need your AWS credentials by either:

  • Installing and configuring the AWS CLI (see Prerequisites). Terraform will use those AWS credentials.

Or

  • Add your access and secret keys to the configuration file in the provider section of variables.tf.

Initialize Terraform in that directory:

terraform init

Look at variables.tf and check that the variables agree with your desired setup and file locations. It's best practice to run terraform plan before any change in order to test and check for errors:

terraform plan

Then apply the configuration:

terraform apply

Your Amazon EC2 P3 instance will now be initializing, and Terraform will output the SSH command to connect to the instance once it's running. This may take several minutes.

At any time you can get the instance parameters and SSH line shown when you started the instance. Enter the configuration directory and type:

terraform output

Starting, Stopping, and Terminating Your VM Instance

Stop: (Requires that AWS CLI is installed)

aws ec2 stop-instances --instance-ids <instance_id>

Start:(Requires that AWS CLI is installed)

aws ec2 start-instances --instance-ids <instance_id>

Terminate:

terraform destroy