Skip to content

fix config remote state s3 and update if needs #2063

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

Merged

Conversation

leonardobiffi
Copy link
Contributor

Hi, this PR is a suggestion to resolve the KMS config when the bucket is created, as the default key KMS ID is not being informed, the bucket has encryption enabled but without the KMS:

image

I am also suggesting an important change so that buckets that do not comply with the default encryption settings, public access blocking, bucket policy (enforce SSL only), access logging, versioning enabled are updated according to what is defined in the block of config. The disable_bucket_update attribute disable this behavior for anyone managing the bucket outside of terragrunt. This change causes the buckets to be updated when running terragrunt to conform to the config that are already made when the bucket is created.

Another fix is for the bucket policy, where currently only EnforcedTLS is being defined, the first policy configured for RootAccess is overwritten.
What I changed is to check the policy already configured and be attached to the existing one, as shown in the image below

image

Closes #1770
Closes #1143
Closes #1106

@denis256
Copy link
Member

Noticed that integration tests failed, each run different tests, I was wondering merge from master(to include #2073) will help tests to pass

https://app.circleci.com/pipelines/github/gruntwork-io/terragrunt?branch=pull-request-2063&filter=all

1 similar comment
@denis256
Copy link
Member

Noticed that integration tests failed, each run different tests, I was wondering merge from master(to include #2073) will help tests to pass

https://app.circleci.com/pipelines/github/gruntwork-io/terragrunt?branch=pull-request-2063&filter=all

@leonardobiffi
Copy link
Contributor Author

@denis256 Hi,
Did this change in the integration test work?
Do I need to change something in PR?

@denis256
Copy link
Member

@leonardobiffi try to merge the last changes from master and we will see if it will help to pass more integration tests

@leonardobiffi leonardobiffi requested a review from denis256 April 27, 2022 11:19
@denis256
Copy link
Member

Build passed 👍

denis256
denis256 previously approved these changes Apr 27, 2022
@leonardobiffi
Copy link
Contributor Author

@denis256 when this PR will be release?

@denis256
Copy link
Member

denis256 commented May 3, 2022

Hi, I think this week, I was doing more tests to see if will appear any issue when switching from older versions

@leonardobiffi
Copy link
Contributor Author

@denis256 awesome, let me known if anything is wrong

Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

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

This LGTM as well! Thanks for the contribution! I had one small request, but once that's addressed, we can move forward with this.

cc @denis256

Comment on lines 484 to 491
type S3BucketConfig struct {
Versioning string
SSEEncryption string
RootAccess string
EnforcedTLS string
AccessLogging string
PublicAccess string
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like value of the string is immaterial in configBucket, and is only used to track if these attributes need updating. Is that true?

If so, these should be bool instead of string and the struct should be renamed to something like S3BucketUpdatesRequired.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yorinasub17 Hi, it does make sense. I made the suggested adjustment and the necessary corrections. Let me know if I'm missing something

yorinasub17
yorinasub17 previously approved these changes May 5, 2022
Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

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

Updates LGTM! I'll kick off a regression build and if it passes, we can merge this in!

@denis256
Copy link
Member

denis256 commented May 6, 2022

Noticed that still fail test TestTerragruntStackCommands, 3 runs - 3 failures:

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

text = "[I am a mgmt vpc template. I have no dependencies.]"
=== CONT  TestTerragruntStackCommands
    integration_test.go:3716: Failed to run Terragrunt command 'terragrunt apply-all --terragrunt-non-interactive --terragrunt-working-dir /tmp/terragrunt-test076015731/fixture-stack/mgmt' due to error: 2 errors occurred:
        	* Cannot process module Module /tmp/terragrunt-test076015731/fixture-stack/mgmt/bastion-host (excluded: false, assume applied: false, dependencies: [/tmp/terragrunt-test076015731/fixture-stack/mgmt/vpc, /tmp/terragrunt-test076015731/fixture-stack/mgmt/kms-master-key]) because one of its dependencies, Module /tmp/terragrunt-test076015731/fixture-stack/mgmt/kms-master-key (excluded: false, assume applied: false, dependencies: []), finished with an error: NoSuchPublicAccessBlockConfiguration: The public access block configuration was not found
        	status code: 404, request id: 0QH1FH92JDDZNA0B, host id: +mMt9VWzhriq9ozRqh2/W0ko1XcwmIZy97r3j1tpTgDN/yjcU32ru4Tsm9W+vrhjYKsLaNgwFHA=
        	* NoSuchPublicAccessBlockConfiguration: The public access block configuration was not found
        	status code: 404, request id: 0QH1FH92JDDZNA0B, host id: +mMt9VWzhriq9ozRqh2/W0ko1XcwmIZy97r3j1tpTgDN/yjcU32ru4Tsm9W+vrhjYKsLaNgwFHA=
        
        
        
        Stdout: (see log output above)
        
        Stderr: (see log output above)

Can be a concurrency issue? when multiple tests try to change S3 configuration?

@leonardobiffi
Copy link
Contributor Author

leonardobiffi commented May 6, 2022

Noticed that still fail test TestTerragruntStackCommands, 3 runs - 3 failures:

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

text = "[I am a mgmt vpc template. I have no dependencies.]"
=== CONT  TestTerragruntStackCommands
    integration_test.go:3716: Failed to run Terragrunt command 'terragrunt apply-all --terragrunt-non-interactive --terragrunt-working-dir /tmp/terragrunt-test076015731/fixture-stack/mgmt' due to error: 2 errors occurred:
        	* Cannot process module Module /tmp/terragrunt-test076015731/fixture-stack/mgmt/bastion-host (excluded: false, assume applied: false, dependencies: [/tmp/terragrunt-test076015731/fixture-stack/mgmt/vpc, /tmp/terragrunt-test076015731/fixture-stack/mgmt/kms-master-key]) because one of its dependencies, Module /tmp/terragrunt-test076015731/fixture-stack/mgmt/kms-master-key (excluded: false, assume applied: false, dependencies: []), finished with an error: NoSuchPublicAccessBlockConfiguration: The public access block configuration was not found
        	status code: 404, request id: 0QH1FH92JDDZNA0B, host id: +mMt9VWzhriq9ozRqh2/W0ko1XcwmIZy97r3j1tpTgDN/yjcU32ru4Tsm9W+vrhjYKsLaNgwFHA=
        	* NoSuchPublicAccessBlockConfiguration: The public access block configuration was not found
        	status code: 404, request id: 0QH1FH92JDDZNA0B, host id: +mMt9VWzhriq9ozRqh2/W0ko1XcwmIZy97r3j1tpTgDN/yjcU32ru4Tsm9W+vrhjYKsLaNgwFHA=
        
        
        
        Stdout: (see log output above)
        
        Stderr: (see log output above)

Can be a concurrency issue? when multiple tests try to change S3 configuration?

@denis256 Hi, i fixed this error and the test passed. Can you validate?

See here this error message: https://github.com/aws/aws-sdk-go/blob/main/service/s3control/errors.go#L50

@denis256
Copy link
Member

denis256 commented May 6, 2022

I see the build started to pass, I'm still somehow suspect since the last change is to shallow NoSuchPublicAccessBlockConfiguration error, and before last change individual run of TestTerragruntStackCommands passed but it failed when the entire integration_test.go was executed

@leonardobiffi
Copy link
Contributor Author

@denis256 Hi,
The integration_test.go still failing because of update in s3?
I couldn`t see circleCI pipeline

@denis256
Copy link
Member

denis256 commented May 9, 2022

Hi, tests are passing all, I was wondering if is a good solution to shallow error NoSuchPublicAccessBlockConfiguration

@leonardobiffi
Copy link
Contributor Author

@denis256
Looking at this aws doc, I understood that this error happens for accounts that don't have the option to configure S3 PublicAccess at the account level

https://docs.aws.amazon.com/sdk-for-go/api/service/s3control/#S3Control.GetPublicAccessBlock
https://docs.aws.amazon.com/AmazonS3/latest/userguide/configuring-block-public-access-account.html

What do you think?

@denis256
Copy link
Member

denis256 commented May 10, 2022

Hello,
error make sense to handle for buckets without PublicAccess configured,
but it doesn't explain why individual execution of TestTerragruntStackCommands pass successfully, but run of entire integration tests fails on TestTerragruntStackCommands (all this before commit with handling of error), so far I think it is an issue of tests not of implementation and can be handled in other PR

@denis256 denis256 merged commit 05b1216 into gruntwork-io:master May 11, 2022
@denis256
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants