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

Inframap not showing all of my resources in graph + square instead of name of resources #112

Open
Nicolasvacher opened this issue Mar 4, 2021 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@Nicolasvacher
Copy link

Nicolasvacher commented Mar 4, 2021

Hi,
Terraform version : 13.5
Os : Alpine Linux
Provider : AWS

I'm executing this command on a tfstate containing a beanstalk env (just then env, not the app, it is already created on AWS) and an RDS database :
inframap generate --tfstate terraformtest.tfstate --clean=false

It's only showing in the graph the RDS, and nothing about the Beanstalk env.

I also have a problem with the graph created using this command :
inframap generate --tfstate terraform.tfstate --clean=false | dot -Tpng > inframap.png

Resulting in this :
image

EDIT : The squares were due to the use of the Alpine OS. Problem found for this one.

Any help would be greatly appreciated :) Thanks !

@xescugc
Copy link
Member

xescugc commented Mar 8, 2021

The squares were due to the use of the Alpine OS. Problem found for this one.

What is/was the main issue? DOT font is not present on AlpineOS? Just to know as it could be ca common usecase to run InfraMap on "minima" setup (like a CI) to generate the graph and could be good to document it or try to find a solution 😄

Ok I would suggest to run inframap generate --tfstate terraform.tfstate --raw which will print what we are reading from the TFState, basically the --raw will not use any kind of logic.

On AWS the connections are detected using security_groups and security_group_rules so those 2 resources should have relations with those.

Also you can run inframap prune --tfstate terraform.tfstate to generate an "anonymized" (if you want even more you can add the --canonicals to it) so then you can send us the tfstate and we can check it without any leaking information. This, ofc, if you want to share it, you are free to look at the output and decide if it has any leaking information :).

@xescugc xescugc self-assigned this Mar 8, 2021
@Nicolasvacher
Copy link
Author

Nicolasvacher commented Mar 9, 2021

What is/was the main issue? DOT font is not present on AlpineOS?

I don't know, I installed graphviz, got dot, but it wasn't writing it correctly, so i tried on a CentOS and it worked.

Ok I would suggest to run inframap generate --tfstate terraform.tfstate --raw

I tried it yes, but ran into an error, something like "graph node already exist" for one of my resources (not AWS but in the same tf code).

On AWS the connections are detected using security_groups and security_group_rules so those 2 resources should have relations with those.

So that's why my PG and NLB are not connected together ?

Of course, how can I send it to you ? Here ? Private ?

Thanks

@xescugc
Copy link
Member

xescugc commented Mar 9, 2021

Of course, how can I send it to you ? Here ? Private ?

Whatever is more confortable for you :) I would prefer it on the issue as with the prune we remove any sensible information (most of the test are real tfstates through the prune) and we keep the one we need.

But if you prefer you can email me :) (info on GH profile 👍 )

Potentially the main issue is that there is no connection between those 2 resources, could you also explain me (in case I don't see anything on the State) what resource should be connecting those 2 elements in your opinion?

Also, if you use more than 1 module on your TFState then #111 could be the issue (for what I see that you say when you use the --raw), if this is the case let's wait until I merge that PR to take a look again :).

@xescugc
Copy link
Member

xescugc commented Mar 9, 2021

Master now has #111 so if you have multiple modules you could try that and could fix your issue :)

@xescugc xescugc added the bug Something isn't working label Mar 9, 2021
@ziyi-bear
Copy link

Hello, I used gitlab-ci, and use the image provide: cycloid/inframap also face this issue

variables:
  INFRAMAP_EXPORT_FILE_PREFIX: "inframap_export_"
  INFRAMAP_EXPORT_FILENAME_STD: "std"
  INFRAMAP_EXPORT_FILENAME_CONNECTIONS: "connections"
  INFRAMAP_EXPORT_FILENAME_RAW: "raw"

terraform-inframap:
  stage: build
  tags:
    - docker
    - linux
  image:
    name: cycloid/inframap
    entrypoint: [""]
  variables:
    INFRAMAP_EXTRA_ARGS: "--hcl --clean=false"
  before_script:
    - export PATH=/app:$PATH
    - inframap version
   
    - apk add graphviz
  script:
    - cd ${TF_ROOT}
    ## https://unix.stackexchange.com/questions/31947/how-to-add-a-newline-to-the-end-of-a-file
    ## add a newline to the end of a file
    - sed -i -e '$a\' *.tf 
    - cat *.tf > temp_inframap.tf

    - cat temp_inframap.tf

    - inframap generate temp_inframap.tf ${INFRAMAP_EXTRA_ARGS} | dot -Tpng > ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_STD}.png

    - inframap generate --connections=false temp_inframap.tf ${INFRAMAP_EXTRA_ARGS} | dot -Tpng > ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_CONNECTIONS}.png

    - inframap generate temp_inframap.tf --raw ${INFRAMAP_EXTRA_ARGS} | dot -Tpng > ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_RAW}.png
  artifacts:
    paths:
      - "temp_inframap.tf"
      - "inframap*.png"
    untracked: false
    expire_in: 90 days

## https://stackoverflow.com/questions/52928915/cant-share-global-variable-value-between-jobs-in-gitlab-ci-yaml-file
terraform-inframap-upload:
  stage: .post
  tags:
    - docker
    - linux
  needs:
    - job: terraform-inframap
      artifacts: true
  image: curlimages/curl
  before_script:
    - curl --version
    - echo "ls:" $(ls -la)
    - echo "Upload inframap std File Name:" ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_STD}
    - echo "Upload inframap connections File Name:" ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_CONNECTIONS}
    - echo "Upload inframap raw File Name:" ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_RAW}
  script:
    - cd ${REPORT_FOLDER} && ls -la 
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" -H "Expect:" --upload-file ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_STD}.png "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/IaC-Report/${CI_COMMIT_REF_NAME}/${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_STD}.png" '
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" -H "Expect:" --upload-file ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_CONNECTIONS}.png "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/IaC-Report/${CI_COMMIT_REF_NAME}/${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_CONNECTIONS}.png" '
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" -H "Expect:" --upload-file ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_RAW}.png "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/IaC-Report/${CI_COMMIT_REF_NAME}/${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_RAW}.png" '

the image generate use the cicd as followed

inframap_export_raw (1)
inframap_export_std (1)
inframap_export_connections (1)

How can i fixed it? thanks

@xescugc
Copy link
Member

xescugc commented May 13, 2022

Hi @ziyi-bear could you send me #112 (comment)?

I may deduce that the resoruce you have we do not support connections for them, right now we'll only display (on AWS) connections by SecurityGroups. So if in you usecase there are not it's better of potentially using the --raw or you could use --connections=false (without the --raw) which will improve a bit the output I think.

@bollohz
Copy link

bollohz commented Jul 26, 2022

Hello there,

I've used successfully Inframap inside a GitLab CI pipeline.
It seems that inside the Alpine Docker image some fonts are missing you can find some details here: https://gitlab.alpinelinux.org/alpine/aports/-/issues/11144

I've added this script inside my CI Pipeline and everything works fine:

  before_script:
    - export PATH=/app:$PATH
    - inframap version
    - apk add graphviz
    - apk add font-bitstream-type1 ghostscript-fonts ttf-cantarell

@xescugc
Copy link
Member

xescugc commented Aug 11, 2022

Ou! Really good find @bollohz hehe

@Nicolasvacher and @ziyi-bear could you test what @bollohz mentioned to see if it works?

I'll also test it on my side with the Docker image and if it fails I think the solution would be for us to add those pkgs on the builded image.

@ziyi-bear
Copy link

Hello there,

I've used successfully Inframap inside a GitLab CI pipeline. It seems that inside the Alpine Docker image some fonts are missing you can find some details here: https://gitlab.alpinelinux.org/alpine/aports/-/issues/11144

I've added this script inside my CI Pipeline and everything works fine:

  before_script:
    - export PATH=/app:$PATH
    - inframap version
    - apk add graphviz
    - apk add font-bitstream-type1 ghostscript-fonts ttf-cantarell

YES I have Test it and this setting works, thanks @bollohz

My Project Output, although the image is a little long
inframap_export_connections (5)

@ziyi-bear
Copy link

Ou! Really good find @bollohz hehe

@Nicolasvacher and @ziyi-bear could you test what @bollohz mentioned to see if it works?

I'll also test it on my side with the Docker image and if it fails I think the solution would be for us to add those pkgs on the builded image.

This is my gitlab ci file: inframap.gitlab-ci.yml

variables:
  INFRAMAP_EXPORT_FILE_PREFIX: "inframap_export_"
  INFRAMAP_EXPORT_FILENAME_STD: "std"
  INFRAMAP_EXPORT_FILENAME_CONNECTIONS: "connections"
  INFRAMAP_EXPORT_FILENAME_RAW: "raw"

terraform-inframap:
  stage: build
  tags:
    - docker
    - linux
  image:
    name: cycloid/inframap
    entrypoint: [""]
  variables:
    INFRAMAP_EXTRA_ARGS: "--hcl --clean=false"
  before_script:
    - export PATH=/app:$PATH
    - inframap version
    - apk add graphviz
    - apk add font-bitstream-type1 ghostscript-fonts ttf-cantarell
  script:
    - cd ${TF_ROOT}
    ## https://unix.stackexchange.com/questions/31947/how-to-add-a-newline-to-the-end-of-a-file
    ## add a newline to the end of a file
    - sed -i -e '$a\' *.tf 
    - cat *.tf > temp_inframap.tf
    - cat temp_inframap.tf
    - inframap generate temp_inframap.tf ${INFRAMAP_EXTRA_ARGS} | dot -Tpng > ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_STD}.png
    - inframap generate --connections=false temp_inframap.tf ${INFRAMAP_EXTRA_ARGS} | dot -Tpng > ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_CONNECTIONS}.png
    - inframap generate temp_inframap.tf --raw ${INFRAMAP_EXTRA_ARGS} | dot -Tpng > ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_RAW}.png
  artifacts:
    paths:
      # - "temp_inframap.tf"
      - "inframap*.png"
    untracked: false
    expire_in: 90 days

## https://stackoverflow.com/questions/52928915/cant-share-global-variable-value-between-jobs-in-gitlab-ci-yaml-file
terraform-inframap-upload:
  stage: .post
  tags:
    - docker
    - linux
  needs:
    - job: terraform-inframap
      artifacts: true
  image: curlimages/curl
  before_script:
    - curl --version
    - echo "ls:" $(ls -la)
    - echo "Upload inframap std File Name:" ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_STD}
    - echo "Upload inframap connections File Name:" ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_CONNECTIONS}
    - echo "Upload inframap raw File Name:" ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_RAW}
  script:
    - cd ${REPORT_FOLDER} && ls -la 
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" -H "Expect:" --upload-file ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_STD}.png "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/IaC-Report/${CI_COMMIT_REF_NAME}/${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_STD}.png" '
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" -H "Expect:" --upload-file ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_CONNECTIONS}.png "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/IaC-Report/${CI_COMMIT_REF_NAME}/${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_CONNECTIONS}.png" '
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" -H "Expect:" --upload-file ${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_RAW}.png "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/IaC-Report/${CI_COMMIT_REF_NAME}/${INFRAMAP_EXPORT_FILE_PREFIX}${INFRAMAP_EXPORT_FILENAME_RAW}.png" '

@xescugc It will generate the image and save to gitlab repo package

image
image

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

No branches or pull requests

4 participants