From 0c5463f8ab110741e035cdfe9e3e9908c9026373 Mon Sep 17 00:00:00 2001 From: xescugc Date: Fri, 29 May 2020 10:38:31 +0200 Subject: [PATCH] aws/resources: Befor importing 'aws_iam_user_group_membership' check grups names If there is no groups we cannot import this resources so we should skip it --- CHANGELOG.md | 5 +++++ aws/resources.go | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4881df3649..1ab2493734 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ - Provide filters to resource functions instead of tags only ([PR #92](https://github.com/cycloidio/terracognita/pull/92)) +## Fixed + +- Error when importing `aws_iam_user_group_membership` without groups + ([Issue #104](https://github.com/cycloidio/terracognita/issues/104)) + ## [0.4.0] _2020-03-31_ ### Added diff --git a/aws/resources.go b/aws/resources.go index 2a6ac8e163..e677be4506 100644 --- a/aws/resources.go +++ b/aws/resources.go @@ -1092,8 +1092,14 @@ func iamUserGroupMemberships(ctx context.Context, a *aws, resourceType string, f if err != nil { return nil, err } - resources := make([]provider.Resource, 0) + + // If the user has no Groups then we do not need to proceed + // or TF will return an error of malformed ID + if len(groupNames) == 0 { + return resources, nil + } + for _, un := range userNames { // The format expected by TF is //... r, err := initializeResource(a, strings.Join(append([]string{un}, groupNames...), "/"), resourceType)