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

bug(terraform): merge with object changes input for kics #7196

Open
granular-ryanbonham opened this issue Jul 14, 2024 · 1 comment
Open
Labels
aws PR related with AWS Cloud bug Something isn't working community Community contribution terraform Terraform query

Comments

@granular-ryanbonham
Copy link

Having a merge() which contains an inline defined object seems to change the output of locals from ${local.common_tags} in the universal json format to local.common_tags.

Expected Behavior

Parsing scanning this terraform file

provider "aws" {
  region = var.REGION
  default_tags {
    tags = local.common_tags
  }
}

Generates this json which contains the expected result of "tags": "${local.common_tags}"

{
	"document": [
		{
			"id": "d336f75d-98b9-4223-890c-96f53fade0a0",
			"provider": {
				"aws": {
					"default_tags": {
						"tags": "${local.common_tags}"
					},
					"region": "${var.REGION}"
				}
			},
			"file": "/path/provider.tf"
		}
	]
}

(Which results are expected from KICS?)

Actual Behavior

Now we add a second tf file with a resource which contains a merge() of our local with another object..

provider.tf

provider "aws" {
  region = var.REGION
  default_tags {
    tags = local.common_tags
  }
}

main.tf

resource "aws_security_group" "bastion" {
  name_prefix = "bastion-"
  vpc_id      = data.terraform_remote_state.scheduler.outputs.vpc_id

  tags = merge(
    local.common_tags,
    {
      Customer_Facing = "no"
      Name            = "bastion"
    }
  )
}

Note the json now says "tags": "local.common_tags" for the provider's default_tags, which is not expected.

{
	"document": [
		{
			"id": "60a116ce-2924-4d6c-b6e8-378e9f52e0b3",
			"resource": {
				"aws_security_group": {
					"bastion": {
						"name_prefix": "bastion-",
						"tags": "${merge(\n    local.common_tags,\n    {\n      Customer_Facing = \"no\"\n      Name            = \"bastion\"\n    }\n  )}",
						"vpc_id": "${data.terraform_remote_state.scheduler.outputs.vpc_id}"
					}
				}
			},
			"file": "/path/main.tf"
		},
		{
			"file": "/path/provider.tf",
			"id": "3a1cbbab-6c48-403d-ad99-880ccf5662cc",
			"provider": {
				"aws": {
					"default_tags": {
						"tags": "local.common_tags"
					},
					"region": "${var.REGION}"
				}
			}
		}
	]
}

Testing has shows this is occurs when the merge() is present. It also must be in a second file, if the resource and the provider block are in the same file this doesn't occur.

@granular-ryanbonham granular-ryanbonham added bug Something isn't working community Community contribution labels Jul 14, 2024
@github-actions github-actions bot added terraform Terraform query aws PR related with AWS Cloud labels Jul 14, 2024
@granular-ryanbonham granular-ryanbonham changed the title bug(Terraform): Merge with object changes input for kics bug(Terraform): merge with object changes input for kics Jul 14, 2024
@granular-ryanbonham granular-ryanbonham changed the title bug(Terraform): merge with object changes input for kics bug(terraform): merge with object changes input for kics Jul 14, 2024
@cx-monicac
Copy link
Collaborator

Hi @granular-ryanbonham ,

Thank you for bringing this bug to our attention we opened an internal bug and will work on it as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws PR related with AWS Cloud bug Something isn't working community Community contribution terraform Terraform query
Projects
None yet
Development

No branches or pull requests

2 participants