I am trying to build a btd pipeline for my code which involves AWS as well. I am using teamcity in which I run docker. For AWS resources dynamic creation I am using terraform. I have my AWS access and secret key set in teamcity environment variables, but passing those credentials to terraform cmd is not working
The dockerfile has all terraform command, while terraform initialises fine, it fails to run apply because of invalid AWS credentials
docker file
RUN apt-get -y install wget unzip
RUN wget https://releases.hashicorp.com/terraform/0.11.11/terraform_0.11.11_linux_amd64.zip
RUN unzip terraform_0.11.11_linux_amd64.zip
RUN mv terraform /usr/local/bin/
ADD main.tf /usr/local/bin
RUN chmod +x /usr/local/bin
RUN terraform init
RUN terraform apply -auto-approve /usr/local/bin/terraform -var 'access_key=${AWS_ACCESS_KEY}' -var 'secret_key=${AWS_SECRET_KEY}'
AWS_ACCESS_KEY and AWS_SECRET_KEY are stored in teamcity as environment variables. main.tf
provider "aws" {
region = "region-name"
}
resource "aws_instance" "aws_test" {
ami = "ami"
instance_type = "t2.micro"
subnet_id = "subnet-id"
#Security group
security_groups = ["security-group"]
}