Jan-Hendrik Palic
Jan-Hendrik Palic

Reputation: 51

Configure terraform to connect to IBM Cloud

I try to connect terraform to IBM Cloud and I got messed up with Softlayer and IBM Cloud credentials.

I followed the instruction on IBM sites to connect my terraform to the IBM Cloud and I am confused, because I may use SL and IBM Cloud connec- tion information like API-keys etc.

I may not run terraform init and/or plan, because there are some information missing. No I am asked for the organization (var.org). Sometimes I got asked about the SL credentials. Our account started in January 2019 and I am sure not to worked with SL at all and only heard about API key from IBM cloud.

May some one have an example, how terraform.tfvars looks like to work properly together with IBM Cloud Kubernetes Service, VPC and classic infrastructure?

Thank you very much.

Jan

Upvotes: 2

Views: 487

Answers (3)

naglep
naglep

Reputation: 1

Here is what you will need to run an init or plan for IBM Cloud Kubernetes Service clusters with terraform...

In your .tf file

terraform {
  required_providers {
    ibm = {
      source = "IBM-Cloud/ibm"
    }
  }
}

provider "ibm" {
  ibmcloud_api_key   = var.ibmcloud_api_key
  iaas_classic_username = var.classic_username
  iaas_classic_api_key  = var.classic_api_key
}

In your shell, set the following environment variables

export IBMCLOUD_API_KEY=<value of your IBM Cloud api key>
export CLASSIC_API_KEY=<Value of you r IBM Cloud classic (i.e. SL) api key>
export CLASSIC_USERNAME=<Value of your IBM Cloud classic username>

Run your init as follows:

terraform init

Run your plan as follows:

terraform plan \
   -var ibmcloud_api_key="${IBMCLOUD_API_KEY}" \
   -var classic_api_key="${CLASSIC_API_KEY}" \
   -var classic_username="${CLASSIC_USERNAME}" 

Upvotes: 0

Powell Quiring
Powell Quiring

Reputation: 2464

For the public_key a string containing the public key should be provided instead of a file that contains the key.

$ cat ~/.ssh/id_rsa.pub
ssh-rsa CCCde...

Then in terraform:

resource "ibm_compute_ssh_key" "test_ssh_key" {
    public_key = "ssh-rsa CCCde..."
}

Alternatively you can use a key that you created earlier:

data "ibm_compute_ssh_key" "ssh_key" {
    label =  "yourexistingkey"
}

resource "ibm_compute_vm_instance" "onprem_vsi" {
  ssh_key_ids       = ["${data.ibm_compute_ssh_key.ssh_key.id}"]
}

Upvotes: 1

data_henrik
data_henrik

Reputation: 17176

I recommend starting to take a look at these two tutorials, dealing with a LAMP stack on classic vertical servers and with Kubernetes and other services. Both provide step by step instructions and guide you through the process of setting up Terraform-based deployments.

They provide the necessary code in GitHub repos. For the Kubernetes sample credentials.tfvars you only need the API key:

ibmcloud_api_key = "your api key"

Upvotes: 2

Related Questions