GoogleCloudPlatform / terraformer

CLI tool to generate terraform files from existing infrastructure (reverse Terraform). Infrastructure to Code
Apache License 2.0
12.09k stars 1.6k forks source link

Importing aws identitystore results in runtime error: index out of range #1891

Open erados opened 3 days ago

erados commented 3 days ago
erados@songmyeong-uui-MacBookPro-2 tf % terraformer import aws --resources=identitystore  --path-pattern="{output}/" --connect=true --regions=us-east-1 --profile=terraform-imdiots
2024/06/28 18:50:31 aws importing region us-east-1
2024/06/28 18:50:32 aws importing... identitystore
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/GoogleCloudPlatform/terraformer/providers/aws.(*IdentityStoreGenerator).GetIdentityStoreId(0x14005944f78?)
        github.com/GoogleCloudPlatform/terraformer/providers/aws/identitystore.go:44 +0x180
github.com/GoogleCloudPlatform/terraformer/providers/aws.(*IdentityStoreGenerator).InitResources(0x0?)
        github.com/GoogleCloudPlatform/terraformer/providers/aws/identitystore.go:169 +0x20
github.com/GoogleCloudPlatform/terraformer/providers/aws.(*AwsFacade).InitResources(0x140008f6aa0?)
        github.com/GoogleCloudPlatform/terraformer/providers/aws/aws_facade.go:61 +0x28
github.com/GoogleCloudPlatform/terraformer/cmd.initServiceResources({_, _}, {_, _}, {{0x140007eb330, 0x1, 0x1}, {0x1163b7300, 0x0, 0x0}, ...}, ...)
        github.com/GoogleCloudPlatform/terraformer/cmd/import.go:209 +0x214
github.com/GoogleCloudPlatform/terraformer/cmd.initAllServicesResources(_, {{0x140007eb330, 0x1, 0x1}, {0x1163b7300, 0x0, 0x0}, {0x16b1d7370, 0x9}, {0x10c8b56d0, ...}, ...}, ...)
        github.com/GoogleCloudPlatform/terraformer/cmd/import.go:166 +0x134
github.com/GoogleCloudPlatform/terraformer/cmd.Import({_, _}, {{0x140007eb330, 0x1, 0x1}, {0x1163b7300, 0x0, 0x0}, {0x16b1d7370, 0x9}, ...}, ...)
        github.com/GoogleCloudPlatform/terraformer/cmd/import.go:98 +0x1a0
github.com/GoogleCloudPlatform/terraformer/cmd.importRegionResources({{0x140007eae10, 0x1, 0x1}, {0x1163b7300, 0x0, 0x0}, {0x16b1d7370, 0x9}, {0x10c8b56d0, 0x9}, ...}, ...)
        github.com/GoogleCloudPlatform/terraformer/cmd/provider_cmd_aws.go:121 +0x260
github.com/GoogleCloudPlatform/terraformer/cmd.newCmdAwsImporter.func1(0x14001293b00?, {0x10c8a95ed?, 0x4?, 0x10c8a95c5?})
        github.com/GoogleCloudPlatform/terraformer/cmd/provider_cmd_aws.go:58 +0x778
github.com/spf13/cobra.(*Command).execute(0x14000e8f080, {0x14000851950, 0x5, 0x5})
        github.com/spf13/cobra@v1.1.1/command.go:850 +0x554
github.com/spf13/cobra.(*Command).ExecuteC(0x14000e8e000)
        github.com/spf13/cobra@v1.1.1/command.go:958 +0x310
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v1.1.1/command.go:895
github.com/GoogleCloudPlatform/terraformer/cmd.Execute()
        github.com/GoogleCloudPlatform/terraformer/cmd/root.go:36 +0x20
main.main()
        github.com/GoogleCloudPlatform/terraformer/main.go:39 +0x50
amine-baaa commented 4 hours ago

It looks like you're running into a runtime error while importing AWS identity store resources with Terraformer. This error appears to stem from the GetIdentityStoreId function trying to access an index that doesn't exist.

  1. Validate Identity Store Configuration: Ensure that your AWS identity store is correctly set up and that the necessary permissions are in place. The error might be caused by an empty response from the AWS API.

  2. Debug Logging: Run Terraformer with increased logging verbosity to get more insights into what's causing the issue.

    TF_LOG=DEBUG terraformer import aws --resources=identitystore --path-pattern="{output}/" --connect=true --regions=us-east-1 --profile=terraform-imdiots
  3. Workaround: As a temporary measure, you might try manually specifying the identity store ID in your Terraformer command if that's an option. This can be done by setting the identity store ID directly in the resource configuration. For example:

    terraformer import aws --resources=identitystore --path-pattern="{output}/" --connect=true --regions=us-east-1 --profile=terraform-imdiots --identitystore-id=<your-identity-store-id>

    Replace <your-identity-store-id> with the actual identity store ID from your AWS account.

Also, it would be helpful if you could provide some additional details about your environment: