Skip to content

Commit 725ea58

Browse files
committed
Merge commit 'bbb9d4d9fd947ce23e21fa0dd6e8ec37054cba68' into HEAD
2 parents e6f66b5 + bbb9d4d commit 725ea58

File tree

3 files changed

+168
-9
lines changed

3 files changed

+168
-9
lines changed

internal/service/opensearch/domain.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,21 @@ func resourceDomain() *schema.Resource {
174174
"aiml_options": {
175175
Type: schema.TypeList,
176176
Optional: true,
177+
Computed: true,
177178
MaxItems: 1,
178179
Elem: &schema.Resource{
179180
Schema: map[string]*schema.Schema{
180181
"natural_language_query_generation_options": {
181182
Type: schema.TypeList,
182183
Optional: true,
184+
Computed: true,
183185
MaxItems: 1,
184186
Elem: &schema.Resource{
185187
Schema: map[string]*schema.Schema{
186188
"desired_state": {
187189
Type: schema.TypeString,
188190
Optional: true,
191+
Computed: true,
189192
ValidateDiagFunc: enum.Validate[awstypes.NaturalLanguageQueryGenerationDesiredState](),
190193
},
191194
},
@@ -194,11 +197,13 @@ func resourceDomain() *schema.Resource {
194197
"s3_vectors_engine": {
195198
Type: schema.TypeList,
196199
Optional: true,
200+
Computed: true,
197201
MaxItems: 1,
198202
Elem: &schema.Resource{
199203
Schema: map[string]*schema.Schema{
200204
names.AttrEnabled: {
201205
Type: schema.TypeBool,
206+
Computed: true,
202207
Optional: true,
203208
},
204209
},
@@ -953,7 +958,7 @@ func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta any) d
953958
}
954959
}
955960
if ds.AIMLOptions != nil {
956-
if err := d.Set("aiml_options", []interface{}{flattenAIMLOptionsOutput(ds.AIMLOptions)}); err != nil {
961+
if err := d.Set("aiml_options", []any{flattenAIMLOptionsOutput(ds.AIMLOptions)}); err != nil {
957962
return sdkdiag.AppendErrorf(diags, "setting aiml_options: %s", err)
958963
}
959964
} else {
@@ -1087,6 +1092,12 @@ func resourceDomainUpdate(ctx context.Context, d *schema.ResourceData, meta any)
10871092
input.AdvancedSecurityOptions = expandAdvancedSecurityOptions(d.Get("advanced_security_options").([]any))
10881093
}
10891094

1095+
if d.HasChange("aiml_options") {
1096+
if v, ok := d.GetOk("aiml_options"); ok && len(v.([]any)) > 0 && v.([]any)[0] != nil {
1097+
input.AIMLOptions = expandAIMLOptionsInput(v.([]any)[0].(map[string]any))
1098+
}
1099+
}
1100+
10901101
if d.HasChange("auto_tune_options") {
10911102
input.AutoTuneOptions = expandAutoTuneOptions(d.Get("auto_tune_options").([]any)[0].(map[string]any))
10921103
}

internal/service/opensearch/domain_structure.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ func flattenAIMLOptionsOutput(apiObject *awstypes.AIMLOptionsOutput) map[string]
302302
tfMap := map[string]any{}
303303

304304
if v := apiObject.NaturalLanguageQueryGenerationOptions; v != nil {
305-
tfMap["natural_language_query_generation_options"] = []interface{}{flattenNaturalLanguageQueryGenerationOptionsOutput(v)}
305+
tfMap["natural_language_query_generation_options"] = []any{flattenNaturalLanguageQueryGenerationOptionsOutput(v)}
306306
}
307307

308308
if v := apiObject.S3VectorsEngine; v != nil {
309-
tfMap["s3_vectors_engine"] = []interface{}{flattenS3VectorsEngine(v)}
309+
tfMap["s3_vectors_engine"] = []any{flattenS3VectorsEngine(v)}
310310
}
311311

312312
return tfMap

internal/service/opensearch/domain_test.go

Lines changed: 154 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func TestAccOpenSearchDomain_basic(t *testing.T) {
155155
Config: testAccDomainConfig_basic(rName),
156156
Check: resource.ComposeTestCheckFunc(
157157
testAccCheckDomainExists(ctx, resourceName, &domain),
158+
resource.TestCheckResourceAttr(resourceName, "aiml_options.#", "1"),
158159
resource.TestMatchResourceAttr(resourceName, "dashboard_endpoint", regexache.MustCompile(`.*(opensearch|es)\..*/_dashboards`)),
159160
resource.TestCheckResourceAttrSet(resourceName, names.AttrEngineVersion),
160161
resource.TestCheckResourceAttr(resourceName, "off_peak_window_options.#", "1"),
@@ -2262,14 +2263,17 @@ func TestAccOpenSearchDomain_softwareUpdateOptions(t *testing.T) {
22622263
})
22632264
}
22642265

2265-
func TestAccOpenSearchDomain_disappears(t *testing.T) {
2266+
func TestAccOpenSearchDomain_AIMLOptions_createEnabled(t *testing.T) {
22662267
ctx := acctest.Context(t)
22672268
if testing.Short() {
22682269
t.Skip("skipping long-running test in short mode")
22692270
}
22702271

2272+
var domain awstypes.DomainStatus
22712273
rName := testAccRandomDomainName()
22722274
resourceName := "aws_opensearch_domain.test"
2275+
enabledState := "ENABLED"
2276+
disabledState := "DISABLED"
22732277

22742278
resource.ParallelTest(t, resource.TestCase{
22752279
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckIAMServiceLinkedRole(ctx, t) },
@@ -2278,17 +2282,67 @@ func TestAccOpenSearchDomain_disappears(t *testing.T) {
22782282
CheckDestroy: testAccCheckDomainDestroy(ctx),
22792283
Steps: []resource.TestStep{
22802284
{
2281-
Config: testAccDomainConfig_basic(rName),
2285+
Config: testAccDomainConfig_AIMLOptions(rName, enabledState, false),
22822286
Check: resource.ComposeTestCheckFunc(
2283-
acctest.CheckResourceDisappears(ctx, acctest.Provider, tfopensearch.ResourceDomain(), resourceName),
2287+
testAccCheckDomainExists(ctx, resourceName, &domain),
2288+
resource.TestCheckResourceAttr(resourceName, "aiml_options.#", "1"),
2289+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.natural_language_query_generation_options.#", "1"),
2290+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.natural_language_query_generation_options.0.desired_state", enabledState),
2291+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.s3_vectors_engine.#", "1"),
2292+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.s3_vectors_engine.0.enabled", acctest.CtFalse),
22842293
),
2285-
ExpectNonEmptyPlan: true,
2294+
ConfigPlanChecks: resource.ConfigPlanChecks{
2295+
PreApply: []plancheck.PlanCheck{
2296+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
2297+
},
2298+
},
2299+
},
2300+
{
2301+
ResourceName: resourceName,
2302+
ImportState: true,
2303+
ImportStateId: rName,
2304+
ImportStateVerify: true,
2305+
ImportStateVerifyIgnore: []string{
2306+
"advanced_security_options",
2307+
},
2308+
},
2309+
{
2310+
Config: testAccDomainConfig_AIMLOptions(rName, disabledState, true),
2311+
Check: resource.ComposeTestCheckFunc(
2312+
testAccCheckDomainExists(ctx, resourceName, &domain),
2313+
resource.TestCheckResourceAttr(resourceName, "aiml_options.#", "1"),
2314+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.natural_language_query_generation_options.#", "1"),
2315+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.natural_language_query_generation_options.0.desired_state", disabledState),
2316+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.s3_vectors_engine.#", "1"),
2317+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.s3_vectors_engine.0.enabled", acctest.CtTrue),
2318+
),
2319+
ConfigPlanChecks: resource.ConfigPlanChecks{
2320+
PreApply: []plancheck.PlanCheck{
2321+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
2322+
},
2323+
},
2324+
},
2325+
{
2326+
Config: testAccDomainConfig_AIMLOptions(rName, enabledState, false),
2327+
Check: resource.ComposeTestCheckFunc(
2328+
testAccCheckDomainExists(ctx, resourceName, &domain),
2329+
resource.TestCheckResourceAttr(resourceName, "aiml_options.#", "1"),
2330+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.natural_language_query_generation_options.#", "1"),
2331+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.natural_language_query_generation_options.0.desired_state", enabledState),
2332+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.s3_vectors_engine.#", "1"),
2333+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.s3_vectors_engine.0.enabled", acctest.CtFalse),
2334+
),
2335+
ConfigPlanChecks: resource.ConfigPlanChecks{
2336+
PreApply: []plancheck.PlanCheck{
2337+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
2338+
},
2339+
},
22862340
},
22872341
},
22882342
})
22892343
}
22902344

2291-
func TestAccOpenSearchDomain_AIMLOptions(t *testing.T) {
2345+
func TestAccOpenSearchDomain_AIMLOptions_createDisabled(t *testing.T) {
22922346
ctx := acctest.Context(t)
22932347
if testing.Short() {
22942348
t.Skip("skipping long-running test in short mode")
@@ -2306,21 +2360,88 @@ func TestAccOpenSearchDomain_AIMLOptions(t *testing.T) {
23062360
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
23072361
CheckDestroy: testAccCheckDomainDestroy(ctx),
23082362
Steps: []resource.TestStep{
2363+
{
2364+
Config: testAccDomainConfig_AIMLOptions(rName, disabledState, true),
2365+
Check: resource.ComposeTestCheckFunc(
2366+
testAccCheckDomainExists(ctx, resourceName, &domain),
2367+
resource.TestCheckResourceAttr(resourceName, "aiml_options.#", "1"),
2368+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.natural_language_query_generation_options.#", "1"),
2369+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.natural_language_query_generation_options.0.desired_state", disabledState),
2370+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.s3_vectors_engine.#", "1"),
2371+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.s3_vectors_engine.0.enabled", acctest.CtTrue),
2372+
),
2373+
ConfigPlanChecks: resource.ConfigPlanChecks{
2374+
PreApply: []plancheck.PlanCheck{
2375+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
2376+
},
2377+
},
2378+
},
2379+
{
2380+
ResourceName: resourceName,
2381+
ImportState: true,
2382+
ImportStateId: rName,
2383+
ImportStateVerify: true,
2384+
ImportStateVerifyIgnore: []string{
2385+
"advanced_security_options",
2386+
},
2387+
},
23092388
{
23102389
Config: testAccDomainConfig_AIMLOptions(rName, enabledState, false),
23112390
Check: resource.ComposeTestCheckFunc(
23122391
testAccCheckDomainExists(ctx, resourceName, &domain),
2392+
resource.TestCheckResourceAttr(resourceName, "aiml_options.#", "1"),
2393+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.natural_language_query_generation_options.#", "1"),
23132394
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.natural_language_query_generation_options.0.desired_state", enabledState),
2395+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.s3_vectors_engine.#", "1"),
23142396
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.s3_vectors_engine.0.enabled", acctest.CtFalse),
23152397
),
2398+
ConfigPlanChecks: resource.ConfigPlanChecks{
2399+
PreApply: []plancheck.PlanCheck{
2400+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
2401+
},
2402+
},
23162403
},
23172404
{
23182405
Config: testAccDomainConfig_AIMLOptions(rName, disabledState, true),
23192406
Check: resource.ComposeTestCheckFunc(
23202407
testAccCheckDomainExists(ctx, resourceName, &domain),
2408+
resource.TestCheckResourceAttr(resourceName, "aiml_options.#", "1"),
2409+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.natural_language_query_generation_options.#", "1"),
23212410
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.natural_language_query_generation_options.0.desired_state", disabledState),
2411+
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.s3_vectors_engine.#", "1"),
23222412
resource.TestCheckResourceAttr(resourceName, "aiml_options.0.s3_vectors_engine.0.enabled", acctest.CtTrue),
23232413
),
2414+
ConfigPlanChecks: resource.ConfigPlanChecks{
2415+
PreApply: []plancheck.PlanCheck{
2416+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
2417+
},
2418+
},
2419+
},
2420+
},
2421+
})
2422+
}
2423+
2424+
func TestAccOpenSearchDomain_disappears(t *testing.T) {
2425+
ctx := acctest.Context(t)
2426+
if testing.Short() {
2427+
t.Skip("skipping long-running test in short mode")
2428+
}
2429+
2430+
rName := testAccRandomDomainName()
2431+
resourceName := "aws_opensearch_domain.test"
2432+
2433+
resource.ParallelTest(t, resource.TestCase{
2434+
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckIAMServiceLinkedRole(ctx, t) },
2435+
ErrorCheck: acctest.ErrorCheck(t, names.OpenSearchServiceID),
2436+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
2437+
CheckDestroy: testAccCheckDomainDestroy(ctx),
2438+
Steps: []resource.TestStep{
2439+
{
2440+
Config: testAccDomainConfig_basic(rName),
2441+
Check: resource.ComposeTestCheckFunc(
2442+
acctest.CheckResourceDisappears(ctx, acctest.Provider, tfopensearch.ResourceDomain(), resourceName),
2443+
),
2444+
ExpectNonEmptyPlan: true,
23242445
},
23252446
},
23262447
})
@@ -4248,9 +4369,36 @@ func testAccDomainConfig_AIMLOptions(rName, desiredState string, S3VecotrsEnable
42484369
resource "aws_opensearch_domain" "test" {
42494370
domain_name = %[1]q
42504371
4372+
cluster_config {
4373+
instance_type = "or1.medium.search"
4374+
instance_count = 1
4375+
}
4376+
4377+
advanced_security_options {
4378+
enabled = true
4379+
internal_user_database_enabled = true
4380+
master_user_options {
4381+
master_user_name = "testmasteruser"
4382+
master_user_password = "Barbarbarbar1!"
4383+
}
4384+
}
4385+
4386+
domain_endpoint_options {
4387+
enforce_https = true
4388+
tls_security_policy = "Policy-Min-TLS-1-2-2019-07"
4389+
}
4390+
4391+
node_to_node_encryption {
4392+
enabled = true
4393+
}
4394+
42514395
ebs_options {
42524396
ebs_enabled = true
4253-
volume_size = 10
4397+
volume_size = 20
4398+
}
4399+
4400+
encrypt_at_rest {
4401+
enabled = true
42544402
}
42554403
42564404
aiml_options {

0 commit comments

Comments
 (0)