Skip to content

Commit 90874b6

Browse files
Merge pull request #1692 from snyk/IAC-2657/remove-deep-mode
Remove deep mode
2 parents 82ddf50 + 26ffd12 commit 90874b6

File tree

259 files changed

+3071
-5274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

259 files changed

+3071
-5274
lines changed

.gitleaksignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,13 @@ ff72de8e77f908fba61df50bc0938744270d1b51:pkg/remote/aws/test/iam_role_multiple/r
281281
ff72de8e77f908fba61df50bc0938744270d1b51:pkg/remote/aws/test/iam_user_multiple/results.golden.json:aws-access-token:12
282282
ff72de8e77f908fba61df50bc0938744270d1b51:pkg/remote/aws/test/iam_user_multiple/results.golden.json:aws-access-token:24
283283
ff72de8e77f908fba61df50bc0938744270d1b51:pkg/remote/aws/test/iam_user_multiple/results.golden.json:aws-access-token:36
284+
20e6356a49e6dd18f00cd6c36b735ef1a850ac55:enumeration/remote/aws_iam_scanner_test.go:aws-access-token:823
285+
20e6356a49e6dd18f00cd6c36b735ef1a850ac55:enumeration/remote/aws_iam_scanner_test.go:aws-access-token:826
286+
651ab697db3ff60ba195c22dc0570d1204a97f7e:enumeration/remote/aws_iam_scanner_test.go:aws-access-token:823
287+
651ab697db3ff60ba195c22dc0570d1204a97f7e:enumeration/remote/aws_iam_scanner_test.go:aws-access-token:826
288+
6cf09f996d8637c30ad06884a450ff66920d9798:enumeration/remote/aws_iam_scanner_test.go:aws-access-token:823
289+
6cf09f996d8637c30ad06884a450ff66920d9798:enumeration/remote/aws_iam_scanner_test.go:aws-access-token:826
290+
6d204a7f446251a3c1519bfc4b80599529eec279:enumeration/remote/aws_iam_scanner_test.go:aws-access-token:823
291+
6d204a7f446251a3c1519bfc4b80599529eec279:enumeration/remote/aws_iam_scanner_test.go:aws-access-token:826
292+
40f68d61a91d8c10c09e43263cbd36b380cca90a:enumeration/remote/aws_iam_scanner_test.go:aws-access-token:823
293+
40f68d61a91d8c10c09e43263cbd36b380cca90a:enumeration/remote/aws_iam_scanner_test.go:aws-access-token:826

.snyk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,9 @@ ignore:
8585
- '*':
8686
reason: This license is addressed by including acknowledgments in each release
8787
created: 2022-09-09T14:25:05.042Z
88+
SNYK-GOLANG-GOLANGORGXNETHTTP2-5953327:
89+
- '*':
90+
reason: Not affected because CLI
91+
expires: 2024-04-15T15:15:28.330Z
92+
created: 2023-10-16T15:15:28.356Z
8893
patch: {}

docs/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ Resource listing is done using cloud providers SDK. Resource details retrieval i
1717
- `Remote` is a representation of a cloud provider
1818
- `Resource` is an abstract representation of a cloud provider resource (e.g. S3 bucket, EC2 instance, etc ...)
1919
- `Enumerator` is used to list resources of a given type from a given remote and return a resource list, it should exist only one Enumerator per resource
20-
- `DetailsFetcher` is used to retrieve resource's details of a given type, this is an optional layer and is used only in deep mode.

docs/media/generalflow.png

-5.13 KB
Loading

docs/media/resource.png

-29.9 KB
Loading

docs/media/resource.puml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,5 @@ RemoteSDK --> Enumerator: Attrs
1212
end
1313
Enumerator --> Scanner: []Resource with limited attributes
1414
end
15-
alt if deep mode enabled
16-
hnote across: Details fetching phase
17-
loop for each enumerated resource
18-
Scanner -> DetailsFetcher: ReadDetails(res)
19-
DetailsFetcher -> TerraformProvider: ReadResource()
20-
TerraformProvider --> DetailsFetcher: CTYValue
21-
DetailsFetcher -> Deserializer: Deserialize()
22-
Deserializer -> DetailsFetcher: Resource
23-
DetailsFetcher -> Scanner: Resource with\nfull attributes
24-
end
25-
end
2615
Scanner --> driftctl: []Resource
27-
@enduml
16+
@enduml

docs/new-resource.md

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,12 @@ Then, you'll find below a more detailed flow of how we handle the enumeration an
1313
First step would be to add a file called `pkg/resource/<providername>/<resourcetype>.go`.
1414
This file will define a string constant that will be the resource type identifier in driftctl.
1515

16-
Optionally, if your resource is to be supported by driftctl experimental deep mode, you can add a function that will be applied to this resource at creation.
17-
This allows to prevent useless diffs to be displayed.
18-
You can also add metadata to fields so that they are compared or displayed differently.
19-
2016
For example this defines the `aws_iam_role` resource:
2117

2218
```go
2319
const AwsIamRoleResourceType = "aws_iam_role"
2420

2521
func initAwsIAMRoleMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) {
26-
// assume_role_policy drifts will be displayed as json
27-
resourceSchemaRepository.UpdateSchema(AwsIamRoleResourceType, map[string]func(attributeSchema *resource.AttributeSchema){
28-
"assume_role_policy": func(attributeSchema *resource.AttributeSchema) {
29-
attributeSchema.JsonString = true
30-
},
31-
})
3222
// force_detach_policies should not be compared so it will be removed before the comparison
3323
resourceSchemaRepository.SetNormalizeFunc(AwsIamRoleResourceType, func(res *resource.Resource) {
3424
val := res.Attrs
@@ -57,17 +47,12 @@ var supportedTypes = map[string]struct{}{
5747
All resources inside driftctl are `resource.Resource` structs.
5848
All the other attributes are represented inside a `map[string]interface`
5949

60-
## Repository, Enumerator and DetailsFetcher
50+
## Repository, Enumerator
6151

62-
Then you will have to implement two interfaces:
52+
Then you will have to implement one interface:
6353

6454
- Repositories are the way we decided to hide direct calls to SDK and pagination logic. It's a common abstraction pattern for data retrieval.
6555
- `remote.common.Enumerator` is used to enumerate resources. It will call the cloud provider SDK to get the list of resources.
66-
For some resource it could make other call to enrich the resource with additional attributes when driftctl is used in deep mode
67-
- `remote.common.DetailsFetcher` is used to retrieve resource's details. It makes a call to Terraform provider `ReadResource`.
68-
This implementation is optional and is only needed if your resource type is to be supported by experimental deep mode.
69-
Please also note that it exists a generic implementation called `remote.common.GenericDetailsFetcher` that can be used with most resource types.
70-
7156

7257
### Repository
7358

@@ -126,7 +111,6 @@ Most of the resource returned by enumerator have empty attributes: they only rep
126111

127112
**There are exceptions to this**:
128113
- Sometimes, you will need more information about resources for them to be fetched in the `DetailsFetcher`. For those cases, you will add specific attributes to the map of data.
129-
- For complex cases (e.g. middlewares) where you would need driftctl to run as expected in deep and non-deep mode, you would need to enumerate resources as well as to fetch manually specific attributes, using the remote SDK, before adding them to the map of data.
130114

131115
You can use an already implemented Enumerator as example.
132116

@@ -192,26 +176,3 @@ Once the enumerator is written you have to add it to the remote initialization l
192176
```go
193177
remoteLibrary.AddEnumerator(NewEC2InstanceEnumerator(s3Repository, factory))
194178
```
195-
196-
### DetailsFetcher
197-
198-
DetailsFetchers are only used by driftctl experimental deep mode.
199-
200-
This is the component that call Terraform provider to retrieve all attributes for each resource.
201-
We do not want to reimplement what has already been done in each Terraform provider. Thus, you should not call the remote SDK there.
202-
203-
If `common.GenericDetailsFetcher` satisfies your needs you should always prefer using it instead of implementing a custom `DetailsFetcher` in a new struct.
204-
205-
The `DetailsFetcher` should also be added to `pkg/remote/<providername>/init.go` even if you use the generic version:
206-
207-
```go
208-
remoteLibrary.AddDetailsFetcher(aws.AwsEbsVolumeResourceType, common.NewGenericDetailsFetcher(aws.AwsEbsVolumeResourceType, provider, deserializer))
209-
```
210-
211-
***Don't forget to add unit tests after adding a new resource.***
212-
213-
You can find example of **functional tests** in `pkg/remote/<type>_scanner_test.go`.
214-
215-
You should also add **acceptance tests** if you think it makes sense. They are located next to the resource definition described in the first step.
216-
217-
More information about adding tests can be found in [testing documentation](testing.md)

0 commit comments

Comments
 (0)