Terraform AWS Provider - import aws_api_gateway_account - amazon-web-services

When importing aws_api_gateway_account it is not matching the output of “aws apigateway get-account”
The cloudwatchRoleArn is not imported properly. I am using Terraform 1.2.2 and aws provider 4.18.0.
I am importing according to the documentation Terraform Registry
Ex:
terraform import aws_api_gateway_account.rest_api_account api-gateway-account

Related

Unbale to import subnets using google cloud network module

I am trying to manage google cloud infrastructure using terraform modules. We have existing infrastructure I would like to use modules to import them as well.
I got this VPC
name: test-vpc
project: project-1
subnets: subnet-01,subnet-02
I used this google cloud module to import VPC and it worked fine, it imported only vpc but not subnets.
terraform import module.vpc.module.vpc.google_compute_network.network projects/project-1/global/networks/test-vpc
Next, I tried to import the subnet as well using the below command following google and some other documents. Whatever I do I am unable to import the subnet, I saw the subnets module got for and for_each loops, Could someone advise how can I import subnets using gcloud modules?
terraform import module.vpc.module.subnets.google_compute_subnetwork.subnetwork projects/project-1/regions/europe-west3/subnetworks/subnet-01
Thank you
I tried all these commands:
terraform import module.vpc.module.subnets.google_compute_subnetwork.subnetwork projects/project-1/regions/europe-west3/subnetworks/subnet-01
terraform import module.vpc.module.subnets.google_compute_subnetwork.subnetwork[\"subnet-01\"] projects/project-1/regions/europe-west3/subnetworks/subnet-01
terraform import module.vpc.module.subnets.google_compute_subnetwork.subnetwork[\"europe-west3\/subnet-01\"] projects/project-1/regions/europe-west3/subnetworks/subnet-01
I don't see a subnet in the tfstate.

Import terraform AWS VPC subnet having CIDR in resource name

I need to import AWS VPC subnets into terraform using import command. When I run terraform plan command I get below output
module.test-vpc.aws_subnet.play["10.76.175.0/24"]
how do I import this resource as it contains this ["10.76.175.0/24"] cidr block. Below are the command I tried which is failing with this error Error: Invalid number literal
terraform import module.test-vpc.aws_subnet.play[10.76.175.0/24] sub-xyz
I tired below commands that got successful import but unable to recognise resources when I run terraform plan again.
terraform import module.test-vpc.aws_subnet.play sub-xyz
terraform import module.test-vpc.aws_subnet.play[0] sub-xyz
The module probably use a for_each condition, so the right command should be
terraform import module.test-vpc.aws_subnet.play["10.76.175.0/24"] sub-xyz
or
terraform import 'module.test-vpc.aws_subnet.play["10.76.175.0/24"]' sub-xyz
with quotes. Because you reference a resource by the key.
It's also possible to reference the resources by a number that represent the order in the map but is not recommended because it's hard to understand if you are doing the right import.
So, doing the commands
terraform import module.test-vpc.aws_subnet.play sub-xyz
terraform import module.test-vpc.aws_subnet.play[0] sub-xyz
you already imported the resources so you don't see that in plan anymore. You can remove the resource from the state by
terraform state rm module.test-vpc.aws_subnet.play[0]
and re-import the resource

Import Existing AWS CFN Template into AWS CDK for Terraform

I’d like to import an existing CloudFormation template. I came across a tutorial [1] to do this for CloudFormation. I was wondering, is there something similar for Terraform?
[1] Import or migrate an existing AWS CloudFormation template - AWS Cloud Development Kit (CDK)
Sadly, there is not such functionality.

How to use filters in Terraformer for importing AWS Lambda function

I have a lambda named blog-dev-createArticle in us-east-1 region. I am trying to use Terraformer to generate its terraform files.
I am unable to use filters and generate the terraform files for a specific lambda function.
I have tried the following till now but all of them either selects all the lambdas & generates the .tf files for them or selects no lambda at all.
terraformer import aws --resources=lambda --filter="Name=tags.FunctionName;Value=blog-dev-createArticle" --regions=us-east-1
terraformer import aws --resources=lambda --filter="FunctionName=blog-dev-createArticle" --regions=us-east-1
terraformer import aws --resources=lambda --filter="Type=aws_lambda_function;FunctionName=blog-dev-createArticle" --regions=us-east-1
Can someone help me in using filters for AWS Lambda with Terraformer in the right way?
AWS Lambda uses FunctionName as attribute for name whereas terraform uses function_name. So, using function_name as attribute in filter did the trick.
terraformer import aws --resources=lambda --regions=ca-central-1 --filter="Name=function_name;Value=blog-dev-createArticle"

terraform import fargate cluster

I have an existing manually created fargate cluster named "test-cluster" in us-west-1
In terraform configuration file i created
resource "aws_ecs_cluster" "mycluster" {
}
I run terraform command to import the files
terraform import aws_ecs_cluster.mycluster test-cluster
I receive this error message
Error: Cannot import non-existent remote object
While attempting to import an existing object to aws_ecs_cluster.cluster, the
provider detected that no object exists with the given id. Only pre-existing
objects can be imported; check that the id is correct and that it is
associated with the provider's configured region or endpoint, or use
"terraform apply" to create a new remote object for this resource.
I've also ran aws configure adding the correct region.
Based on the comments.
The issue was caused by using wrong account in terraform and/or AWS console.
The solution was to use correct account.