IBM-Cloud / terraform-provider-ibm-docker

8 stars 15 forks source link

Update Dockerfile to fix terraformrc #8

Open dprosper opened 5 years ago

dprosper commented 5 years ago

While running trying to use the docker image available from DockerHub I received the following error message:

Provider "ibm" not available for installation.

A provider named "ibm" could not be found in the official repository.

This may result from mistyping the provider name, or the given provider may
be a third-party provider that cannot be installed automatically.

In the latter case, the plugin must be installed manually by locating and
downloading a suitable distribution package and placing the plugin's executable
file in the following directory:
    terraform.d/plugins/linux_amd64

Terraform detects necessary plugins by inspecting the configuration and state.
To view the provider versions requested by each module, run
"terraform providers".

Reviewing the docker file it looks like the command that generates the terraformrc is not working as expected, if you look at the inside of the docker image as pulled from DockerHub you find that the terraformrc looks like this:

bash-4.4# cat /root/.terraformrc 
 providers { 
 ibm = "/go/bin/terraform-provider-ibm_v${TERRAFORM_IBMCLOUD_VERSION}" 
 }
bash-4.4# 

That is because the single ' used to generate the file don't result in the environment variable to be properly evaluated. Instead you need to modify the RUN command to do the following:

RUN echo "providers { \
ibm = \"/go/bin/terraform-provider-ibm_v${TERRAFORM_IBMCLOUD_VERSION}\" \
}" > /root/.terraformrc
dprosper commented 5 years ago

even after making these changes in my local Dockerfile and creating a new image, I was still getting the error of not finding the ibm provider. I ended up placing the provider inside the /root/.terraform.d/plugins folder and it finally worked.

hkantare commented 5 years ago

Hi The binary is available as part of /go/bin/ directory.

$ docker pull ibmterraform/terraform-provider-ibm-docker $ docker run -it ibmterraform/terraform-provider-ibm-docker:latest

I performed this steps and logged into container. I'm able to successfully run terraform commands

dprosper commented 5 years ago

I don't understand why my experience would be any different since I am pulling the same image with the same commands.

What about this file, are the result for a cat command what you expect and want?

bash-4.4# cat /root/.terraformrc 
 providers { 
 ibm = "/go/bin/terraform-provider-ibm_v${TERRAFORM_IBMCLOUD_VERSION}" 
 }
bash-4.4# 
dprosper commented 5 years ago

I have narrowed down the issue. It seems to happen in templates that have the provider section, like in this example:

provider "ibm" {
  version          = "0.17.6"
  ibmcloud_api_key    = "${var.ibm_bmx_api_key}"
  iaas_classic_username = "${var.ibm_sl_username}"
  iaas_classic_api_key  = "${var.ibm_sl_api_key}"
}

Once you add this version restriction it fails.