Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests and semaphoreci integration #2

Merged
merged 13 commits into from
Mar 17, 2020

Conversation

soerenmartius
Copy link
Member

@soerenmartius soerenmartius commented Mar 10, 2020

Implement an integration test:

  • Create ECR repository
  • Build a docker image
  • Authenticate with ECR
  • Push the docker image to ECR
  • Use Docker-out-of-Docker ( DooD ) approach to build docker image inside the build-tools container

@soerenmartius soerenmartius requested a review from mariux as a code owner March 10, 2020 13:30
mariux
mariux previously approved these changes Mar 10, 2020
Copy link
Member

@mariux mariux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@soerenmartius
Copy link
Member Author

Hi Marius,

The code is still a bit messy but it should be clear what we're doing here:

  • Create ECR repository
  • Build a docker image
  • Authenticate with ECR
  • Push the docker image to EC

Executing the test with AWS_ACCESS_KEY_ID=XXXX AWS_SECRET_ACCESS_KEY=XXXX go test -v -parallel 128 ./... works well now.

However, we currently can't run the test with our (https://hub.docker.com/r/mineiros/build-tools)[build-tools} docker image. If we'd like to be able to run the test inside a docker container, we need to add docker as a dependency to the build-tools image and start a privileged container. I don't think that this is a good practice though.

I would suggest, that we use a packer image to create and push the test docker image. However, that would come with a few downsides:

  • We can't cache docker builds with packer
  • The test would take longer
  • The test would likely create costs because packer spans up an EC2 instance.

wdyt @mariux ?

@soerenmartius
Copy link
Member Author

lgtm

We shouldn't approve PR's with failing tests though...

@soerenmartius soerenmartius force-pushed the tests-and-semaphoreci-integration branch from 7bea34b to 537c203 Compare March 11, 2020 13:41
@soerenmartius soerenmartius force-pushed the tests-and-semaphoreci-integration branch from 537c203 to a7f2067 Compare March 11, 2020 23:53
@soerenmartius
Copy link
Member Author

soerenmartius commented Mar 15, 2020

Hi Marius,

The code is still a bit messy but it should be clear what we're doing here:

  • Create ECR repository
  • Build a docker image
  • Authenticate with ECR
  • Push the docker image to EC

Executing the test with AWS_ACCESS_KEY_ID=XXXX AWS_SECRET_ACCESS_KEY=XXXX go test -v -parallel 128 ./... works well now.

However, we currently can't run the test with our ([https://hub.docker.com/r/mineiros/build-tools)build-tools}%5Bbuild-tools%7D) docker image. If we'd like to be able to run the test inside a docker container, we need to add docker as a dependency to the build-tools image and start a privileged container. I don't think that this is a good practice though.

I would suggest, that we use a packer image to create and push the test docker image. However, that would come with a few downsides:

  • We can't cache docker builds with packer
  • The test would take longer
  • The test would likely create costs because packer spans up an EC2 instance.

wdyt @mariux ?

For now, I chose the easiest way possible: Docker out of Docker

@soerenmartius soerenmartius requested a review from mariux March 15, 2020 20:13
@soerenmartius
Copy link
Member Author

Ready for review @mariux

@soerenmartius
Copy link
Member Author

I just saw that whenever we use terraform output, terratest writes the full output to stdout. It's not critical, since the created IAM User comes without any implicit permissions and will be destroyed after the test finished.
Still, it's not acceptable and a no go. I am gonna open a PR for terratest to suppress output logs for sensitive outputs.

@soerenmartius
Copy link
Member Author

I just saw that whenever we use terraform output, terratest writes the full output to stdout. It's not critical, since the created IAM User comes without any implicit permissions and will be destroyed after the test finished.
Still, it's not acceptable and a no go. I am gonna open a PR for terratest to suppress output logs for sensitive outputs.

gruntwork-io/terratest#476

Copy link
Member

@mariux mariux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should discuss how we want to deliver outputs... as this duplicates exported data and creates documentation overhead.

outputs.tf Outdated
Comment on lines 6 to 20
output "repository_arn" {
description = "The ARN of the repository."
value = try(aws_ecr_repository.repository[0].arn, null)
}

output "repository_id" {
description = "The Id of the repository."
value = try(aws_ecr_repository.repository[0].id, null)
}

output "repository_url" {
description = "The URL of the repository."
value = try(aws_ecr_repository.repository[0].repository_url, null)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? you can get them from the repository itself

module.name.repository.arn
module.name.repository_arn

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in aaa3cc7

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My take on outputs:

I don't have a strong opinion yet but here are some bullet points that lead me in the direction of explicit outputs:

  • returning the whole object doesn't really create a contract / valid API. What if the internal representation changes due to Provider upgrade? The module won't be able to guarantee backward compatibility anymore. If we return explicit outputs we can guarantee BC.
  • What does the user really want? Returning the whole resource will most likely end in a scenario in which the user only uses 20% of the outputs anyways ... do we really need all information?
  • We might return sensitive outputs per default if we always return the whole object?
  • No convenient API - the user would need to check the terraform providers documentation to get an overview of the outputs.

I will post this in the related trello task also.
wdyt?

Also: I think we might be ready to get this merged now ? :)

Copy link
Member

@mariux mariux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@soerenmartius soerenmartius merged commit c19bcc1 into master Mar 17, 2020
@soerenmartius soerenmartius deleted the tests-and-semaphoreci-integration branch March 17, 2020 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants