-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17850 from hashicorp/acmpca-private-cert
ACM PCA: add resource to issue certificates from private CA and import CA certificates
- Loading branch information
Showing
24 changed files
with
1,797 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```release-note:new-resource | ||
aws_acmpca_certificate | ||
``` | ||
|
||
```release-note:new-data-source | ||
aws_acmpca_certificate | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
aws_acmpca_certificate_authority_certificate | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/acmpca" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceAwsAcmpcaCertificate() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsAcmpcaCertificateRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validateArn, | ||
}, | ||
"certificate_authority_arn": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validateArn, | ||
}, | ||
"certificate": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"certificate_chain": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsAcmpcaCertificateRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).acmpcaconn | ||
certificateArn := d.Get("arn").(string) | ||
|
||
getCertificateInput := &acmpca.GetCertificateInput{ | ||
CertificateArn: aws.String(certificateArn), | ||
CertificateAuthorityArn: aws.String(d.Get("certificate_authority_arn").(string)), | ||
} | ||
|
||
log.Printf("[DEBUG] Reading ACM PCA Certificate: %s", getCertificateInput) | ||
|
||
certificateOutput, err := conn.GetCertificate(getCertificateInput) | ||
if err != nil { | ||
return fmt.Errorf("error reading ACM PCA Certificate (%s): %w", certificateArn, err) | ||
} | ||
|
||
d.SetId(certificateArn) | ||
d.Set("certificate", aws.StringValue(certificateOutput.Certificate)) | ||
d.Set("certificate_chain", aws.StringValue(certificateOutput.CertificateChain)) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAwsAcmpcaCertificate_Basic(t *testing.T) { | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
resourceName := "aws_acmpca_certificate.test" | ||
dataSourceName := "data.aws_acmpca_certificate.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsAcmpcaCertificateConfig_NonExistent, | ||
ExpectError: regexp.MustCompile(`ResourceNotFoundException`), | ||
}, | ||
{ | ||
Config: testAccDataSourceAwsAcmpcaCertificateConfig_ARN(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "certificate", resourceName, "certificate"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "certificate_chain", resourceName, "certificate_chain"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "certificate_authority_arn", resourceName, "certificate_authority_arn"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAwsAcmpcaCertificateConfig_ARN(rName string) string { | ||
return fmt.Sprintf(` | ||
data "aws_acmpca_certificate" "test" { | ||
arn = aws_acmpca_certificate.test.arn | ||
certificate_authority_arn = aws_acmpca_certificate_authority.test.arn | ||
} | ||
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 = "SHA256WITHRSA" | ||
template_arn = "arn:${data.aws_partition.current.partition}:acm-pca:::template/RootCACertificate/V1" | ||
validity { | ||
type = "YEARS" | ||
value = 1 | ||
} | ||
} | ||
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 = "%[1]s.com" | ||
} | ||
} | ||
} | ||
data "aws_partition" "current" {} | ||
`, rName) | ||
} | ||
|
||
const testAccDataSourceAwsAcmpcaCertificateConfig_NonExistent = ` | ||
data "aws_acmpca_certificate" "test" { | ||
arn = "arn:${data.aws_partition.current.partition}:acm-pca:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:certificate-authority/does-not-exist/certificate/does-not-exist" | ||
certificate_authority_arn = "arn:${data.aws_partition.current.partition}:acm-pca:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:certificate-authority/does-not-exist" | ||
} | ||
data "aws_caller_identity" "current" {} | ||
data "aws_partition" "current" {} | ||
data "aws_region" "current" {} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.