hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.81k stars 9.15k forks source link

Synthetics Canary Cleanup #19141

Closed bauteb-sci closed 3 years ago

bauteb-sci commented 3 years ago

Community Note

Description

When creating an aws_synthetics_canary, it automatically creates a lambda function and lambda layer for the source code. When you destroy the canary resource, those lambda resources are left behind. Please enhance the removal process to also destroy those resources.

New or Affected Resource(s)

Potential Terraform Configuration

resource "aws_synthetics_canary" "canary-monitor" {
  name                 = var.canary_name
  handler              = "${var.handler_name}.handler"
  start_canary       = var.start_canary
  artifact_s3_location = var.artifact_s3_location
  execution_role_arn  = var.synthetics_exec_role
  runtime_version      = var.runtime_version
  s3_bucket          = var.synthetics_bucket_name
  s3_key               = aws_s3_bucket_object.canary-source-zip.key
  s3_version         = aws_s3_bucket_object.canary-source-zip.version_id
  schedule {
    expression = var.schedule_expression
  }
  run_config {
    timeout_in_seconds = var.run_timeout
  }
}

Thanks!

gdavison commented 3 years ago

Thanks, @bauteb-sci, this would be very useful for a lot of users. When developing the AWS provider, we follow the AWS API fairly closely, and the API doesn't provide specific calls to clean up after a Canary after it's deleted. The AWS documentation advises users to manually clean up after deleting a Canary https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/synthetics_canaries_deletion.html

One potential workaround to this is to use terraform import to bring the extra resources under Terraform management after AWS has created them.

github-actions[bot] commented 3 years ago

I'm going to lock this issue because it has been closed for 30 days ā³. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.