GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — separate remote-state by env by davidcheung · Pull Request #39 · commitdev/zero-aws-eks-stack

Conversation

@davidcheung

@davidcheung davidcheung commented May 4, 2020

Copy link
Copy Markdown
Contributor

No description provided.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@davidcheung
davidcheung requested review from bmonkman and karimkawambwa May 4, 2020 18:49
bmonkman
bmonkman reviewed May 4, 2020
View reviewed changes
Comment thread terraform/bootstrap/remote-state/production/main.tf Outdated

@bmonkman bmonkman May 4, 2020

Copy link
Copy Markdown
Contributor

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.

We already have the environment provided as a variable when apply is run. How about just use that var here so we don't have to duplicate the files?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

karimkawambwa reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@davidcheung davidcheung May 4, 2020

Copy link
Copy Markdown
Contributor Author

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.

as in not moving it to a module?
I would still need 1 set of the file per env, right?

or you mean just using environment = var.environment

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bmonkman bmonkman May 4, 2020

Copy link
Copy Markdown
Contributor

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.

Yeah, just using the variable.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bmonkman bmonkman May 4, 2020

Copy link
Copy Markdown
Contributor

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.

Actually I think even having it as a module is overkill. How about just leave it as it was before, but accept the environment variable?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@davidcheung davidcheung May 4, 2020

Copy link
Copy Markdown
Contributor Author

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.

sure, either way is easy to change down the road

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bmonkman reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
karimkawambwa
karimkawambwa suggested changes May 4, 2020
View reviewed changes
Comment thread Makefile Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Makefile Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread terraform/bootstrap/remote-state/staging/main.tf Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread terraform/bootstrap/remote-state/staging/main.tf Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread terraform/bootstrap/remote-state/production/main.tf Resolved

Uh oh!

There was an error while loading. Please reload this page.

@davidcheung
davidcheung force-pushed the remote-state-env branch from 536fb59 to 0443b19 Compare May 4, 2020 21:15
@bmonkman

bmonkman commented May 4, 2020

Copy link
Copy Markdown
Contributor

Now can you just move main.tf up so it's not inside an environment directory?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@davidcheung

davidcheung commented May 4, 2020

Copy link
Copy Markdown
Contributor Author

Not sure if I understand, you mean /remote-state/production/main.tf -> /remote-state/main.tf?
this would go back to the original behavior where they end up sharing state across envs no?

Now can you just move main.tf up so it's not inside an environment directory?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bmonkman

bmonkman commented May 4, 2020

Copy link
Copy Markdown
Contributor

This is part of a bigger discussion actually. The local state here is what's causing the problem, and I think the way we are dealing with that is not quite right. We can't rely on the local state being present for this because it won't be checked in to source control. And if that's the case we should probably just remove it so people don't depend on it. Though that does make it a bit harder to test with because we can't have a teardown command for the remote state that we bootstrap.
I think there are 2 options here:

  1. Delete the local state file after this operation. If someone wants to tear down the environment they would have to manually delete the s3 bucket and dynamodb table. This is fine for normal use cases, as most likely you will create the remote state and leave it forever. It's a pain for testing when you may need to delete and recreate.

  2. Write out different state files with the -state=production.tfstate and check them in. Having state in git is not great, and this is not necessary for most cases, but it makes it easer for testing.

I guess a hybrid approach could be to write out state files for the different environments and then exclude them with gitignore, and use them only for testing. But I would be a bit worried that this would be misleading for people.
Or maybe we need some separate make targets just for testing.
Thoughts?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@davidcheung

davidcheung commented May 4, 2020

Copy link
Copy Markdown
Contributor Author

the teardown already often requires manually emptying the S3 bucket, we could alias some commands to do what the terraform destroy since its only 2 resources to replace the make teardown

if we do option2 with -state=production.tfstate <- this means we will treat tfstate as a first class citizen and tie it into our infra? and pull out the correct state based on ENV=?

Hmm, is having 2 folders for 2 env's TF local state that bad? I feel this is the less confusing route. And all the other stuff would go into the correct remote state since theyre initiated with the terraform backend with terraform/environments/production/main.tf etc (or you're talking about removing all the environment folders altogether?)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bmonkman

bmonkman commented May 4, 2020

Copy link
Copy Markdown
Contributor

The problem with having directories per environment is that it implies that there should be local state which is not the case.
I'm kinda leaning toward wanting to just delete the local state files after they are created to reinforce the fact that it shouldn't be relied upon.
And if we really want to have some helpers for testing maybe we just delete those resources using the aws cli like you mentioned.
Same goes for secrets.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

davidcheung
davidcheung commented May 5, 2020
View reviewed changes
Comment thread Makefile Resolved

Uh oh!

There was an error while loading. Please reload this page.

bmonkman
bmonkman reviewed May 5, 2020
View reviewed changes
Comment thread Makefile Resolved

Uh oh!

There was an error while loading. Please reload this page.

bmonkman
bmonkman reviewed May 6, 2020
View reviewed changes
Comment thread Makefile Outdated

@bmonkman bmonkman May 6, 2020

Copy link
Copy Markdown
Contributor

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.

The keys should be deleted automatically if the user is deleted, I don't think this is necessary.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@davidcheung davidcheung May 6, 2020

Copy link
Copy Markdown
Contributor Author

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.

they actually dont cascade delete entities it seems, i get the following error without deleting the keys

An error occurred (DeleteConflict) when calling the DeleteUser operation: Cannot delete entity, must delete access keys first.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bmonkman reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@bmonkman bmonkman May 7, 2020

Copy link
Copy Markdown
Contributor

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.

Okay, one more thing to try.. The --access-key-id param to delete-access-key takes a regex. Could you just say -access-key-id .*?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@davidcheung davidcheung May 7, 2020

Copy link
Copy Markdown
Contributor Author

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.

their man page is lying i suspect, it may support regex but it needs to go through a bunch of validation that conforms the keyID's schema 🤦

with .*?

Parameter validation failed:
Invalid length for parameter AccessKeyId, value: 3, valid range: 16-inf

i tried to make it 16 character or above with \w\w\w\w\w\w\w\w[\w]+ then it gave me

An error occurred (ValidationError) when calling the DeleteAccessKey operation: The specified value for accessKeyId is invalid. It must contain only alphanumeric characters.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bmonkman bmonkman May 7, 2020

Copy link
Copy Markdown
Contributor

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.

Sheesh. Oh well, thanks for trying!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
bmonkman
bmonkman approved these changes May 7, 2020
View reviewed changes
@davidcheung
davidcheung force-pushed the remote-state-env branch from e548f69 to e8f4327 Compare May 7, 2020 17:01
@davidcheung
separate remote-state by env
f5e7746
@davidcheung
davidcheung force-pushed the remote-state-env branch from e8f4327 to f5e7746 Compare May 7, 2020 17:05
@davidcheung
davidcheung merged commit fbc9d9e into master May 7, 2020
@davidcheung
davidcheung deleted the remote-state-env branch May 7, 2020 18:26
bmonkman pushed a commit that referenced this pull request Oct 10, 2020
@davidcheung
Merge pull request #39 from commitdev/remote-state-env
cb256c3
separate remote-state by env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

2 more reviewers
@karimkawambwa karimkawambwa karimkawambwa requested changes
@bmonkman bmonkman bmonkman approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@davidcheung @bmonkman @karimkawambwa
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.