-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add support for a custom aws endpoint #1264
base: main
Are you sure you want to change the base?
Conversation
|
||
// Set a custom endpoint for AWS, and set the keys to dummy keys to | ||
// pass that check | ||
os.Setenv("TERRATEST_CUSTOM_AWS_ENDPOINT", "http://localhost:5000") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think should be better to use t.Setenv()
since it has automatic cleanup of env variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get this error:
panic: testing: t.Setenv called after t.Parallel; cannot set environment variables in parallel tests
If I make it a non parallel test it passes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, in the end I did change it to t.Setenv
. I just wanted to let you know that had to change it to a non parallel test for that to work.
Noticed that some of files aren't formatted:
|
Ah, sorry about that @denis256. I hadn't installed the pre-commit hooks in this repo. It should be fixed now. |
@denis256 It seems like the previous CI test failed because of a golang installation. I don't think I changed anything that would affect that. I added a new CI task that installs moto server and runs the local endpoint test case against it. I used this to test the installation of the dependencies and verify that the local server works:
However, it looks like there are some private repos this depends on, so I can't test the whole thing as it would be in CI. |
Not sure if are required any changes in |
Fixes gruntwork-io#494. This makes it possible to run terratest against a custom aws endpoint. This allows it to be used woth [Moto's standalone server mode](http://docs.getmoto.org/en/latest/docs/server_mode.html) for example, to test AWS modules locally without needing an AWS account or any access to AWS. Unfortunately these tests don't pass as is, because they would require setting up the moto server, and I'm not sure where that setup should be added. They do pass if the moto server is running.
It needs to be a separate group because moto server needs to be installed and running
d18e6dd
to
6905e03
Compare
Ok, done! |
I'm happy to update the docs too, although I don't know where I would add something like this. Specifically, I'd put something like this:
|
Documentation is located in the same repository, into |
@denis256 Added the docs and attempted to fix the circleci build again. Thanks for your patience! |
Co-authored-by: Etiene Dalcol <[email protected]>
I see an error in CI:
Do you have any advice on how to fix that? The other failures look unrelated to this change, so I'll merge in latest master. |
Co-authored-by: Etiene Dalcol <[email protected]>
Thanks @Etiene. I added your suggested change and merged in the latest master. |
Thank you @sverch. I think this looks good now! I've kicked off the tests again :) |
@Etiene Thanks for running that again! Fixed these issues:
I can't say for sure it'll work now, but hopefully that's one step closer! Although, the |
No worries! Running them again |
- run: | ||
command: | | ||
mkdir -p /tmp/logs | ||
run-go-tests --packages "-tags=mockaws -run TestTerraformAwsEndpointExample ./test/" | tee /tmp/logs/test_output.log |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
@Etiene Thanks for rerunning. I also needed to remove "localhost" from the terraform backend configuration and use 127.0.0.1 instead. |
The tests are still failing though! |
Ah, I see. So using the IP to try to get around the DNS issue doesn't really work because S3 is using a subdomain. I'll have to see if there's a circleci way to reference this local AWS server with a DNS name. But now I'm wondering why localhost didn't work before. I'm looking at https://circleci.com/docs/postgres-config/ for an example, and it says that services are available with localhost, and then when I look at https://circleci.com/docs/configuration-reference/, I see:
So I wonder if the reason it didn't work before is because localhost is meant to be used if you create a "service" container. The problem with that though is that I don't think I can run commands in the service container to run the mock aws server. At this point, I'm just speculating. The tests pass for me locally, so I think this does come down to figuring out how to properly connect to localhost in circleci. Any chance you've done this for any other tests? |
I have not done this for other tests before, sorry :( I could try investigating this in more details, but Im not sure if I'll have the time to get to it. |
I understand that @Etiene, and thank you for your patience with all the back and forth. I finally just created a custom circleci config on my own branch without the private gruntwork dependencies to get to the bottom of this, and was able to reproduce the issue. It turns out that Circleci doesn't expose any way to configure this as far as I can tell, so the only option from this end would be to run some custom DNS server. That's starting to get kind of heavyweight, and I wouldn't want to do anything that might be used by other tests or cause hard to debug issues later. So I tried to get the calls to s3 to use the "path style" API, and it worked! See: https://app.circleci.com/pipelines/github/sverch/terratest/12/workflows/5a161e91-bd96-4951-b7b2-b31d50f2919d/jobs/12 The caveats are that I had to add support for that in terratest, so the scope of this change is a bit bigger, and AWS wants to deprecate that someday (I put that in the comments). Enough people seem to be pushing back on it that it's unclear when that will actually happen. |
Description
Fixes #494.
This makes it possible to run terratest against a custom aws endpoint. This allows it to be used woth Moto's standalone server mode for example, to test AWS modules locally without needing an AWS account or any access to AWS.
Unfortunately these tests don't pass as is, because they would require setting up the moto server, and I'm not sure where that setup should be added. They do pass if the moto server is running.
TODOs
Read the Gruntwork contribution guidelines.
Release Notes (draft)
Added support for aws custom endpoints with
TERRATEST_CUSTOM_AWS_ENDPOINT
environment variable.Migration Guide
No migration needed. No changes if
TERRATEST_CUSTOM_AWS_ENDPOINT
is unset.