Skip to content

Commit da19676

Browse files
authored
Merge pull request #43136 from stefanfreitag/f-aws_amplify_app-add-build-compute-type
feat: add support for job_config
2 parents d90a76e + ae97b91 commit da19676

File tree

5 files changed

+134
-1
lines changed

5 files changed

+134
-1
lines changed

.changelog/43136.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_amplify_app: Add `job_config` argument
3+
```

internal/service/amplify/amplify_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestAccAmplify_serial(t *testing.T) {
3030
"Description": testAccApp_Description,
3131
"EnvironmentVariables": testAccApp_EnvironmentVariables,
3232
"IamServiceRole": testAccApp_IAMServiceRole,
33+
"JobConfig": testAccApp_JobConfig,
3334
"Name": testAccApp_Name,
3435
"Repository": testAccApp_Repository,
3536
},

internal/service/amplify/app.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,22 @@ func resourceApp() *schema.Resource {
265265
Optional: true,
266266
ValidateFunc: verify.ValidARN,
267267
},
268+
"job_config": {
269+
Type: schema.TypeList,
270+
Optional: true,
271+
Computed: true,
272+
MaxItems: 1,
273+
Elem: &schema.Resource{
274+
Schema: map[string]*schema.Schema{
275+
"build_compute_type": {
276+
Type: schema.TypeString,
277+
Optional: true,
278+
Computed: true,
279+
ValidateDiagFunc: enum.Validate[types.BuildComputeType](),
280+
},
281+
},
282+
},
283+
},
268284
names.AttrName: {
269285
Type: schema.TypeString,
270286
Required: true,
@@ -391,6 +407,10 @@ func resourceAppCreate(ctx context.Context, d *schema.ResourceData, meta any) di
391407
input.IamServiceRoleArn = aws.String(v.(string))
392408
}
393409

410+
if v, ok := d.GetOk("job_config"); ok && len(v.([]any)) > 0 && v.([]any)[0] != nil {
411+
input.JobConfig = expandJobConfig(v.([]any)[0].(map[string]any))
412+
}
413+
394414
if v, ok := d.GetOk("oauth_token"); ok {
395415
input.OauthToken = aws.String(v.(string))
396416
}
@@ -461,6 +481,13 @@ func resourceAppRead(ctx context.Context, d *schema.ResourceData, meta any) diag
461481
d.Set("enable_branch_auto_deletion", app.EnableBranchAutoDeletion)
462482
d.Set("environment_variables", aws.StringMap(app.EnvironmentVariables))
463483
d.Set("iam_service_role_arn", app.IamServiceRoleArn)
484+
if app.JobConfig != nil {
485+
if err := d.Set("job_config", []any{flattenJobConfig(app.JobConfig)}); err != nil {
486+
return sdkdiag.AppendErrorf(diags, "setting job_config: %s", err)
487+
}
488+
} else {
489+
d.Set("job_config", nil)
490+
}
464491
d.Set(names.AttrName, app.Name)
465492
d.Set("platform", app.Platform)
466493
if app.ProductionBranch != nil {
@@ -571,6 +598,12 @@ func resourceAppUpdate(ctx context.Context, d *schema.ResourceData, meta any) di
571598
input.IamServiceRoleArn = aws.String(d.Get("iam_service_role_arn").(string))
572599
}
573600

601+
if d.HasChange("job_config") {
602+
if v, ok := d.Get("job_config").([]any); ok && len(v) > 0 && v[0] != nil {
603+
input.JobConfig = expandJobConfig(v[0].(map[string]any))
604+
}
605+
}
606+
574607
if d.HasChange(names.AttrName) {
575608
input.Name = aws.String(d.Get(names.AttrName).(string))
576609
}
@@ -818,6 +851,20 @@ func expandCustomRules(tfList []any) []types.CustomRule {
818851
return apiObjects
819852
}
820853

854+
func expandJobConfig(tfMap map[string]any) *types.JobConfig {
855+
if tfMap == nil {
856+
return nil
857+
}
858+
859+
apiObject := &types.JobConfig{}
860+
861+
if v, ok := tfMap["build_compute_type"].(string); ok && v != "" {
862+
apiObject.BuildComputeType = types.BuildComputeType(v)
863+
}
864+
865+
return apiObject
866+
}
867+
821868
func flattenCustomRule(apiObject types.CustomRule) map[string]any {
822869
tfMap := map[string]any{}
823870

@@ -854,6 +901,18 @@ func flattenCustomRules(apiObjects []types.CustomRule) []any {
854901
return tfList
855902
}
856903

904+
func flattenJobConfig(apiObject *types.JobConfig) map[string]any {
905+
if apiObject == nil {
906+
return nil
907+
}
908+
909+
tfMap := map[string]any{}
910+
911+
tfMap["build_compute_type"] = string(apiObject.BuildComputeType)
912+
913+
return tfMap
914+
}
915+
857916
func flattenProductionBranch(apiObject *types.ProductionBranch) map[string]any {
858917
if apiObject == nil {
859918
return nil

internal/service/amplify/app_test.go

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func testAccApp_basic(t *testing.T) {
4747
resource.TestCheckResourceAttr(resourceName, "basic_auth_credentials", ""),
4848
resource.TestCheckResourceAttr(resourceName, "build_spec", ""),
4949
resource.TestCheckResourceAttr(resourceName, "cache_config.#", "1"),
50-
resource.TestCheckResourceAttr(resourceName, "cache_config.0.type", "AMPLIFY_MANAGED"),
50+
resource.TestCheckResourceAttr(resourceName, "cache_config.0.type", "AMPLIFY_MANAGED_NO_COOKIES"),
5151
resource.TestCheckResourceAttr(resourceName, "compute_role_arn", ""),
5252
resource.TestCheckResourceAttr(resourceName, "custom_headers", ""),
5353
resource.TestCheckResourceAttr(resourceName, "custom_rule.#", "0"),
@@ -59,6 +59,8 @@ func testAccApp_basic(t *testing.T) {
5959
resource.TestCheckResourceAttr(resourceName, "enable_branch_auto_deletion", acctest.CtFalse),
6060
resource.TestCheckResourceAttr(resourceName, "environment_variables.%", "0"),
6161
resource.TestCheckResourceAttr(resourceName, "iam_service_role_arn", ""),
62+
resource.TestCheckResourceAttr(resourceName, "job_config.#", "1"),
63+
resource.TestCheckResourceAttr(resourceName, "job_config.0.build_compute_type", "STANDARD_8GB"),
6264
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
6365
resource.TestCheckNoResourceAttr(resourceName, "oauth_token"),
6466
resource.TestCheckResourceAttr(resourceName, "platform", "WEB"),
@@ -432,6 +434,43 @@ func testAccApp_CustomRules(t *testing.T) {
432434
})
433435
}
434436

437+
func testAccApp_JobConfig(t *testing.T) {
438+
ctx := acctest.Context(t)
439+
var app types.App
440+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
441+
resourceName := "aws_amplify_app.test"
442+
443+
resource.Test(t, resource.TestCase{
444+
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(t) },
445+
ErrorCheck: acctest.ErrorCheck(t, names.AmplifyServiceID),
446+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
447+
CheckDestroy: testAccCheckAppDestroy(ctx),
448+
Steps: []resource.TestStep{
449+
{
450+
Config: testAccAppConfig_jobConfig(rName, "LARGE_16GB"),
451+
Check: resource.ComposeTestCheckFunc(
452+
testAccCheckAppExists(ctx, resourceName, &app),
453+
resource.TestCheckResourceAttr(resourceName, "job_config.#", "1"),
454+
resource.TestCheckResourceAttr(resourceName, "job_config.0.build_compute_type", "LARGE_16GB"),
455+
),
456+
},
457+
{
458+
ResourceName: resourceName,
459+
ImportState: true,
460+
ImportStateVerify: true,
461+
},
462+
{
463+
Config: testAccAppConfig_jobConfig(rName, "STANDARD_8GB"),
464+
Check: resource.ComposeTestCheckFunc(
465+
testAccCheckAppExists(ctx, resourceName, &app),
466+
resource.TestCheckResourceAttr(resourceName, "job_config.#", "1"),
467+
resource.TestCheckResourceAttr(resourceName, "job_config.0.build_compute_type", "STANDARD_8GB"),
468+
),
469+
},
470+
},
471+
})
472+
}
473+
435474
func testAccApp_Description(t *testing.T) {
436475
ctx := acctest.Context(t)
437476
var app types.App
@@ -1038,3 +1077,15 @@ resource "aws_amplify_app" "test" {
10381077
}
10391078
`, rName, repository, accessToken)
10401079
}
1080+
1081+
func testAccAppConfig_jobConfig(rName, buildComputeType string) string {
1082+
return fmt.Sprintf(`
1083+
resource "aws_amplify_app" "test" {
1084+
name = %[1]q
1085+
1086+
job_config {
1087+
build_compute_type = %[2]q
1088+
}
1089+
}
1090+
`, rName, buildComputeType)
1091+
}

website/docs/r/amplify_app.html.markdown

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ resource "aws_amplify_app" "example" {
160160
}
161161
```
162162

163+
### Job Config
164+
165+
```terraform
166+
resource "aws_amplify_app" "example" {
167+
name = "example"
168+
169+
job_config {
170+
build_compute_type = "STANDARD_8GB"
171+
}
172+
}
173+
```
174+
163175
## Argument Reference
164176

165177
This resource supports the following arguments:
@@ -182,6 +194,7 @@ This resource supports the following arguments:
182194
* `enable_branch_auto_deletion` - (Optional) Automatically disconnects a branch in the Amplify Console when you delete a branch from your Git repository.
183195
* `environment_variables` - (Optional) Environment variables map for an Amplify app.
184196
* `iam_service_role_arn` - (Optional) AWS Identity and Access Management (IAM) service role for an Amplify app.
197+
* `job_config` - (Optional) Used to configure the [Amplify Application build settings](https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html). See [`job_config` Block](#job_config-block) for details.
185198
* `oauth_token` - (Optional) OAuth token for a third-party source control system for an Amplify app. The OAuth token is used to create a webhook and a read-only deploy key. The OAuth token is not stored.
186199
* `platform` - (Optional) Platform or framework for an Amplify app. Valid values: `WEB`, `WEB_COMPUTE`. Default value: `WEB`.
187200
* `repository` - (Optional) Repository for an Amplify app.
@@ -217,6 +230,12 @@ The `custom_rule` configuration block supports the following arguments:
217230
* `status` - (Optional) Status code for a URL rewrite or redirect rule. Valid values: `200`, `301`, `302`, `404`, `404-200`.
218231
* `target` - (Required) Target pattern for a URL rewrite or redirect rule.
219232

233+
### `job_config` Block
234+
235+
The `job_config` configuration block supports the following arguments:
236+
237+
* `build_compute_type` - (Optional) Size of the build instance. Valid values: `STANDARD_8GB`, `LARGE_16GB`, and `XLARGE_72GB`. Default: `STANDARD_8GB`.
238+
220239
## Attribute Reference
221240

222241
This resource exports the following attributes in addition to the arguments above:

0 commit comments

Comments
 (0)