GoogleCloudPlatform / terraformer

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

Errors in multi region AWS resources import #1887

Closed dkislov closed 2 weeks ago

dkislov commented 3 months ago

When running "terraformer import aws..." with multiple regions in the --regions option, errors are generated on the second region resources import:

ERROR: Read resource response is null for resource ERROR: Unable to refresh resource

That is happening because of the caching of configuration in provider/aws/aws_service.go:

in
func (s *AWSService) generateConfig() (aws.Config, error) there is piece of code:

if configCache != nil { return *configCache, nil }

amine-baaa commented 3 months ago

A quick workaround that helped me was to clear the config cache explicitly before initiating the import for each region. You can achieve this by modifying the aws_service.go file to reset the configCache at the start of the generateConfig function.

Here's a brief patch that you might find useful:

func (s *AWSService) generateConfig() (aws.Config, error) {
    // Clear the cache to ensure a fresh config is generated for each region
    configCache = nil

    if configCache != nil {
        return *configCache, nil
    }
    ...
}

This change forces Terraformer to generate a new configuration for each region, which should prevent the errors you’re seeing.

If you're not comfortable modifying the source code directly, you might want to split your imports by region and run them sequentially in separate commands:

terraformer import aws --resources=identitystore --regions=us-east-1 --profile=terraform-imdiots
terraformer import aws --resources=identitystore --regions=us-west-1 --profile=terraform-imdiots
github-actions[bot] commented 3 weeks ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 2 weeks ago

This issue was closed because it has been stalled for 7 days with no activity.