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

Cannot Destroy - Packer AWS Query Returns No Results On Existing AR #884

Open
ivang-coder opened this issue Mar 6, 2024 · 1 comment
Open

Comments

@ivang-coder
Copy link

Hi Team,

Issue Description
While using AR Docker on Macbook Air M2 and successfully deploying Attack Range on a standalone AWS, we're having issues destroying that AR environment by using the standard command python attack_range.py destroy, see the log output below.

Meanwhile, there are no issues with AWS Account access and the standard commands with actions like "build", "stop", "resume" and "show" run successfully.

Log output of the command python attack_range.py destroy

(attack-range-py3.10) root@da518bbc86a1:/attack_range# python attack_range.py destroy
...
module.networkModule.module.vpc.aws_route_table_association.public[0]: Refreshing state... [id=rtbassoc-055542d5bc6b8d3cc]
╷
│ Error: Your query returned no results. Please change your search criteria and try again.
│ 
│   with module.linux-server.data.aws_ami.linux_server_packer[0],
│   on modules/linux-server/resources.tf line 2, in data "aws_ami" "linux_server_packer":
│    2: data "aws_ami" "linux_server_packer" {
│ 
╵
╷
│ Error: Your query returned no results. Please change your search criteria and try again.
│ 
│   with module.nginx-server.data.aws_ami.nginx_server_packer[0],
│   on modules/nginx-server/resources.tf line 3, in data "aws_ami" "nginx_server_packer":
│    3: data "aws_ami" "nginx_server_packer" {
│ 
╵
╷
│ Error: Your query returned no results. Please change your search criteria and try again.
│ 
│   with module.splunk-server.data.aws_ami.splunk_server_packer[0],
│   on modules/splunk-server/resources.tf line 3, in data "aws_ami" "splunk_server_packer":
│    3: data "aws_ami" "splunk_server_packer" {
│ 
╵
╷
│ Error: Your query returned no results. Please change your search criteria and try again.
│ 
│   with module.windows-server.data.aws_ami.windows_ami_packer[1],
│   on modules/windows/resources.tf line 5, in data "aws_ami" "windows_ami_packer":
│    5: data "aws_ami" "windows_ami_packer" {
│ 
╵
╷
│ Error: Your query returned no results. Please change your search criteria and try again.
│ 
│   with module.windows-server.data.aws_ami.windows_ami_packer[0],
│   on modules/windows/resources.tf line 5, in data "aws_ami" "windows_ami_packer":
│    5: data "aws_ami" "windows_ami_packer" {
│ 
╵

Could you advise how to resolve this issue, please?

@ivang-coder
Copy link
Author

A solution (more like a workaround) has been found.

Solution Summary

By replacing the "aws_ami" data source with "aws_ami_ids" and commenting the "most_recent = true" statement out, Terraform is now able to complete the playrun invoked by python attack_range.py destroycommand.

Solution Details

To replicate the solution, amend the tf files as per below

vi terraform/aws/modules/linux-server/resources.tf

line 2, data "aws_ami_ids" "linux_server_packer" {
line 4, # most_recent = true #(line commented)
line 13 data "aws_ami_ids" "linux_server" {
line 15 # most_recent = true #(line commented)
line 31, ami = var.general.use_prebuilt_images_with_packer == "1" ? data.aws_ami_ids.linux_server_packer[count.index].id : data.aws_ami_ids.linux_server[count.index].id

vi terraform/aws/modules/nginx-server/resources.tf

line 3, data "aws_ami_ids" "nginx_server_packer" {
line 5, # most_recent = true #(line commented)
line 14 data "aws_ami_ids" "nginx_server" {
line 16 # most_recent = true #(line commented)
line 32, ami = var.general.use_prebuilt_images_with_packer == "1" ? data.aws_ami_ids.nginx_server_packer[0].id : data.aws_ami_ids.nginx_server[0].id

vi terraform/aws/modules/splunk-server/resources.tf

line 3, data "aws_ami_ids" "splunk_server_packer" {
line 5, # most_recent = true #(line commented)
line 14, data "aws_ami_ids" "splunk_server" {
line 16, # most_recent = true #(line commented)
line 91, ami = var.general.use_prebuilt_images_with_packer == "1" ? data.aws_ami_ids.splunk_server_packer[0].id : data.aws_ami_ids.splunk_server[0].id

vi terraform/aws/modules/windows/resources.tf

line 5, data "aws_ami_ids" "windows_ami_packer" {
line 7, # most_recent = true #(line commented)
line 16, data "aws_ami_ids" "windows_ami" {
line 18, # most_recent = true #(line commented)
line 35, ami = var.general.use_prebuilt_images_with_packer == "1" ? data.aws_ami_ids.windows_ami_packer[count.index].id : data.aws_ami_ids.windows_ami[count.index].id

Team, can you see if the workaround can be considered a solution and a candidate for the merge request?

Regards,
Ivan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant