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.86k stars 9.2k forks source link

[Bug]: Can't use resources representing Backup Vaults created by AWS for automatic backups #28126

Open gimbo opened 1 year ago

gimbo commented 1 year ago

Terraform Core Version

1.3.5

AWS Provider Version

4.41.0

Affected Resource(s)

I suspect similar issues may affect other resources, e.g. and in particular aws_backup_plan — but I haven't tested that.

Expected Behavior

I should be able to import any existing Backup Vault into terraform state and use it as normal.

Actual Behavior

Some Backup Vaults created automatically by AWS have names which contain / characters (which are normally prohibited). E.g. when "automatic backups" are enabled on some EFS volume, AWS created a backup vault called aws/efs/automatic-backup-vault.

The aws_backup_vault resource doesn't allow / characters in their names (and again, that's normally the right thing to do because end users can't create such vaults). As such, while I can create a resource for that vault and import its state, I cannot then plan or apply vs that resource without changing its name (which I suspect is not possible anyway for these automatically-created vaults, which also seem to be not deletable).

Relevant Error/Panic Output Snippet

$ terraform import aws_backup_vault.efs_automatic 'aws/efs/automatic-backup-vault'
...
aws_backup_vault.efs_automatic: Importing from ID "aws/efs/automatic-backup-vault"...
aws_backup_vault.efs_automatic: Import prepared!
  Prepared aws_backup_vault for import
...

Import successful!

...

$ terraform plan
╷
│ Error: invalid value for name (must consist of letters, numbers, and hyphens.)
│
│   with aws_backup_vault.efs_automatic,
│   on backup.tf line 10, in resource "aws_backup_vault" "efs_automatic":
│   10:   name        = "aws/efs/automatic-backup-vault"
│

Terraform Configuration Files

data "aws_kms_key" "aws_backup" {
  key_id = "alias/aws/backup"
}

resource "aws_backup_vault" "efs_automatic" {
  name        = "aws/efs/automatic-backup-vault"
  kms_key_arn = data.aws_kms_key.aws_backup.arn
}

Steps to Reproduce

  1. Create an EFS volume and enable automatic backups (e.g. I used an aws_efs_backup_policy resource).
  2. Verify that a Backup Vault called aws/efs/automatic-backup-vault has been created.
  3. Create a terraform configuration containing an aws_backup_vault resource with that name.
  4. Import the resource (this works).
  5. terraform plan (this fails).

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

No

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

burner1024 commented 1 month ago

Same for aws_backup_plan, aws_backup_plan/rule, aws_backup_selection. If there's any other resources in Backup, likely those too.