Skip to content

lionelmace/learn-ibm-terraform

Repository files navigation

Learn terraform on IBM Cloud

Estimated duration: 30 mins

This lab will teach how to use Terraform in IBM Cloud and provision the following Cloud Services:

  • a Resource Group
  • a VPC
  • a Subnet
  • a SSH Key
  • a VSI (Virtual Server Instance)
  • a Floating IP

You can then ssh into the newly created VSI.

Terraform Estimation Duration
Apply ~2 mins
Destroy ~3 mins

Before you begin

This lab requires the following command lines:

Unless you are Administrator of the Cloud Account, you need permissions to be able to provision VPC Resources. Ask the Administrator run the Terraform in iam folder.

Lab

  1. Clone this repository

    git clone https://github.com/lionelmace/learn-ibm-terraform
  2. Login to IBM Cloud

    ibmcloud login
  3. Create and store the value of an API KEY as environment variable

    export IBMCLOUD_API_KEY=$(ibmcloud iam api-key-create my-api-key --output json | jq -r .apikey)

    If the variable "ibmcloud_api_key" is set in your provider, you can initialize it using the following command export TF_VAR_ibmcloud_api_key="Your IBM Cloud API Key"

  4. Terraform must initialize the provider before it can be used.

    terraform init
  5. Review the plan

    terraform plan
  6. Start provisioning.

    Estimated duration: 2 mins

    terraform apply

    Outputs look like this:

    ssh_connection_string = "ssh -i ./rsakey.pem root@VSI-FLOATING-IP"
    vsi_private_ip = "10.10.10.4"
    vsi_public_ip = "158.177.3.170"
  7. Connect to the VSI

    ssh -i ./rsakey.pem root@PUBLIC_IP
  8. Clean up the resources to avoid cost

    terraform destroy

Additional commands

  1. Once provisioned, reads and outputs a Terraform state or plan file in a human-readable form.

    terraform show
  2. Terraform graph outputs the visual execution graph of Terraform resources. The graph is outputted in DOT format, which can easily be converted to an image by making use of dot provided by GraphViz:

    terraform graph | dot -Tsvg > graph.svg

    Graph

About

Learn how to use Terraform with IBM Cloud

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages