Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to filter one role out of all #410

Open
Tavisca-Praveen-Kumar opened this issue Apr 4, 2024 · 2 comments
Open

to filter one role out of all #410

Tavisca-Praveen-Kumar opened this issue Apr 4, 2024 · 2 comments
Labels
Type: Bug Something isn't working

Comments

@Tavisca-Praveen-Kumar
Copy link

General information:
As per requirement, I just want to import one role out of all the role present in aws account

  • Operating System: Linux
  • Terracognita version / tag: 0.8.4
  • Did you build Terracognita from sources or did you use the Docker image:
    I have build terracognita from source
    Describe the bug:
    sh-4.2$ terracognita aws --module devops --tfstate terraform.tfstate --aws-default-region us-east-1 -i aws_iam_role --tags 'Name:bnr-common-lambda-dynamic-runner-deploy-stack,Product:plt'
    We are about to remove all content from "devops", are you sure? Yes/No (Y/N):
    Y
    Starting Terracognita with version v0.8.4
    Importing with filters:
    Tags: [{Name bnr-common-lambda-dynamic-runner-deploy-stack} {Product plt}],
    Include: [aws_iam_role],
    Exclude: [],
    Targets: [],
    Importing aws_iam_role [5/1540]^C

A clear and concise description of what the bug is.
why it is importing all the roles present in the account. Since I only want to filter on basis of tag attached in it?

@Tavisca-Praveen-Kumar Tavisca-Praveen-Kumar added the Type: Bug Something isn't working label Apr 4, 2024
@Tavisca-shruti-joshi
Copy link

Tavisca-shruti-joshi commented Apr 8, 2024

I am also facing the same issue, the tag filter does not seem to work. It returns all the resources, despite passing the tag. I have double checked the tag key name and its value. Here is my output:

terracognita aws --aws-profile default --module route53record --tags Name:wwwpoc.net --tfstate terraform.tfstate --aws-default-region us-east-1
We are about to remove all content from "route53record", are you sure? Yes/No (Y/N):
Y
Starting Terracognita with version v0.8.4
Importing with filters:
        Tags:    [{Name wwwpoc.net}],
        Include: [],
        Exclude: [],
        Targets: [],
Importing aws_alb_target_group [5/5] Done!
Importing aws_api_gateway_deployment [55/83]^C

If I try to include a certain resource type along with the tags, it says importing 31 resources but gives an empty state file like so:

$ terracognita aws --aws-profile default --module route53record --tags Name:wwwpoc.net --tfstate terraform.tfstate --aws-default-region us-east-1 --include aws_route53_record
We are about to remove all content from "route53record", are you sure? Yes/No (Y/N):
Y
Starting Terracognita with version v0.8.4
Importing with filters:
        Tags:    [{Name wwwpoc.net}],
        Include: [aws_route53_record],
        Exclude: [],
        Targets: [],
Importing aws_route53_record [31/31] Done!
Writing HCL Done!
Writing TFState Done!
sh-4.2$ cat terraform.tfstate
{
  "version": 4,
  "terraform_version": "1.1.9",
  "serial": 0,
  "lineage": "e0041f14-403e-ee66-132a-2a99897dd5be",
  "outputs": {},
  "resources": []
}

@ls-spryker
Copy link

ls-spryker commented Apr 22, 2024

I think it works as intended, just the output is misleading, eg. for lambda, where only one of 32 functions has tag clickops:yes.

terracognita aws --include aws_lambda_function --tfstate temp.json --hcl lambda_generated --tags 'clickops:yes'

terracognita aws --include aws_lambda_function --hcl lambda_generated --tags 'clickops:yes' --tfstate temp.json
We are about to remove all content from "lambda_generated", are you sure? Yes/No (Y/N):
y
Starting Terracognita with version v0.8.4
Importing with filters:
	Tags:    [{clickops yes}],
	Include: [aws_lambda_function],
	Exclude: [],
	Targets: [],
Importing aws_lambda_function [32/32] Done!
Writing HCL Done! 
cat temp.json | jq .resources | jq length
1

grep resource lambda_generated/*.hcl | wc -l 
1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants