Skip to content

Commit 72b875c

Browse files
authored
Merge pull request #43449 from tabito-hara/f-aws_codebuild_fleet-add_instance_type
[Enhancement] aws_codebuild_fleet: Support custom instance type in the fleet
2 parents 9ef58be + 8711b4e commit 72b875c

File tree

7 files changed

+143
-4
lines changed

7 files changed

+143
-4
lines changed

.changelog/43449.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/aws_codebuild_fleet: Add `instance_type` argument in `compute_configuration` block to support custom instance types
3+
```
4+
5+
```release-note:enhancement
6+
data-source/aws_codebuild_fleet: Add `instance_type` attribute in `compute_configuration` block
7+
```

internal/service/codebuild/fleet.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,15 @@ func resourceFleet() *schema.Resource {
5858
Optional: true,
5959
Computed: true,
6060
},
61+
names.AttrInstanceType: {
62+
Type: schema.TypeString,
63+
Optional: true,
64+
Computed: true,
65+
},
6166
"machine_type": {
6267
Type: schema.TypeString,
6368
Optional: true,
69+
Computed: true,
6470
ValidateDiagFunc: enum.Validate[types.MachineType](),
6571
},
6672
"memory": {
@@ -585,6 +591,10 @@ func expandComputeConfiguration(tfMap map[string]any) *types.ComputeConfiguratio
585591
apiObject.MachineType = types.MachineType(v)
586592
}
587593

594+
if v, ok := tfMap[names.AttrInstanceType].(string); ok && v != "" {
595+
apiObject.InstanceType = aws.String(v)
596+
}
597+
588598
if v, ok := tfMap["memory"].(int); ok {
589599
apiObject.Memory = aws.Int64(int64(v))
590600
}
@@ -674,6 +684,10 @@ func flattenComputeConfiguration(apiObject *types.ComputeConfiguration) map[stri
674684
tfMap["machine_type"] = v
675685
}
676686

687+
if v := apiObject.InstanceType; v != nil {
688+
tfMap[names.AttrInstanceType] = aws.ToString(v)
689+
}
690+
677691
if v := apiObject.Memory; v != nil {
678692
tfMap["memory"] = aws.ToInt64(v)
679693
}

internal/service/codebuild/fleet_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func dataSourceFleet() *schema.Resource {
4040
Type: schema.TypeInt,
4141
Computed: true,
4242
},
43+
names.AttrInstanceType: {
44+
Type: schema.TypeString,
45+
Computed: true,
46+
},
4347
"machine_type": {
4448
Type: schema.TypeString,
4549
Computed: true,

internal/service/codebuild/fleet_data_source_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,37 @@ func TestAccCodeBuildFleetDataSource_basic(t *testing.T) {
4646
})
4747
}
4848

49+
func TestAccCodeBuildFleetDataSource_customInstanceType(t *testing.T) {
50+
ctx := acctest.Context(t)
51+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
52+
resourceName := "aws_codebuild_fleet.test"
53+
datasourceName := "data.aws_codebuild_fleet.test"
54+
55+
resource.ParallelTest(t, resource.TestCase{
56+
PreCheck: func() { acctest.PreCheck(ctx, t) },
57+
ErrorCheck: acctest.ErrorCheck(t, names.CodeBuildServiceID),
58+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
59+
Steps: []resource.TestStep{
60+
{
61+
Config: testAccFleetDataSourceConfig_customInstanceType(rName, "t3.medium"),
62+
Check: resource.ComposeTestCheckFunc(
63+
resource.TestCheckResourceAttrPair(datasourceName, names.AttrARN, resourceName, names.AttrARN),
64+
resource.TestCheckResourceAttrPair(datasourceName, "base_capacity", resourceName, "base_capacity"),
65+
resource.TestCheckResourceAttrPair(datasourceName, "compute_configuration.0.disk", resourceName, "compute_configuration.0.disk"),
66+
resource.TestCheckResourceAttrPair(datasourceName, "compute_configuration.0.instance_type", resourceName, "compute_configuration.0.instance_type"),
67+
resource.TestCheckResourceAttrPair(datasourceName, "compute_type", resourceName, "compute_type"),
68+
resource.TestCheckResourceAttrPair(datasourceName, "created", resourceName, "created"),
69+
resource.TestCheckResourceAttrPair(datasourceName, "environment_type", resourceName, "environment_type"),
70+
resource.TestCheckResourceAttrPair(datasourceName, names.AttrID, resourceName, names.AttrID),
71+
resource.TestCheckResourceAttrPair(datasourceName, "last_modified", resourceName, "last_modified"),
72+
resource.TestCheckResourceAttrPair(datasourceName, names.AttrName, resourceName, names.AttrName),
73+
resource.TestCheckResourceAttrPair(datasourceName, "overflow_behavior", resourceName, "overflow_behavior"),
74+
),
75+
},
76+
},
77+
})
78+
}
79+
4980
func testAccFleetDataSourceConfig_basic(rName string) string {
5081
return fmt.Sprintf(`
5182
resource "aws_codebuild_fleet" "test" {
@@ -69,3 +100,22 @@ data "aws_codebuild_fleet" "test" {
69100
}
70101
`, rName)
71102
}
103+
104+
func testAccFleetDataSourceConfig_customInstanceType(rName, instanceType string) string {
105+
return fmt.Sprintf(`
106+
resource "aws_codebuild_fleet" "test" {
107+
base_capacity = 1
108+
compute_type = "CUSTOM_INSTANCE_TYPE"
109+
compute_configuration {
110+
instance_type = %[2]q
111+
}
112+
environment_type = "LINUX_CONTAINER"
113+
name = %[1]q
114+
overflow_behavior = "QUEUE"
115+
}
116+
117+
data "aws_codebuild_fleet" "test" {
118+
name = aws_codebuild_fleet.test.name
119+
}
120+
`, rName, instanceType)
121+
}

internal/service/codebuild/fleet_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,53 @@ func TestAccCodeBuildFleet_vpcConfig(t *testing.T) {
359359
})
360360
}
361361

362+
func TestAccCodeBuildFleet_customInstanceType(t *testing.T) {
363+
ctx := acctest.Context(t)
364+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
365+
resourceName := "aws_codebuild_fleet.test"
366+
367+
resource.ParallelTest(t, resource.TestCase{
368+
PreCheck: func() { acctest.PreCheck(ctx, t) },
369+
ErrorCheck: acctest.ErrorCheck(t, names.CodeBuildServiceID),
370+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
371+
CheckDestroy: testAccCheckFleetDestroy(ctx),
372+
Steps: []resource.TestStep{
373+
{
374+
Config: testAccFleetConfig_customInstanceType(rName, "t3.medium"),
375+
Check: resource.ComposeTestCheckFunc(
376+
testAccCheckFleetExists(ctx, resourceName),
377+
resource.TestCheckResourceAttr(resourceName, "base_capacity", "1"),
378+
resource.TestCheckResourceAttr(resourceName, "compute_configuration.#", "1"),
379+
resource.TestCheckResourceAttr(resourceName, "compute_configuration.0.disk", "0"),
380+
resource.TestCheckResourceAttr(resourceName, "compute_configuration.0.instance_type", "t3.medium"),
381+
resource.TestCheckResourceAttr(resourceName, "compute_configuration.0.machine_type", "GENERAL"),
382+
resource.TestCheckResourceAttr(resourceName, "compute_type", "CUSTOM_INSTANCE_TYPE"),
383+
resource.TestCheckResourceAttr(resourceName, "environment_type", "LINUX_CONTAINER"),
384+
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
385+
resource.TestCheckResourceAttr(resourceName, "overflow_behavior", "QUEUE"),
386+
),
387+
},
388+
{
389+
ResourceName: resourceName,
390+
ImportState: true,
391+
ImportStateVerify: true,
392+
},
393+
{
394+
Config: testAccFleetConfig_basic(rName),
395+
Check: resource.ComposeTestCheckFunc(
396+
testAccCheckFleetExists(ctx, resourceName),
397+
resource.TestCheckResourceAttr(resourceName, "base_capacity", "1"),
398+
resource.TestCheckResourceAttr(resourceName, "compute_configuration.#", "0"),
399+
resource.TestCheckResourceAttr(resourceName, "compute_type", "BUILD_GENERAL1_SMALL"),
400+
resource.TestCheckResourceAttr(resourceName, "environment_type", "LINUX_CONTAINER"),
401+
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
402+
resource.TestCheckResourceAttr(resourceName, "overflow_behavior", "ON_DEMAND"),
403+
),
404+
},
405+
},
406+
})
407+
}
408+
362409
func testAccCheckFleetDestroy(ctx context.Context) resource.TestCheckFunc {
363410
return func(s *terraform.State) error {
364411
conn := acctest.Provider.Meta().(*conns.AWSClient).CodeBuildClient(ctx)
@@ -669,3 +716,18 @@ resource "aws_codebuild_fleet" "test" {
669716
}
670717
`, rName, tagKey1, tagValue1, tagKey2, tagValue2)
671718
}
719+
720+
func testAccFleetConfig_customInstanceType(rName, instanceType string) string {
721+
return fmt.Sprintf(`
722+
resource "aws_codebuild_fleet" "test" {
723+
base_capacity = 1
724+
compute_type = "CUSTOM_INSTANCE_TYPE"
725+
compute_configuration {
726+
instance_type = %[2]q
727+
}
728+
environment_type = "LINUX_CONTAINER"
729+
name = %[1]q
730+
overflow_behavior = "QUEUE"
731+
}
732+
`, rName, instanceType)
733+
}

website/docs/d/codebuild_fleet.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ This data source exports the following attributes in addition to the arguments a
5959
* `base_capacity` - Number of machines allocated to the fleet.
6060
* `compute_configuration` - Compute configuration of the compute fleet.
6161
* `disk` - Amount of disk space of the instance type included in the fleet.
62+
* `instance_type` - EC2 instance type in the fleet.
6263
* `machine_type` - Machine type of the instance type included in the fleet.
6364
* `memory` - Amount of memory of the instance type included in the fleet.
6465
* `vcpu` - Number of vCPUs of the instance type included in the fleet.

website/docs/r/codebuild_fleet.html.markdown

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The following arguments are required:
5252
The following arguments are optional:
5353

5454
* `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference).
55-
* `compute_configuration` - (Optional) The compute configuration of the compute fleet. This is only required if `compute_type` is set to `ATTRIBUTE_BASED_COMPUTE`. See [`compute_configuration`](#compute_configuration) below.
55+
* `compute_configuration` - (Optional) The compute configuration of the compute fleet. This is only required if `compute_type` is set to `ATTRIBUTE_BASED_COMPUTE` or `CUSTOM_INSTANCE_TYPE`. See [`compute_configuration`](#compute_configuration) below.
5656
* `fleet_service_role` - (Optional) The service role associated with the compute fleet.
5757
* `image_id` - (Optional) The Amazon Machine Image (AMI) of the compute fleet.
5858
* `overflow_behavior` - (Optional) Overflow behavior for compute fleet. Valid values: `ON_DEMAND`, `QUEUE`.
@@ -63,9 +63,10 @@ The following arguments are optional:
6363
### compute_configuration
6464

6565
* `disk` - (Optional) Amount of disk space of the instance type included in the fleet.
66-
* `machine_type` - (Optional) Machine type of the instance type included in the fleet. Valid values: `GENERAL`, `NVME`.
67-
* `memory` - (Optional) Amount of memory of the instance type included in the fleet.
68-
* `vcpu` - (Optional) Number of vCPUs of the instance type included in the fleet.
66+
* `instance_type` - (Optional) EC2 instance type to be launched in the fleet. Specify only if `compute_type` is set to `CUSTOM_INSTANCE_TYPE`. See [Supported instance families](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html#environment-reserved-capacity.instance-types).
67+
* `machine_type` - (Optional) Machine type of the instance type included in the fleet. Valid values: `GENERAL`, `NVME`. Specify only if `compute_type` is set to `ATTRIBUTE_BASED_COMPUTE`.
68+
* `memory` - (Optional) Amount of memory of the instance type included in the fleet. Specify only if `compute_type` is set to `ATTRIBUTE_BASED_COMPUTE`.
69+
* `vcpu` - (Optional) Number of vCPUs of the instance type included in the fleet. Specify only if `compute_type` is set to `ATTRIBUTE_BASED_COMPUTE`.
6970

7071
### scaling_configuration
7172

0 commit comments

Comments
 (0)