Terraform S3 backend authentication on Codeship/Docker












0















I'm using Terraform version 0.11.10 and I've setup the S3 backend and it works locally when I use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables for authentication.



provider "aws" {
region = "eu-west-1"
}

terraform {
backend "s3" {
bucket = "terraform-state-xxxxx"
region = "eu-west-1"
key = "terraform/dev.tfstate"
dynamodb_table = "terraform-locks"
}
}


However when I try to run the exact same code in the hashicorp/terraform:0.11.10 Docker container on Codeship with the same environment variables it gives the following error:




Initializing the backend...



Error configuring the backend "s3": InvalidClientTokenId: The security
token included in the request is invalid.




If I set skip_credentials_validation = "true" then I get the following:




InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.




Why is it not using the credentials from the environment variables?



There is no ~/.aws/credentials file or any other place it could be getting credentials from that I am aware of.










share|improve this question























  • Hi @Mikhail - have you checked if the environment variables are being inherited by the Docker container? Run Terraform in debug mode to see what it sees. terraform.io/docs/internals/debugging.html

    – KJH
    Nov 23 '18 at 15:46











  • Hi @KJH, yes the variables are there. I found the problem, it was that I had quotes around the environment variable values and for some reason they were being escaped and used as part of the access key. I just had to remove the quotes.

    – Mikhail Janowski
    Nov 25 '18 at 15:38











  • Great! You should write that as your answer, then you can accept it after 2 days.

    – KJH
    Nov 25 '18 at 17:19
















0















I'm using Terraform version 0.11.10 and I've setup the S3 backend and it works locally when I use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables for authentication.



provider "aws" {
region = "eu-west-1"
}

terraform {
backend "s3" {
bucket = "terraform-state-xxxxx"
region = "eu-west-1"
key = "terraform/dev.tfstate"
dynamodb_table = "terraform-locks"
}
}


However when I try to run the exact same code in the hashicorp/terraform:0.11.10 Docker container on Codeship with the same environment variables it gives the following error:




Initializing the backend...



Error configuring the backend "s3": InvalidClientTokenId: The security
token included in the request is invalid.




If I set skip_credentials_validation = "true" then I get the following:




InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.




Why is it not using the credentials from the environment variables?



There is no ~/.aws/credentials file or any other place it could be getting credentials from that I am aware of.










share|improve this question























  • Hi @Mikhail - have you checked if the environment variables are being inherited by the Docker container? Run Terraform in debug mode to see what it sees. terraform.io/docs/internals/debugging.html

    – KJH
    Nov 23 '18 at 15:46











  • Hi @KJH, yes the variables are there. I found the problem, it was that I had quotes around the environment variable values and for some reason they were being escaped and used as part of the access key. I just had to remove the quotes.

    – Mikhail Janowski
    Nov 25 '18 at 15:38











  • Great! You should write that as your answer, then you can accept it after 2 days.

    – KJH
    Nov 25 '18 at 17:19














0












0








0








I'm using Terraform version 0.11.10 and I've setup the S3 backend and it works locally when I use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables for authentication.



provider "aws" {
region = "eu-west-1"
}

terraform {
backend "s3" {
bucket = "terraform-state-xxxxx"
region = "eu-west-1"
key = "terraform/dev.tfstate"
dynamodb_table = "terraform-locks"
}
}


However when I try to run the exact same code in the hashicorp/terraform:0.11.10 Docker container on Codeship with the same environment variables it gives the following error:




Initializing the backend...



Error configuring the backend "s3": InvalidClientTokenId: The security
token included in the request is invalid.




If I set skip_credentials_validation = "true" then I get the following:




InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.




Why is it not using the credentials from the environment variables?



There is no ~/.aws/credentials file or any other place it could be getting credentials from that I am aware of.










share|improve this question














I'm using Terraform version 0.11.10 and I've setup the S3 backend and it works locally when I use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables for authentication.



provider "aws" {
region = "eu-west-1"
}

terraform {
backend "s3" {
bucket = "terraform-state-xxxxx"
region = "eu-west-1"
key = "terraform/dev.tfstate"
dynamodb_table = "terraform-locks"
}
}


However when I try to run the exact same code in the hashicorp/terraform:0.11.10 Docker container on Codeship with the same environment variables it gives the following error:




Initializing the backend...



Error configuring the backend "s3": InvalidClientTokenId: The security
token included in the request is invalid.




If I set skip_credentials_validation = "true" then I get the following:




InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.




Why is it not using the credentials from the environment variables?



There is no ~/.aws/credentials file or any other place it could be getting credentials from that I am aware of.







docker amazon-s3 terraform codeship






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 10:32









Mikhail JanowskiMikhail Janowski

75411024




75411024













  • Hi @Mikhail - have you checked if the environment variables are being inherited by the Docker container? Run Terraform in debug mode to see what it sees. terraform.io/docs/internals/debugging.html

    – KJH
    Nov 23 '18 at 15:46











  • Hi @KJH, yes the variables are there. I found the problem, it was that I had quotes around the environment variable values and for some reason they were being escaped and used as part of the access key. I just had to remove the quotes.

    – Mikhail Janowski
    Nov 25 '18 at 15:38











  • Great! You should write that as your answer, then you can accept it after 2 days.

    – KJH
    Nov 25 '18 at 17:19



















  • Hi @Mikhail - have you checked if the environment variables are being inherited by the Docker container? Run Terraform in debug mode to see what it sees. terraform.io/docs/internals/debugging.html

    – KJH
    Nov 23 '18 at 15:46











  • Hi @KJH, yes the variables are there. I found the problem, it was that I had quotes around the environment variable values and for some reason they were being escaped and used as part of the access key. I just had to remove the quotes.

    – Mikhail Janowski
    Nov 25 '18 at 15:38











  • Great! You should write that as your answer, then you can accept it after 2 days.

    – KJH
    Nov 25 '18 at 17:19

















Hi @Mikhail - have you checked if the environment variables are being inherited by the Docker container? Run Terraform in debug mode to see what it sees. terraform.io/docs/internals/debugging.html

– KJH
Nov 23 '18 at 15:46





Hi @Mikhail - have you checked if the environment variables are being inherited by the Docker container? Run Terraform in debug mode to see what it sees. terraform.io/docs/internals/debugging.html

– KJH
Nov 23 '18 at 15:46













Hi @KJH, yes the variables are there. I found the problem, it was that I had quotes around the environment variable values and for some reason they were being escaped and used as part of the access key. I just had to remove the quotes.

– Mikhail Janowski
Nov 25 '18 at 15:38





Hi @KJH, yes the variables are there. I found the problem, it was that I had quotes around the environment variable values and for some reason they were being escaped and used as part of the access key. I just had to remove the quotes.

– Mikhail Janowski
Nov 25 '18 at 15:38













Great! You should write that as your answer, then you can accept it after 2 days.

– KJH
Nov 25 '18 at 17:19





Great! You should write that as your answer, then you can accept it after 2 days.

– KJH
Nov 25 '18 at 17:19












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391044%2fterraform-s3-backend-authentication-on-codeship-docker%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391044%2fterraform-s3-backend-authentication-on-codeship-docker%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()