Skip to content

Commit 7cb27e3

Browse files
authored
Merge pull request #37889 from nikhil-goenka/f/aws_emrserverless_application
aws_emrserverless_application
2 parents e941402 + 34c2b3c commit 7cb27e3

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

.changelog/37889.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_emrserverless_application: Add `interactive_configuration` argument
3+
```

internal/service/emrserverless/application.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,26 @@ func resourceApplication() *schema.Resource {
155155
},
156156
},
157157
},
158+
"interactive_configuration": {
159+
Type: schema.TypeList,
160+
Optional: true,
161+
Computed: true,
162+
MaxItems: 1,
163+
Elem: &schema.Resource{
164+
Schema: map[string]*schema.Schema{
165+
"livy_endpoint_enabled": {
166+
Type: schema.TypeBool,
167+
Optional: true,
168+
Computed: true,
169+
},
170+
"studio_enabled": {
171+
Type: schema.TypeBool,
172+
Optional: true,
173+
Computed: true,
174+
},
175+
},
176+
},
177+
},
158178
"maximum_capacity": {
159179
Type: schema.TypeList,
160180
Optional: true,
@@ -258,6 +278,10 @@ func resourceApplicationCreate(ctx context.Context, d *schema.ResourceData, meta
258278
input.InitialCapacity = expandInitialCapacity(v.(*schema.Set))
259279
}
260280

281+
if v, ok := d.GetOk("interactive_configuration"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
282+
input.InteractiveConfiguration = expandInteractiveConfiguration(v.([]interface{})[0].(map[string]interface{}))
283+
}
284+
261285
if v, ok := d.GetOk("maximum_capacity"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
262286
input.MaximumCapacity = expandMaximumCapacity(v.([]interface{})[0].(map[string]interface{}))
263287
}
@@ -319,6 +343,10 @@ func resourceApplicationRead(ctx context.Context, d *schema.ResourceData, meta i
319343
return sdkdiag.AppendErrorf(diags, "setting initial_capacity: %s", err)
320344
}
321345

346+
if err := d.Set("interactive_configuration", []interface{}{flattenInteractiveConfiguration(application.InteractiveConfiguration)}); err != nil {
347+
return sdkdiag.AppendErrorf(diags, "setting interactive_configuration: %s", err)
348+
}
349+
322350
if err := d.Set("maximum_capacity", []interface{}{flattenMaximumCapacity(application.MaximumCapacity)}); err != nil {
323351
return sdkdiag.AppendErrorf(diags, "setting maximum_capacity: %s", err)
324352
}
@@ -362,6 +390,10 @@ func resourceApplicationUpdate(ctx context.Context, d *schema.ResourceData, meta
362390
input.InitialCapacity = expandInitialCapacity(v.(*schema.Set))
363391
}
364392

393+
if v, ok := d.GetOk("interactive_configuration"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
394+
input.InteractiveConfiguration = expandInteractiveConfiguration(v.([]interface{})[0].(map[string]interface{}))
395+
}
396+
365397
if v, ok := d.GetOk("maximum_capacity"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
366398
input.MaximumCapacity = expandMaximumCapacity(v.([]interface{})[0].(map[string]interface{}))
367399
}
@@ -573,6 +605,42 @@ func flattenAutoStopConfig(apiObject *types.AutoStopConfig) map[string]interface
573605
return tfMap
574606
}
575607

608+
func expandInteractiveConfiguration(tfMap map[string]interface{}) *types.InteractiveConfiguration {
609+
if tfMap == nil {
610+
return nil
611+
}
612+
613+
apiObject := &types.InteractiveConfiguration{}
614+
615+
if v, ok := tfMap["livy_endpoint_enabled"].(bool); ok {
616+
apiObject.LivyEndpointEnabled = aws.Bool(v)
617+
}
618+
619+
if v, ok := tfMap["studio_enabled"].(bool); ok {
620+
apiObject.StudioEnabled = aws.Bool(v)
621+
}
622+
623+
return apiObject
624+
}
625+
626+
func flattenInteractiveConfiguration(apiObject *types.InteractiveConfiguration) map[string]interface{} {
627+
if apiObject == nil {
628+
return nil
629+
}
630+
631+
tfMap := map[string]interface{}{}
632+
633+
if v := apiObject.LivyEndpointEnabled; v != nil {
634+
tfMap["livy_endpoint_enabled"] = aws.ToBool(v)
635+
}
636+
637+
if v := apiObject.StudioEnabled; v != nil {
638+
tfMap["studio_enabled"] = aws.ToBool(v)
639+
}
640+
641+
return tfMap
642+
}
643+
576644
func expandMaximumCapacity(tfMap map[string]interface{}) *types.MaximumAllowedResources {
577645
if tfMap == nil {
578646
return nil

internal/service/emrserverless/application_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,63 @@ func TestAccEMRServerlessApplication_imageConfiguration(t *testing.T) {
230230
})
231231
}
232232

233+
func TestAccEMRServerlessApplication_interactiveConfiguration(t *testing.T) {
234+
ctx := acctest.Context(t)
235+
var application types.Application
236+
resourceName := "aws_emrserverless_application.test"
237+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
238+
239+
resource.ParallelTest(t, resource.TestCase{
240+
PreCheck: func() { acctest.PreCheck(ctx, t) },
241+
ErrorCheck: acctest.ErrorCheck(t, names.EMRServerlessServiceID),
242+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
243+
CheckDestroy: testAccCheckApplicationDestroy(ctx),
244+
Steps: []resource.TestStep{
245+
{
246+
Config: testAccApplicationConfig_interactiveConfiguration(rName, true, true),
247+
Check: resource.ComposeTestCheckFunc(
248+
testAccCheckApplicationExists(ctx, resourceName, &application),
249+
resource.TestCheckResourceAttr(resourceName, "interactive_configuration.#", acctest.Ct1),
250+
resource.TestCheckResourceAttr(resourceName, "interactive_configuration.0.livy_endpoint_enabled", acctest.CtTrue),
251+
resource.TestCheckResourceAttr(resourceName, "interactive_configuration.0.studio_enabled", acctest.CtTrue),
252+
),
253+
},
254+
{
255+
ResourceName: resourceName,
256+
ImportState: true,
257+
ImportStateVerify: true,
258+
},
259+
{
260+
Config: testAccApplicationConfig_interactiveConfiguration(rName, true, false),
261+
Check: resource.ComposeTestCheckFunc(
262+
testAccCheckApplicationExists(ctx, resourceName, &application),
263+
resource.TestCheckResourceAttr(resourceName, "interactive_configuration.#", acctest.Ct1),
264+
resource.TestCheckResourceAttr(resourceName, "interactive_configuration.0.livy_endpoint_enabled", acctest.CtTrue),
265+
resource.TestCheckResourceAttr(resourceName, "interactive_configuration.0.studio_enabled", acctest.CtFalse),
266+
),
267+
},
268+
{
269+
Config: testAccApplicationConfig_interactiveConfiguration(rName, false, true),
270+
Check: resource.ComposeTestCheckFunc(
271+
testAccCheckApplicationExists(ctx, resourceName, &application),
272+
resource.TestCheckResourceAttr(resourceName, "interactive_configuration.#", acctest.Ct1),
273+
resource.TestCheckResourceAttr(resourceName, "interactive_configuration.0.livy_endpoint_enabled", acctest.CtFalse),
274+
resource.TestCheckResourceAttr(resourceName, "interactive_configuration.0.studio_enabled", acctest.CtTrue),
275+
),
276+
},
277+
{
278+
Config: testAccApplicationConfig_interactiveConfiguration(rName, false, false),
279+
Check: resource.ComposeTestCheckFunc(
280+
testAccCheckApplicationExists(ctx, resourceName, &application),
281+
resource.TestCheckResourceAttr(resourceName, "interactive_configuration.#", acctest.Ct1),
282+
resource.TestCheckNoResourceAttr(resourceName, "interactive_configuration.0.livy_endpoint_enabled"),
283+
resource.TestCheckNoResourceAttr(resourceName, "interactive_configuration.0.studio_enabled"),
284+
),
285+
},
286+
},
287+
})
288+
}
289+
233290
func TestAccEMRServerlessApplication_maxCapacity(t *testing.T) {
234291
ctx := acctest.Context(t)
235292
var application types.Application
@@ -460,6 +517,20 @@ resource "aws_emrserverless_application" "test" {
460517
`, rName, cpu)
461518
}
462519

520+
func testAccApplicationConfig_interactiveConfiguration(rName string, livyEndpointEnabled, studioEnabled bool) string {
521+
return fmt.Sprintf(`
522+
resource "aws_emrserverless_application" "test" {
523+
name = %[1]q
524+
release_label = "emr-7.1.0"
525+
type = "spark"
526+
interactive_configuration {
527+
livy_endpoint_enabled = %[2]t
528+
studio_enabled = %[3]t
529+
}
530+
}
531+
`, rName, livyEndpointEnabled, studioEnabled)
532+
}
533+
463534
func testAccApplicationConfig_maxCapacity(rName, cpu string) string {
464535
return fmt.Sprintf(`
465536
resource "aws_emrserverless_application" "test" {

website/docs/r/emrserverless_application.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ The following arguments are required:
6868
* `auto_stop_configuration` – (Optional) The configuration for an application to automatically stop after a certain amount of time being idle.
6969
* `image_configuration` – (Optional) The image configuration applied to all worker types.
7070
* `initial_capacity` – (Optional) The capacity to initialize when the application is created.
71+
* `interactive_configuration` – (Optional) Enables the interactive use cases to use when running an application.
7172
* `maximum_capacity` – (Optional) The maximum capacity to allocate when the application is created. This is cumulative across all workers at any given point in time, not just when an application is created. No new resources will be created once any one of the defined limits is hit.
7273
* `name` – (Required) The name of the application.
7374
* `network_configuration` – (Optional) The network configuration for customer VPC connectivity.
@@ -109,6 +110,11 @@ The following arguments are required:
109110
* `worker_configuration` - (Optional) The resource configuration of the initial capacity configuration.
110111
* `worker_count` - (Required) The number of workers in the initial capacity configuration.
111112

113+
### interactive_configuration Arguments
114+
115+
* `livy_endpoint_enabled` - (Optional) Enables an Apache Livy endpoint that you can connect to and run interactive jobs.
116+
* `studio_enabled` - (Optional) Enables you to connect an application to Amazon EMR Studio to run interactive workloads in a notebook.
117+
112118
##### worker_configuration Arguments
113119

114120
* `cpu` - (Required) The CPU requirements for every worker instance of the worker type.

0 commit comments

Comments
 (0)