|
8 | 8 | "fmt" |
9 | 9 | "testing" |
10 | 10 |
|
| 11 | + awstypes "github.com/aws/aws-sdk-go-v2/service/opensearch/types" |
11 | 12 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
12 | 13 | "github.com/hashicorp/terraform-plugin-testing/terraform" |
13 | 14 | "github.com/hashicorp/terraform-provider-aws/internal/acctest" |
@@ -53,6 +54,43 @@ func TestAccOpenSearchPackage_basic(t *testing.T) { |
53 | 54 | }) |
54 | 55 | } |
55 | 56 |
|
| 57 | +func TestAccOpenSearchPackage_packageTypeZipPlugin(t *testing.T) { |
| 58 | + ctx := acctest.Context(t) |
| 59 | + pkgName := testAccRandomDomainName() |
| 60 | + resourceName := "aws_opensearch_package.test" |
| 61 | + |
| 62 | + resource.ParallelTest(t, resource.TestCase{ |
| 63 | + PreCheck: func() { acctest.PreCheck(ctx, t) }, |
| 64 | + ErrorCheck: acctest.ErrorCheck(t, names.OpenSearchServiceID), |
| 65 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, |
| 66 | + CheckDestroy: testAccCheckPackageDestroy(ctx), |
| 67 | + Steps: []resource.TestStep{ |
| 68 | + { |
| 69 | + Config: testAccPackageConfig_packageTypeZipPlugin(pkgName, "OpenSearch_2.17"), |
| 70 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 71 | + testAccCheckPackageExists(ctx, resourceName), |
| 72 | + resource.TestCheckResourceAttr(resourceName, "available_package_version", "v1"), |
| 73 | + resource.TestCheckResourceAttr(resourceName, "engine_version", "OpenSearch_2.17"), |
| 74 | + resource.TestCheckResourceAttr(resourceName, "package_description", ""), |
| 75 | + resource.TestCheckResourceAttrSet(resourceName, "package_id"), |
| 76 | + resource.TestCheckResourceAttr(resourceName, "package_name", pkgName), |
| 77 | + resource.TestCheckResourceAttr(resourceName, "package_source.#", "1"), |
| 78 | + resource.TestCheckResourceAttr(resourceName, "package_type", string(awstypes.PackageTypeZipPlugin)), |
| 79 | + ), |
| 80 | + }, |
| 81 | + { |
| 82 | + ResourceName: resourceName, |
| 83 | + ImportState: true, |
| 84 | + ImportStateVerify: true, |
| 85 | + ImportStateVerifyIgnore: []string{ |
| 86 | + "available_package_version", |
| 87 | + "package_source", // This isn't returned by the API |
| 88 | + }, |
| 89 | + }, |
| 90 | + }, |
| 91 | + }) |
| 92 | +} |
| 93 | + |
56 | 94 | func TestAccOpenSearchPackage_disappears(t *testing.T) { |
57 | 95 | ctx := acctest.Context(t) |
58 | 96 | pkgName := testAccRandomDomainName() |
@@ -140,3 +178,35 @@ resource "aws_opensearch_package" "test" { |
140 | 178 | } |
141 | 179 | `, rName) |
142 | 180 | } |
| 181 | + |
| 182 | +func testAccPackageConfig_packageTypeZipPlugin(rName, engineVersion string) string { |
| 183 | + return fmt.Sprintf(` |
| 184 | +resource "aws_s3_bucket" "test" { |
| 185 | + bucket = %[1]q |
| 186 | +} |
| 187 | +
|
| 188 | +
|
| 189 | +# example-dummy-opensearch-plugin.zip was created from the sample repository provided by AWS using the following commands: |
| 190 | +# > git clone https://github.com/aws-samples/kr-tech-blog-sample-code.git |
| 191 | +# > cd kr-tech-blog-sample-code/opensearch_custom_plugin |
| 192 | +# > gradele build |
| 193 | +# > cp build/distributions/opensearch-custom-plugin-1.0.0.zip terraform-provider-aws/internal/service/opensearch/test-fixtures/example-dummy-opensearch-plugin.zip |
| 194 | +
|
| 195 | +resource "aws_s3_object" "test" { |
| 196 | + bucket = aws_s3_bucket.test.bucket |
| 197 | + key = %[1]q |
| 198 | + source = "./test-fixtures/example-dummy-opensearch-plugin.zip" |
| 199 | + etag = filemd5("./test-fixtures/example-dummy-opensearch-plugin.zip") |
| 200 | +} |
| 201 | +
|
| 202 | +resource "aws_opensearch_package" "test" { |
| 203 | + engine_version = %[2]q |
| 204 | + package_name = %[1]q |
| 205 | + package_source { |
| 206 | + s3_bucket_name = aws_s3_bucket.test.bucket |
| 207 | + s3_key = aws_s3_object.test.key |
| 208 | + } |
| 209 | + package_type = "ZIP-PLUGIN" |
| 210 | +} |
| 211 | +`, rName, engineVersion) |
| 212 | +} |
0 commit comments