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

Allow to use a whole local directory as IaC source #292

Merged
merged 1 commit into from
Feb 26, 2021

Conversation

eliecharra
Copy link
Contributor

Q A
πŸ› Bug fix? no
πŸš€ New feature? yes
⚠ Deprecations? no
❌ BC Break no
πŸ”— Related issues #253
❓ Documentation yes

Description

Allow to use a whole local directory as IaC source.
⚠️ Does not follow symlinks within root folder

@eliecharra eliecharra added the kind/enhancement New feature or improvement label Feb 24, 2021
@eliecharra eliecharra requested a review from a team February 24, 2021 11:02
@eliecharra eliecharra marked this pull request as ready for review February 26, 2021 09:15
@codecov
Copy link

codecov bot commented Feb 26, 2021

Codecov Report

Merging #292 (c90da70) into main (ab41545) will increase coverage by 0.02%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #292      +/-   ##
==========================================
+ Coverage   68.87%   68.90%   +0.02%     
==========================================
  Files         258      259       +1     
  Lines        5523     5554      +31     
==========================================
+ Hits         3804     3827      +23     
- Misses       1392     1398       +6     
- Partials      327      329       +2     
Impacted Files Coverage Ξ”
pkg/iac/terraform/state/enumerator/file.go 85.71% <85.71%> (ΓΈ)
...iac/terraform/state/enumerator/state_enumerator.go 55.55% <100.00%> (-44.45%) ⬇️

Copy link
Contributor

@lotoussa lotoussa left a comment

Choose a reason for hiding this comment

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

Seems cool πŸ‘

moadibfr
moadibfr previously approved these changes Feb 26, 2021
Copy link
Contributor

@wbeuil wbeuil left a comment

Choose a reason for hiding this comment

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

Need to change all multiples to multiple.

I tested it like you did which works perfectly. But we're gonna have problems with people who would like to use it with a folder like this one below which seems pretty normal in terragrunt environment if I remember well:

β”œβ”€β”€ route53
β”‚   └── terraform.tf
β”‚   └── terraform.tfstate
└── s3
    └── terraform.tf
    └── terraform.tfstate

driftctl scan will output:

image

Maybe in another PR we should check that files are indeed terraform.states files before adding them to the slice.


// File enumeration does not follow symlinks.
// We may use something like this https://pkg.go.dev/github.com/facebookgo/symwalk
// to follow links, but it allow infinite loop so be careful !
Copy link
Contributor

Choose a reason for hiding this comment

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

it allows ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like I need to take English lesson on the plural rule with you πŸ˜…

@@ -9,6 +9,33 @@ import (
"github.com/cloudskiff/driftctl/test/acceptance/awsutils"
)

func TestAcc_StateReader_WithMultiplesStatesInDirectory(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Multiple no S ^^

acceptance.Run(t, acceptance.AccTestCase{
Paths: []string{
"./testdata/acc/multiples_states_local/s3",
"./testdata/acc/multiples_states_local/route53",
Copy link
Contributor

Choose a reason for hiding this comment

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

All your multiples_.... must be changed

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also rename the folder multiples_states_local to multiple_states_local

@eliecharra
Copy link
Contributor Author

Need to change all multiples to multiple.

Sure nice catch πŸ™πŸ»

I tested it like you did which works perfectly. But we're gonna have problems with people who would like to use it with a folder like this one below which seems pretty normal in terragrunt environment if I remember well:

This is a real question, it can totally be done in this PR but I don't know exactly what we want to do.
The .tfstate extension is not enforced by terraform at all, so I don't think we can hardcode a check on this extension.
Maybe it's the responsibility to the user to specify the pattern in the --from argument with a glob pattern for example.

I had in mind something like THAT

@wbeuil
Copy link
Contributor

wbeuil commented Feb 26, 2021

This is a real question, it can totally be done in this PR but I don't know exactly what we want to do.
The .tfstate extension is not enforced by terraform at all, so I don't think we can hardcode a check on this extension.
Maybe it's the responsibility to the user to specify the pattern in the --from argument with a glob pattern for example.

Agree we must not hardcode a check on any extension. Either it's gonna be the user who would specify a pattern like you did or if it's possible we could check if a file is a terraform state but I can't find a method in their repo that does that yet ...

I'd say we could first ship this PR with the changes I requested, then ask @sjourdan about his view and finally decide which way to go.

@lotoussa
Copy link
Contributor

This is a real question, it can totally be done in this PR but I don't know exactly what we want to do.
The .tfstate extension is not enforced by terraform at all, so I don't think we can hardcode a check on this extension.
Maybe it's the responsibility to the user to specify the pattern in the --from argument with a glob pattern for example.

Agree we must not hardcode a check on any extension. Either it's gonna be the user who would specify a pattern like you did or if it's possible we could check if a file is a terraform state but I can't find a method in their repo that does that yet ...

I'd say we could first ship this PR with the changes I requested, then ask @sjourdan about his view and finally decide which way to go.

Can't we use magic number to check ? I'm not sure there is an identification for tf state tho.

@moadibfr
Copy link
Contributor

The scope of ticket in this release was just to be able to use a batch of tfstate inside a repository. We talked about blob filtering but this was more intended as a first step from what I remember.

Copy link
Contributor

@wbeuil wbeuil left a comment

Choose a reason for hiding this comment

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

LGTM now

@eliecharra eliecharra merged commit d9b4ca5 into main Feb 26, 2021
@eliecharra eliecharra deleted the allow_local_state_enumeration branch February 26, 2021 15:16
@eliecharra eliecharra linked an issue Feb 26, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Be able to use all states within a directory
4 participants