Configure Visual Studio Code For IBM-Cloud and Terraform Part — 1

What this page covers:

  • We are going to setup VS code, Git, and terraform provider.
  • We are going to clone the terraform project in VS code and modify the TF file using terraform extension.
  • We are going to provision the resource and push the template file to github.

Installation:

  1. Install VS Code
  • Install Git here based on your dev environment requirements.
  • Setup some basic required user config for git. Open a command prompt and run the following commands:
  • Download Terraform binary here.
  • Follow the instructions by hashicorp to download, install and setup hashicorp Terraform binary from here.

Configure VS Code:

  1. To Configure, launch VS Code.
  • Go to Extensions, search for Terraform (Forked) and click on install.
  • To verify if the extension is installed, go to extensions and search for @installed installed extension ll appear here.
  • Download the IBM Cloud provider plugin for Terraform templates using IBM Cloud resources.
  • Unzip the release archive to extract the plugin binary (terraform-provider-ibm_vX.Y.Z).
  • Move the binary into the Terraform plugins directory for the platform:

Cloning a terraform project:

Terraform Extension in Action :

  • Terraform (Forked) is a free extension for VS Code published by Frederic Lavigne, you can install it to increase the power of your Visual Studio Code.
  • Forked to include IBM Cloud provider. Syntax highlighting, linting, formatting, and validation for Hashicorp’s Terraform templates.
  • Type resource “ibm_<ctrl+space>” and you should see the IntelliSense options:
  • Inside a resources block “ibm_is_instance” (again, after pressing Ctrl + Space), it will list the available properties, and show if the property is optional or required, and the type of input (ie. “string”) the property is expecting.

Deploy Infrastructure:

  • terraform init
  • terraform plan
  • terraform apply
  • terraform destroy
  1. Select New Terminal from the terminal tab:
  • Export credentials as environment variables. This can either be IBM Cloud API keys or Softlayer API keys and usernames, depending on the resources you are provisioning.
  • Run terraform init in your VS Code terminal.
  • This is the first command that should be run after writing a new Terraform configuration or cloning an existing one from version control.
  • You’ll see this when the terraform is successfully initialized.
  • Run terraform plan in your VS Code terminal.
  • This command is checking whether the execution plan for a set of changes matches your expectations without making any changes to real resources or to the state.
  • For the above terraform template you’ll see this at the end of the terminal if the plan is successful.
  • Run terraform apply in your VS Code terminal.
  • This applies the changes required to reach the desired state of the configuration, or the pre-determined set of actions generated by the above executed plan.
  • After the plan is applied you’ll get the status of the resources added, updated and destroyed.
  • Now if we wish to destroy the Terraform infrastructure we created, we can simply run “terraform destroy”. This will destroy all the resources we have created in our Terraform infrastructure.
  • Run terraform destroy to delete applied resources from IBM Cloud. For more Terraform Commands use Terraform Commands CLI as a reference.

Configure VS Code for Git:

  • As you make changes in the repository, the Source Control icon on the left-hand pane should change to show uncommitted change for the repository.
  • Click on Source Control icon.
  • Hover of the main.tf file and click the ‘+’ to stage the file. This means it will be included in the next commit, allowing you to decide which files are committed and which files are not.
  • Enter a short message to describe the commit and hit the ‘tick’ to perform the commit.
  • push the commit to the repository, Open Terminal in vs code :

End of Part -1:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store