Terraform-aws-eks: Cannot Delete Module

Created on 27 Aug 2018  路  7Comments  路  Source: terraform-aws-modules/terraform-aws-eks

I have issues deleting module.

I'm submitting a...

  • [x] bug report
  • [ ] feature request
  • [ ] support request
  • [ ] kudos, thank you, warm fuzzy

What is the current behavior?

I add an EKS Cluster

module "eks" {
  source                = "terraform-aws-modules/eks/aws"
  cluster_name          = "test-eks"
  subnets               = "${module.test_subnets.private_subnets}"
  tags                  = "${map("Environment", "${var.stage}")}"
  vpc_id                = "${module.test_subnets.vpc_id}"
}

it creates a succesful cluster. I remove the above code to delete the cluster and get an error:

Error: module.eks.data.http.workstation_external_ip: configuration for module.eks.provider.http is not present; a provider configuration block is required for all operations

There is no code left from this module, but Terraform won't cleanup after itself properly.

If this is a bug, how to reproduce? Please include a code sample if relevvant.

  • Create a cluster
  • Remove code to delete cluster.

What's the expected behavior?

  • When I remove the code, the instance should be removed.

Are you able to fix this problem and submit a PR? Link here if you have already.

Environment details

  • Affected module version:
  • OS: TFE
  • Terraform version: v0.11.7

Any other relevant info

Most helpful comment

Hi @gb-ckedzierski
I don't think this is a problem with this module, it's common error with terraform 0.11:
https://github.com/hashicorp/terraform/issues/17928
https://github.com/hashicorp/terraform/issues/16824

I think there are 2 ways around it:

  1. Instead of removing the module definition, you can run terraform destroy -target=module.eks`
  2. Just run terraform state rm module.eks.data.http.workstation_external_ip

I usually do option 2.

All 7 comments

Hi @gb-ckedzierski
I don't think this is a problem with this module, it's common error with terraform 0.11:
https://github.com/hashicorp/terraform/issues/17928
https://github.com/hashicorp/terraform/issues/16824

I think there are 2 ways around it:

  1. Instead of removing the module definition, you can run terraform destroy -target=module.eks`
  2. Just run terraform state rm module.eks.data.http.workstation_external_ip

I usually do option 2.

Thanks for your help! This worked deleting those items from the state directly.

Note to future me, these are the things that needed to be deleted

terraform state rm module.eks.null_resource.tags_as_list_of_maps
terraform state rm module.eks.data.template_file.kubeconfig
terraform state rm module.eks.data.http.workstation_external_ip
terraform state rm module.eks.data.template_file.config_map_aws_auth
terraform state rm module.eks.data.template_file.userdata

I wonder if the workaround is to pass modules like recommend in the link issues? I'll test and create a PR if I find anything that could work here. Thanks again for the help!

I had to do this just now. Is this really closed?

@pessoa Yes and no, new issue is opened up here with the real fix to the issue.

I am unable to delete the EKS cluster provsioned with this module.
Here is how I provisioned the EKS cluster.

https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/examples/eks_test_fixture/main.tf

terraform destroy fails
terraform destroy -target=module.eks also fails.

It fails to delete the security group after 10 minutes.
module.eks.aws_security_group.workers: Still destroying... (ID: sg-0f2da422658faa936, 10s elapsed)
Error: Error applying plan:

1 error(s) occurred:

  • module.eks.aws_security_group.workers (destroy): 1 error(s) occurred:

  • aws_security_group.workers: DependencyViolation: resource sg-0f2da422658faa936 has a dependent object
    status code: 400, request id: 5fab7838-61cf-4b1d-8b57-e1cf3360c58a

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

Let me know if anybody has any suggestions for successfully deleting the cluster.

@rajpolaris

If you created any ELBs from k8s, referenced any security groups in other SG rules, enabled scale in protection (or many more things), then this will prevent terraform destroy.

Just do to the AWS console and try to delete the SG sg-0f2da422658faa936 manually and see what the error is.

@rajpolaris add delete_on_termination = true in the network_interfaces part of the aws_launch_template as mentioned here: https://github.com/terraform-providers/terraform-provider-aws/issues/1671#issuecomment-420098531. That worked for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tokiwong picture tokiwong  路  4Comments

mattlawnz picture mattlawnz  路  3Comments

jimmiebtlr picture jimmiebtlr  路  3Comments

maganuk picture maganuk  路  4Comments

discordianfish picture discordianfish  路  4Comments