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

When I run the terraformer command in my python script for ec2 instance, I am unable to generate the terraform.tfstate file #1874

Closed kavya922 closed 2 months ago

kavya922 commented 2 months ago

Terraform Version Terraformer v0.8.24 Terraform Configuration Files subprocess.run(["terraformer", "import", "aws", "--resources", service, "--regions", region], capture_output=True, shell=True)

Debug Output CompletedProcess(args=['terraformer', 'import', 'aws', '--resources', 'ec2', '--regions', 'us-east-1'], returncode=0, stdout=b'2024/05/01 13:54:48 aws importing region us-east-1\n2024/05/01 13:54:57 aws importing... ec2\n2024/05/01 13:54:57 aws error importing ec2, err: aws: ec2 not supported service\n2024/05/01 13:54:57 aws Connecting.... \n', stderr=b'')

Expected Behavior Should generate the terraform.tfstate file for ec2 instance

Actual Behavior CompletedProcess(args=['terraformer', 'import', 'aws', '--resources', 'ec2', '--regions', 'us-east-1'], returncode=0, stdout=b'2024/05/01 13:54:48 aws importing region us-east-1\n2024/05/01 13:54:57 aws importing... ec2\n2024/05/01 13:54:57 aws error importing ec2, err: aws: ec2 not supported service\n2024/05/01 13:54:57 aws Connecting.... \n', stderr=b'')

Steps to Reproduce terraform init subprocess.run(["terraformer", "import", "aws", "--resources", service, "--regions", region], capture_output=True, shell=True) Additional Context This is the python command I am using to run the terraformer command for ec2 instance subprocess.run(["terraformer", "import", "aws", "--resources", service, "--regions", region], capture_output=True, shell=True)

And the error I am getting is CompletedProcess(args=['terraformer', 'import', 'aws', '--resources', 'ec2', '--regions', 'us-east-1'], returncode=0, stdout=b'2024/05/01 13:54:48 aws importing region us-east-1\n2024/05/01 13:54:57 aws importing... ec2\n2024/05/01 13:54:57 aws error importing ec2, err: aws: ec2 not supported service\n2024/05/01 13:54:57 aws Connecting.... \n', stderr=b'')

I do not understand why it throwing an error : ec2 as a not supported service

The version of terraformer i am using is = Terraformer v0.8.24

Any help is greatly appreciated

Thank you in advance

samuel-casey commented 2 months ago

I had this issue too. You need to use ec2_instance instead of just ec2 as the argument for resources.

The list of aws resource names that terraformer accepts can be found here.

kavya922 commented 2 months ago

@samuel-casey Thanks a lot ! It worked !