mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-08 15:13:56 -06:00
be56c7d2f6
* Add aws dms vendoring * Add aws dms endpoint resource * Add aws dms replication instance resource * Add aws dms replication subnet group resource * Add aws dms replication task resource * Fix aws dms resource go vet errors * Review fixes: Add id validators for all resources. Add validator for endpoint engine_name. * Add aws dms resources to importability list * Review fixes: Add aws dms iam role dependencies to test cases * Review fixes: Adjustments for handling input values * Add aws dms replication subnet group tagging * Fix aws dms subnet group doesn't use standard error for resource not found * Missed update of aws dms vendored version * Add aws dms certificate resource * Update aws dms resources to force new for immutable attributes * Fix tests failing on subnet deletion by adding explicit dependencies. Combine import tests with basic tests to cut down runtime.
104 lines
4.0 KiB
Go
104 lines
4.0 KiB
Go
package aws
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
dms "github.com/aws/aws-sdk-go/service/databasemigrationservice"
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccAwsDmsCertificateBasic(t *testing.T) {
|
|
resourceName := "aws_dms_certificate.dms_certificate"
|
|
randId := acctest.RandString(8)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: dmsCertificateDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: dmsCertificateConfig(randId),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
checkDmsCertificateExists(resourceName),
|
|
resource.TestCheckResourceAttrSet(resourceName, "certificate_arn"),
|
|
),
|
|
},
|
|
{
|
|
ResourceName: resourceName,
|
|
ImportState: true,
|
|
ImportStateVerify: true,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func dmsCertificateDestroy(s *terraform.State) error {
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "aws_dms_certificate" {
|
|
continue
|
|
}
|
|
|
|
err := checkDmsCertificateExists(rs.Primary.ID)
|
|
if err == nil {
|
|
return fmt.Errorf("Found a certificate that was not destroyed: %s", rs.Primary.ID)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func checkDmsCertificateExists(n string) resource.TestCheckFunc {
|
|
providers := []*schema.Provider{testAccProvider}
|
|
return checkDmsCertificateExistsWithProviders(n, &providers)
|
|
}
|
|
|
|
func checkDmsCertificateExistsWithProviders(n string, providers *[]*schema.Provider) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No ID is set")
|
|
}
|
|
for _, provider := range *providers {
|
|
// Ignore if Meta is empty, this can happen for validation providers
|
|
if provider.Meta() == nil {
|
|
continue
|
|
}
|
|
|
|
conn := provider.Meta().(*AWSClient).dmsconn
|
|
_, err := conn.DescribeCertificates(&dms.DescribeCertificatesInput{
|
|
Filters: []*dms.Filter{
|
|
{
|
|
Name: aws.String("certificate-id"),
|
|
Values: []*string{aws.String(rs.Primary.ID)},
|
|
},
|
|
},
|
|
})
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("DMS certificate error: %v", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
return fmt.Errorf("DMS certificate not found")
|
|
}
|
|
}
|
|
|
|
func dmsCertificateConfig(randId string) string {
|
|
return fmt.Sprintf(`
|
|
resource "aws_dms_certificate" "dms_certificate" {
|
|
certificate_id = "tf-test-dms-certificate-%[1]s"
|
|
certificate_pem = "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIJAJ58TJVjU7G1MA0GCSqGSIb3DQEBBQUAMFExCzAJBgNV\nBAYTAlVTMREwDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGR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