terratest icon indicating copy to clipboard operation
terratest copied to clipboard

Add aws custom configuration support for local testing (i.e: localstack use)

Open ffernandezcast opened this issue 5 years ago • 30 comments

Issues related:

  • https://github.com/gruntwork-io/terratest/issues/494

  • https://github.com/gruntwork-io/terratest/issues/453

The goal is be able to use Terratest assert like AssertS3BucketExists without receive credentials issues because is trying to use aws cloud and not localstack terraform provider config

i.e:

include in your test something like:

Global test config file

var LocalEndpoints = map[string]string{
	"apigateway":     "http://localhost:4567",
	"cloudformation": "http://localhost:4581",
	"cloudwatch":     "http://localhost:4582",
	"dynamodb":       "http://localhost:4569",
	"es":             "http://localhost:4578",
	"firehose":       "http://localhost:4573",
	"iam":            "http://localhost:4593",
	"kinesis":        "http://localhost:4568",
	"lambda":         "http://localhost:4574",
	"route53":        "http://localhost:4580",
	"redshift":       "http://localhost:4577",
	"s3":             "http://localhost:4572",
	"secretsmanager": "http://localhost:4584",
	"ses":            "http://localhost:4579",
	"sns":            "http://localhost:4575",
	"sqs":            "http://localhost:4576",
	"ssm":            "http://localhost:4583",
	"stepfunctions":  "http://localhost:4585",
	"sts":            "http://localhost:4592",
}

Inside Global Setup Tests Suite File

func TestMain(m *testing.M) {
     aws.SetAwsEndpointsOverrides(LocalEndpoints)
}

ffernandezcast avatar Apr 07 '20 17:04 ffernandezcast

Hi, i am interested on this PR. Any update?

pinmarva avatar Nov 23 '20 19:11 pinmarva

Hi,

Any updates on this?

MrZablah avatar Jan 04 '21 18:01 MrZablah

This PR has been open for nearly 9mo. Any chance of this getting merged soon-ish? @yorinasub17 & @brikis98 any chance one of you can review?

edit: NM, looks like the PR is still missing unit tests.

synfinatic avatar Jan 12 '21 21:01 synfinatic

Also particularly interested in this feature!

rdelpret avatar Jan 14 '21 18:01 rdelpret

@yorinasub17 @brikis98 anything I can do to help shepard this PR through? Seem's like it is more or less done?

rdelpret avatar Jan 15 '21 16:01 rdelpret

I think the missing bit is some sort of automated testing for this new functionality. If someone wants to open up a new PR and wrap this up, please feel free!

brikis98 avatar Jan 18 '21 18:01 brikis98

I think the missing bit is some sort of automated testing for this new functionality. If someone wants to open up a new PR and wrap this up, please feel free!

I will try to do it(I'm facing some times constraints). But any contributions are welcome!!!

ffernandezcast avatar Jan 18 '21 21:01 ffernandezcast

Hi peers @brikis98 @yorinasub17 @synfinatic I have added some tests. Waiting for your feedback Thanks!

ffernandezcast avatar Jan 29 '21 10:01 ffernandezcast

@brikis98 @yorinasub17 @synfinatic any additional feedback or observation?

ffernandezcast avatar Feb 05 '21 16:02 ffernandezcast

LGTM. I would definitely squash the 94 commits though :) Unfortunately, I'm just some rando on the internet and don't actually have any approval permissions

synfinatic avatar Feb 05 '21 16:02 synfinatic

@brikis98 @yorinasub17 any feedback on this one?

rdelpret avatar Feb 22 '21 20:02 rdelpret

Sorry folks, we are unusually busy right now, and doing our best to work through the backlog of issues/PRs. We'll get to this as soon as we can.

brikis98 avatar Mar 01 '21 12:03 brikis98

Been over two months now since last update. I'm hoping to open source some code for terratest & localstack soon and I'd really like to avoid requiring people to pin a custom fork for terratest in their go.mod file.

synfinatic avatar May 10 '21 23:05 synfinatic

So one thing that this PR does not support is running multiple localstack containers for testing in parallel. This is because the variables storing the AWS Endpoints are global. Ideally this would not be the case, but TBH this is better than nothing. That said, I'm not sure adding this is supported without massive changes to terratest.

synfinatic avatar May 24 '21 18:05 synfinatic

Ugh, this PR has been open for 18 months and now has a merge conflict because of that. Right now I have code I'd like to open source which depends on this being merged, but it just doesn't make sense to release it if I have to maintain a fork.

@brikis98 How can I help move this forward? Or is this PR/solution dead in the water?

synfinatic avatar Oct 12 '21 14:10 synfinatic

This looks awesome - would also love to see this getting merged. 👍 Anything we can do to help push this forward? @ffernandezcast @brikis98 Thanks! 🙏

whummer avatar Oct 12 '21 15:10 whummer

This looks awesome - would also love to see this getting merged. 👍 Anything we can do to help push this forward? @ffernandezcast @brikis98 Thanks! 🙏

I did a quick update. Maybe could you test it to verify if keep backward compatibility. @whummer

ffernandezcast avatar Oct 18 '21 10:10 ffernandezcast

Ugh, this PR has been open for 18 months and now has a merge conflict because of that. Right now I have code I'd like to open source which depends on this being merged, but it just doesn't make sense to release it if I have to maintain a fork.

@brikis98 How can I help move this forward? Or is this PR/solution dead in the water?

I did a quick update. Maybe could you test it to verify if keep backward compatibility. @synfinatic

ffernandezcast avatar Oct 18 '21 10:10 ffernandezcast

@ffernandezcast : Yep, all my unit tests pass with your latest PR.

synfinatic avatar Oct 20 '21 18:10 synfinatic

Would be nice to get this merged. Any reason it is sitting for so long?

oblogic7 avatar Dec 29 '21 21:12 oblogic7

Are there any updates on this PR? Will this PR be merged at all?

tata2000 avatar May 05 '22 07:05 tata2000

It would be great to have this merged!

https://github.com/spulec/moto is another use case for this feature

jimsheldon avatar Jun 02 '22 16:06 jimsheldon

why is this not yet merged? how people test with localstack?

segator avatar Jul 10 '22 12:07 segator

Hey folks, my apologies for the continued delay here. There are two things at play here:

  1. To properly support LocalStack, there are two areas to consider, and there are open questions with both:
    1. Updating Terratest's own helpers to be able to talk to LocalStack. This is what this PR does, which is handy. However, it's only part of the story. Moreover, there are some open questions here to think through: e.g., the list of localEndpoints is already out of date, so how do we do this in a maintainable way?
    2. Updating the code you're deploying with Terratest to talk to LocalStack. For example, if you're using Terratest's terraform.Apply(t testing.T, opts *terraform.Options) helper to deploy a Terraform module, it would make sense to update the terraform.Options struct with a UseLocalStack parameter, that if set, overrides the Terraform module's provider configuration to use LocalStack (similar to the tflocal script). I don't think this PR does this yet. Moreover, there are open questions here to think through as well: e.g., do we just call tflocal directly or re-implement its logic in Go (and how maintainable will that be)?
  2. We are very overloaded right now:
    1. We're a small, bootstrapped company, so we have to be very picky in where we spend our time & resources. We do our best to maintain all aspects of Terratest that we depend on (e.g., the Terraform helpers, Docker helpers, K8S helpers, etc), but we don't currently use LocalStack ourselves. So it has been hard to justify carving out our time to think through those open questions. That said, we should've done a better job of updating you all on this!
    2. Note that we are currently working on our roadmap for the next few months and using LocalStack is one of the items we're considering. I don't know if it'll make the cut in the near term, but when it does, then we'll come back and give more thought to this PR. If not, others are welcome to think through the open questions above, and we'll try to respond if we can, but please understand we're doing our best to maintain this (fairly popular) open source project with limited resources, so we have to pick our battles.

brikis98 avatar Jul 29 '22 10:07 brikis98

@brikis98 Well, it's been 18mo since I started following this PR and honestly I no longer care at this point. I've killed my project which was dependent on this PR and moved on to other projects.

synfinatic avatar Jul 31 '22 16:07 synfinatic

Hi @brikis98 , thanks for the detailed response!

the list of localEndpoints is already out of date, so how do we do this in a maintainable way?

That's a great point - in fact, the list of services would need to be adjusted to cover the latest additions to LocalStack. The endpoint URL is the same for all services (port 4566 by default), so we can parameterize the list of services, then generate the localEndpoints map dynamically. 👍

it would make sense to update the terraform.Options struct with a UseLocalStack parameter, that if set, overrides the Terraform module's provider configuration to use LocalStack

Thanks for the pointer - that would be quite useful indeed!

LocalStack is one of the items we're considering [...] so we have to pick our battles

That's great, glad to hear that! And yes, very much understandable that you need to pick your battles. I'll see if I or someone from the LocalStack team can help address the points you've raised, so we can jointly work on getting this over the line. Thanks for your help!


@ffernandezcast Would you be ok if we work on this PR collaboratively, could you please give me push access to your fork/branch? (Alternatively, I could branch off your PR, and make sure that your original authorship is retained..) Thanks!

whummer avatar Aug 01 '22 13:08 whummer

@ ffernandezcast Thank you for this, I've had to fork this repo and apply your patch. Works perfectly, too bad GruntWork hasn't addressed this in the 2+ years now

blairham avatar Dec 02 '22 17:12 blairham

👏 thanks @blairham . It's a pity after we the community members invest our time for free and also promote and evangelise about framework use. Also I should answer to @brikis98 comments because I feel there is some misunderstanding in his comments about the proposal

ffernandezcast avatar Dec 02 '22 18:12 ffernandezcast

@brikis98 , there are two different things we are talking about

  1. To support terratest terraform APIs to talk to localstack
  2. To support terratest aws APIs to talk to localstack

First point is not even an issue currently as this can be easily handled from the .tf files with absolutely no changes to terratest APIs. I am not sure why this has to be even considered for this PR

PR is targeting point 2 where we are unable to use the aws module just because we cannot set an endpoint to do so.

Regarding your comment on time crunch, I can fully understand and that is why there is a community to help. When @ffernandezcast has spent considerable time on PR and even you have spent time reviewing it, I don't understand where its stuck? Reviewer's team has to spend time reviewing it, which is already being done.

This PR is fulfilling the purpose it was open for. It is not meant to do a full-fledge support for LocalStack as such. Cos this implementation can support moto as well which has nothing to do with localstack. I request you to re-look into this PR as its almost ready. This can help many of us :pray:

coding-yogi avatar Apr 12 '23 08:04 coding-yogi

👏 thanks @blairham . It's a pity after we the community members invest our time for free and also promote and evangelise about framework use. Also I should answer to @brikis98 comments because I feel there is some misunderstanding in his comments about the proposal

I have it working flawlessly in my own fork, it is a pity as I opened an MR but they wanted way too much from me to merge it. I'll continue to use my fork and maybe open it up to everyone else so the community can provide input

If you're interested, it's an easy fix with: https://github.com/gruntwork-io/terratest/pull/1211

blairham avatar Apr 28 '23 14:04 blairham