Skip to content

Commit

Permalink
Renaming + adding go docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jckuester committed Feb 16, 2021
1 parent be41715 commit 16df612
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ You can download a specific version of awsls on the [releases page](https://gith
install it the following way to `./bin/`:

```bash
curl -sSfL https://raw.githubusercontent.com/jckuester/awsls/master/install.sh | sh -s v0.8.1
curl -sSfL https://raw.githubusercontent.com/jckuester/awsls/master/install.sh | sh -s v0.8.2
```

### Homebrew
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ func mainExitCode() int {

hasAttrs, err := resource.HasAttributes(attributes, rType, &p)
if err != nil {
fmt.Fprint(os.Stderr, color.RedString("Error: failed to check if resource type has attribute: "+
"%s\n", err))
fmt.Fprint(os.Stderr, color.RedString("Error: failed to check if resource type has attribute: %s\n",
err))
return 1
}

Expand Down
28 changes: 15 additions & 13 deletions resource/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ import (
"github.com/jckuester/terradozer/pkg/provider"
)

// UpdatedResources contains resources which Terraform state
// has been updated. Failed updates are logged in the Errors array.
type UpdatedResources struct {
Resources []awsls.Resource
Errors []error
}

// ListInMultipleAccountsAndRegions lists resources of given resource type in parallel
// for multiple accounts and regions.
// ListInMultipleAccountsAndRegions lists resources of a given resource type in parallel for multiple accounts and
// regions and updates the resources' Terraform state.
func ListInMultipleAccountsAndRegions(rType string, hasAttrs map[string]bool,
clients map[aws.ClientKey]awsls.Client, providers map[aws.ClientKey]provider.TerraformProvider) UpdatedResources {
var wg sync.WaitGroup
sem := internal.NewSemaphore(10)

resources := terraform.ResourcesThreadSafe{
result := terraform.ResourcesThreadSafe{
Resources: []awsls.Resource{},
}

Expand All @@ -54,7 +56,7 @@ func ListInMultipleAccountsAndRegions(rType string, hasAttrs map[string]bool,
return
}

res, err := awsls.ListResourcesByType(&client, rType)
resources, err := awsls.ListResourcesByType(&client, rType)
if err != nil {
fmt.Fprint(os.Stderr, color.RedString("Error %s: %s\n", rType, err))
return
Expand All @@ -63,22 +65,22 @@ func ListInMultipleAccountsAndRegions(rType string, hasAttrs map[string]bool,
if len(hasAttrs) > 0 {
// for performance reasons:
// only fetch state if some attributes need to be displayed for this resource type
updatesRes, errs := terraform.UpdateStates(res, providers, 10)
res = updatesRes
updatesResources, errs := terraform.UpdateStates(resources, providers, 10)
resources = updatesResources

resources.Lock()
resources.Errors = append(resources.Errors, errs...)
resources.Unlock()
result.Lock()
result.Errors = append(result.Errors, errs...)
result.Unlock()
}

resources.Lock()
resources.Resources = append(resources.Resources, res...)
resources.Unlock()
result.Lock()
result.Resources = append(result.Resources, resources...)
result.Unlock()
}(client)
}

// Wait until listing resources of this type completes for every account and region
wg.Wait()

return UpdatedResources{resources.Resources, resources.Errors}
return UpdatedResources{result.Resources, result.Errors}
}

0 comments on commit 16df612

Please sign in to comment.