puppetlabs / puppetlabs-pecdm

Puppet Bolt driven fusion of puppetlabs/peadm and Terraform.
Apache License 2.0
14 stars 18 forks source link

pecdm::destroy on aws failing with aws_vpc.pe is empty tuple #98

Closed jessereynolds closed 1 year ago

jessereynolds commented 1 year ago

Describe the Bug

Attempting to destroy the infra on aws is failing for me as follows:

% bolt plan run pecdm::destroy provider=aws
Starting: plan pecdm::destroy
Starting: plan pecdm::subplans::destroy
Destroying Puppet Enterprise deployment on aws
Starting: task terraform::initialize on localhost
Finished: task terraform::initialize with 0 failures in 0.16 sec
Starting: plan terraform::destroy
Starting: task terraform::destroy on localhost
Finished: task terraform::destroy with 1 failure in 7.1 sec
Finished: plan terraform::destroy in 7.1 sec
Finished: plan pecdm::subplans::destroy in 8.12 sec
Finished: plan pecdm::destroy in 8.13 sec
Failed on localhost:

  Error: Error in function call

    on modules/networking/main.tf line 7, in locals:
     7:   vpc_id        = try(aws_vpc.pe[0].id, data.aws_vpc.existing[0].id)
      ├────────────────
      │ while calling try(expressions...)
      │ aws_vpc.pe is empty tuple
      │ data.aws_vpc.existing is empty tuple

  Call to function "try" failed: no expression succeeded:
  - Invalid index (at modules/networking/main.tf:7,33-36)
    The given key does not identify an element in this collection value: the collection has no elements.
  - Invalid index (at modules/networking/main.tf:7,62-65)
    The given key does not identify an element in this collection value: the collection has no elements.

  At least one expression must produce a successful result.
Failed on 1 target: localhost
Ran on 1 target

line 7 of modules/networking/main.tf is the vpc_id assignment line in the following:

# To contain each PE deployment, a fresh VPC to deploy into
locals {
  name_tag = {
    Name = "pe-${var.id}"
  }
  network_count = var.to_create ? 1 : 0
  vpc_id        = try(aws_vpc.pe[0].id, data.aws_vpc.existing[0].id)
  subnet_ids    = coalescelist(aws_subnet.pe_subnet[*].id, data.aws_subnet.existing[*].id)
}

Expected Behavior

The destroy plan should destroy any remaining infrastructure that was created by the project.

Steps to Reproduce

Build the infrastructure as per https://github.com/puppetlabs/puppetlabs-pecdm/issues/97 (note there have been subsequent reprovision and deletion attempts)

Attempt to destroy the infrastructure using the plan, or terraform destroy directly.

timidri commented 1 year ago

@jessereynolds I can destroy a cluster in a non-default region by running this command:

bolt plan run pecdm::destroy provider=aws cloud_region=eu-central-1 

So I also explicitly pass the region. Can you try this and confirm that that is working for you?