https://infracost.io logo
#help
Title
# help
p

proud-wolf-89343

06/16/2023, 2:11 PM
I'm using `infracost-atlantis`: Is there a method, similar to
TF_ROOT
, which causes infracost to ignore all pull requests that do not change any terraform code? Currently our pipelines are blocked, because infracost searches for breakdown files in pull requests, where they are never generated, because atlantis ignores the pull request
l

little-author-61621

06/16/2023, 2:35 PM
@proud-wolf-89343 what does your current pipeline look like? By breakdown files are you meaning
$SHOWFILE
?
p

proud-wolf-89343

06/16/2023, 2:42 PM
I do believe it's the
$SHOWFILE
that isn't (rightfully) generated
Copy code
ATLANTIS_REPO_CONFIG_JSON: >                                                                                                                                                                         
        {                                                                                  
          "repos":[                                                                        
            {                                                                              
              "id": "/.*/",                                                                
              "branch": "/master/",                                                        
              "apply_requirements": [                                                      
                "approved",                                                                
                "mergeable",                                                               
                "undiverged"                                                               
              ],                                                                           
              "delete_source_branch_on_merge": true,                                       
              "workflow": "terraform-infracost",                                           
              "pre_workflow_hooks": [                                                      
                {                                                                          
                  "run": "rm -rf /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM"          
                },                                                                         
                {                                                                          
                  "run": "mkdir -p /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM"        
                }                                                                          
              ],                                                                           
              "post_workflow_hooks": [                                                     
                {                                                                          
                  "run": "infracost comment gitlab --repo $BASE_REPO_OWNER/$BASE_REPO_NAME --merge-request $PULL_NUM --path /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM/'*'-infracost.json --gitlab-token $GITLAB_TOKEN --behavior new"
                },                                                                      
                {                                                                       
                  "run": "rm -rf /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM"       
                }                                                                       
              ]                                                                         
            }                                                                           
          ],                                                                            
          "workflows": {                                                                
            "terraform-infracost": {                                                    
              "plan": {                                                                 
                "steps": [                                                              
                  {                                                                     
                    "env": {                                                               
                      "name": "INFRACOST_OUTPUT",                                          
                      "command": "echo /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM/$WORKSPACE-${REPO_REL_DIR//\//-}-infracost.json"
                    }                                                                   
                  },                                                                    
                  "init",                                                               
                  "plan",                                                               
                  "show",                                                                  
                 {                                                                         
                   "run": "infracost breakdown --path=$SHOWFILE --format=json --log-level=info --out-file=$INFRACOST_OUTPUT --project-name=$REPO_REL_DIR"
                 }                                                                      
                ]                                                                       
              }                                                                         
            }                                                                           
          }
l

little-author-61621

06/16/2023, 2:54 PM
And how does Atlantis ignore the PR currently? My knowledge of Atlantis pipelines isn’t super great, but this looks like the infracost workflow only runs if a plan is run anyway. If the $SHOWFILE doesn’t exist for any reason though maybe we can add a step to exit the workflow early in that case
p

proud-wolf-89343

06/16/2023, 3:08 PM
There is an atlantis.yaml file, which conatins a "when-changed" statement. Thanks for the tip on "Early exit". I'll take it up monday once I'm back to work
l

little-author-61621

06/16/2023, 3:10 PM
Great! also @proud-wolf-89343 our native GitLab App by default runs on only changed terraform files and works alongside Atlantis if that’s interesting: https://www.infracost.io/docs/integrations/gitlab_app/
10 Views