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

Exception thrown in main.py at line 150 #605

Closed
jekwesco opened this issue Mar 17, 2022 · 2 comments
Closed

Exception thrown in main.py at line 150 #605

jekwesco opened this issue Mar 17, 2022 · 2 comments
Assignees
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation
Projects

Comments

@jekwesco
Copy link

Description

Trying to run terraform-compliance GitHub action and getting an exception being thrown. Simple Azure PoC with a simple Terraform config and just trying to use the tests that are in user-friendly-features.

To Reproduce

GitHub Action yaml. Passing in the plan file via upload/download archive.

jobs:
  scan:
    # The type of runner that the job will run on 
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks 
    # that will be executed as part of the job
    steps:
      - name: Download Plan File
        uses: actions/download-artifact@v3
        with:
          name: ${{inputs.plan_to_scan}}
      - name: Show files
        run: |
          pwd
          ls -l    
      - name: terraform-compliance
        uses: terraform-compliance/github_action@main
        with:
          plan: plan.out.json
          features: git:https://github.com/terraform-compliance/user-friendly-features.git

Feature File:

Only using user-friendly-features git repo

Plan File:

{
	"format_version": "1.0",
	"terraform_version": "1.1.7",
	"planned_values": {
		"root_module": {
			"resources": [
				{
					"address": "azurerm_resource_group.example",
					"mode": "managed",
					"type": "azurerm_resource_group",
					"name": "example",
					"provider_name": "registry.terraform.io/hashicorp/azurerm",
					"schema_version": 0,
					"values": {
						"location": "eastus",
						"name": "tf-action-test-delete1",
						"tags": null,
						"timeouts": null
					},
					"sensitive_values": {}
				}
			]
		}
	},
	"resource_drift": [
		{
			"address": "azurerm_resource_group.example",
			"mode": "managed",
			"type": "azurerm_resource_group",
			"name": "example",
			"provider_name": "registry.terraform.io/hashicorp/azurerm",
			"change": {
				"actions": [
					"delete"
				],
				"before": {
					"id": "<removed>/tf-action-test-delete1",
					"location": "eastus",
					"name": "tf-action-test-delete1",
					"tags": null,
					"timeouts": null
				},
				"after": null,
				"after_unknown": {},
				"before_sensitive": {},
				"after_sensitive": false
			}
		}
	],
	"resource_changes": [
		{
			"address": "azurerm_resource_group.example",
			"mode": "managed",
			"type": "azurerm_resource_group",
			"name": "example",
			"provider_name": "registry.terraform.io/hashicorp/azurerm",
			"change": {
				"actions": [
					"create"
				],
				"before": null,
				"after": {
					"location": "eastus",
					"name": "tf-action-test-delete1",
					"tags": null,
					"timeouts": null
				},
				"after_unknown": {
					"id": true
				},
				"before_sensitive": false,
				"after_sensitive": {}
			}
		}
	],
	"configuration": {
		"provider_config": {
			"azurerm": {
				"name": "azurerm",
				"expressions": {
					"features": [
						{}
					]
				}
			}
		},
		"root_module": {
			"resources": [
				{
					"address": "azurerm_resource_group.example",
					"mode": "managed",
					"type": "azurerm_resource_group",
					"name": "example",
					"provider_config_key": "azurerm",
					"expressions": {
						"location": {
							"constant_value": "East US"
						},
						"name": {
							"constant_value": "tf-action-test-delete1"
						}
					},
					"schema_version": 0
				}
			]
		}
	}
}

Sample Terraform Code:

# Create a resource group
resource "azurerm_resource_group" "example" {
  name     = "tf-action-test-delete1"
  location = "East US"
}

terraform {
  #required_providers {
  #azurerm = "~> 2.91.0"
  backend "remote" {
    hostname     = "app.terraform.io"
    organization = "wescodist"

    workspaces {
      name = "devsecops-sandbox"
      #name = "iot-sandbox"
      #prefix = "sp-sandbox"
    }
  }
}


provider "azurerm" {
  features {}
  #skip_provider_registration = "true"
}
}

Used terraform-compliance Parameters:

only -p/-f

Running via Docker:

GitHub Actions

Error Output:

terraform-compliance v1.3.31 initiated

Error in sys.excepthook:
Using remote git repository: git:https://github.com/terraform-compliance/user-friendly-features.git

Features : /home/runner/work/tf-sonarcube-community-edition/tf-sonarcube-community-edition/git:https:/github.com/terraform-compliance/user-friendly-features.git/
Plan File : /home/runner/work/tf-sonarcube-community-edition/tf-sonarcube-community-edition/plan.out.json

  • Running in non-interactive mode.

Running tests.

list index out of range
! ERROR: local variable 'result' referenced before assignment
Traceback (most recent call last):
File "/home/runner/.local/lib/python3.8/site-packages/radish/errororacle.py", line 72, in catch_unhandled_exception
handle_exception(exc_value)
File "/home/runner/.local/lib/python3.8/site-packages/terraform_compliance/extensions/override_radish_hookerrors.py", line 67, in handle_exception
write_failure(Failure(exception))
File "/home/runner/.local/lib/python3.8/site-packages/radish/utils.py", line 39, in init
traceback_info = traceback.extract_tb(sys.exc_info()[2])[-1]
IndexError: list index out of range

Original exception was:
Traceback (most recent call last):
File "/usr/local/bin/terraform-compliance", line 8, in
sys.exit(cli())
File "/home/runner/.local/lib/python3.8/site-packages/terraform_compliance/main.py", line 150, in cli
return result
UnboundLocalError: local variable 'result' referenced before assignment
Error: Process completed with exit code 1.

Expected Behavior:

No exception? :)

Tested Versions:

  • terraform-compliance version: 1.3.31
  • terraform version: 1.1.7
  • python version: 3.8
@jekwesco jekwesco added the bug label Mar 17, 2022
@eerkunt eerkunt added this to To do in Task Queue via automation Mar 21, 2022
@eerkunt eerkunt moved this from To do to Prioritised in Task Queue Mar 21, 2022
@eerkunt
Copy link
Member

eerkunt commented Mar 22, 2022

This problem should be fixed along with #608

@eerkunt eerkunt moved this from Prioritised to In progress in Task Queue Mar 22, 2022
@eerkunt eerkunt added the waiting for confirmation Workaround/Fix applied, waiting for confirmation label Mar 24, 2022
@eerkunt eerkunt moved this from In progress to Released in Task Queue Mar 28, 2022
@jekwesco
Copy link
Author

jekwesco commented May 3, 2022

Hey @eerkunt this seems to be fixed. Sorry for taking so long to verify. Thanks!

@jekwesco jekwesco closed this as completed May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation
Projects
Task Queue
Released
Development

No branches or pull requests

2 participants