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.8k stars 9.15k forks source link

resource/aws_acmpca_certificate: If ACM PCA CA is in invalid state, reading certificate fails #26968

Open gdavison opened 2 years ago

gdavison commented 2 years ago

Terraform Core Version

1.2.9

AWS Provider Version

4.32.0,4.29.0

Affected Resource(s)

Expected Behavior

The provider should ignore the error and remove the aws_acmpca_certificate from state

Actual Behavior

On update, if an ACM PCA CA with previously issued aws_acmpca_certificate and aws_acmpca_certificate_authority_certificate is now in an invalid state, e.g. DELETED, reading the aws_acmpca_certificate will fail with the error:

Error: error reading ACM PCA Certificate (arn:aws:acm-pca:us-west-2:123456789012:certificate-authority//certificate/): InvalidStateException: The certificate authority arn:aws:acm-pca:us-west-2: 123456789012:certificate-authority/**** is not in the correct state to have issued certificates.

Reading the aws_acmpca_certificate_authority_certificate will fail with the error:

Error: error reading ACM PCA Certificate Authority Certificate (arn:aws:acm-pca:us-west-2: 123456789012:certificate-authority/): InvalidStateException: The certificate authority arn:aws:acm-pca:us-west-2: 123456789012:certificate-authority/ is not in the correct state to have a certificate signing request

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_acmpca_certificate_authority" "test" { permanent_deletion_time_in_days = 7 type = "ROOT"

certificate_authority_configuration { key_algorithm = "RSA_4096" signing_algorithm = "SHA512WITHRSA"

subject {
  common_name = "private-certificate.test"
}

} }

resource "aws_acmpca_certificate" "test" { certificate_authority_arn = aws_acmpca_certificate_authority.test.arn certificate_signing_request = aws_acmpca_certificate_authority.test.certificate_signing_request signing_algorithm = "SHA512WITHRSA"

template_arn = "arn:${data.aws_partition.current.partition}:acm-pca:::template/RootCACertificate/V1"

validity { type = "YEARS" value = 2 } }

resource "aws_acmpca_certificate_authority_certificate" "test" { certificate_authority_arn = aws_acmpca_certificate_authority.test.arn

certificate = aws_acmpca_certificate.test.certificate certificate_chain = aws_acmpca_certificate.test.certificate_chain }

data "aws_partition" "current" {}

Steps to Reproduce

  1. apply the configuration
  2. delete the CA
  3. plan

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

No response

github-actions[bot] commented 2 years ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

BryanStenson-okta commented 1 year ago

I'd suggest the desired effect is that the provider un-deletes and re-enables the PCA.