Skip to content
7 changes: 7 additions & 0 deletions .changelog/43449.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_codebuild_fleet: Add `instance_type` argument in `compute_configuration` block to support custom instance types
```

```release-note:enhancement
data-source/aws_codebuild_fleet: Add `instance_type` attribute in `compute_configuration` block
```
14 changes: 14 additions & 0 deletions internal/service/codebuild/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ func resourceFleet() *schema.Resource {
Optional: true,
Computed: true,
},
names.AttrInstanceType: {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"machine_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateDiagFunc: enum.Validate[types.MachineType](),
},
"memory": {
Expand Down Expand Up @@ -585,6 +591,10 @@ func expandComputeConfiguration(tfMap map[string]any) *types.ComputeConfiguratio
apiObject.MachineType = types.MachineType(v)
}

if v, ok := tfMap[names.AttrInstanceType].(string); ok && v != "" {
apiObject.InstanceType = aws.String(v)
}

if v, ok := tfMap["memory"].(int); ok {
apiObject.Memory = aws.Int64(int64(v))
}
Expand Down Expand Up @@ -674,6 +684,10 @@ func flattenComputeConfiguration(apiObject *types.ComputeConfiguration) map[stri
tfMap["machine_type"] = v
}

if v := apiObject.InstanceType; v != nil {
tfMap[names.AttrInstanceType] = aws.ToString(v)
}

if v := apiObject.Memory; v != nil {
tfMap["memory"] = aws.ToInt64(v)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/service/codebuild/fleet_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func dataSourceFleet() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
names.AttrInstanceType: {
Type: schema.TypeString,
Computed: true,
},
"machine_type": {
Type: schema.TypeString,
Computed: true,
Expand Down
50 changes: 50 additions & 0 deletions internal/service/codebuild/fleet_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,37 @@ func TestAccCodeBuildFleetDataSource_basic(t *testing.T) {
})
}

func TestAccCodeBuildFleetDataSource_customInstanceType(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_codebuild_fleet.test"
datasourceName := "data.aws_codebuild_fleet.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.CodeBuildServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccFleetDataSourceConfig_customInstanceType(rName, "t3.medium"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, names.AttrARN, resourceName, names.AttrARN),
resource.TestCheckResourceAttrPair(datasourceName, "base_capacity", resourceName, "base_capacity"),
resource.TestCheckResourceAttrPair(datasourceName, "compute_configuration.0.disk", resourceName, "compute_configuration.0.disk"),
resource.TestCheckResourceAttrPair(datasourceName, "compute_configuration.0.instance_type", resourceName, "compute_configuration.0.instance_type"),
resource.TestCheckResourceAttrPair(datasourceName, "compute_type", resourceName, "compute_type"),
resource.TestCheckResourceAttrPair(datasourceName, "created", resourceName, "created"),
resource.TestCheckResourceAttrPair(datasourceName, "environment_type", resourceName, "environment_type"),
resource.TestCheckResourceAttrPair(datasourceName, names.AttrID, resourceName, names.AttrID),
resource.TestCheckResourceAttrPair(datasourceName, "last_modified", resourceName, "last_modified"),
resource.TestCheckResourceAttrPair(datasourceName, names.AttrName, resourceName, names.AttrName),
resource.TestCheckResourceAttrPair(datasourceName, "overflow_behavior", resourceName, "overflow_behavior"),
),
},
},
})
}

func testAccFleetDataSourceConfig_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_codebuild_fleet" "test" {
Expand All @@ -69,3 +100,22 @@ data "aws_codebuild_fleet" "test" {
}
`, rName)
}

func testAccFleetDataSourceConfig_customInstanceType(rName, instanceType string) string {
return fmt.Sprintf(`
resource "aws_codebuild_fleet" "test" {
base_capacity = 1
compute_type = "CUSTOM_INSTANCE_TYPE"
compute_configuration {
instance_type = %[2]q
}
environment_type = "LINUX_CONTAINER"
name = %[1]q
overflow_behavior = "QUEUE"
}

data "aws_codebuild_fleet" "test" {
name = aws_codebuild_fleet.test.name
}
`, rName, instanceType)
}
62 changes: 62 additions & 0 deletions internal/service/codebuild/fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,53 @@ func TestAccCodeBuildFleet_vpcConfig(t *testing.T) {
})
}

func TestAccCodeBuildFleet_customInstanceType(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_codebuild_fleet.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.CodeBuildServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckFleetDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccFleetConfig_customInstanceType(rName, "t3.medium"),
Check: resource.ComposeTestCheckFunc(
testAccCheckFleetExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "base_capacity", "1"),
resource.TestCheckResourceAttr(resourceName, "compute_configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "compute_configuration.0.disk", "0"),
resource.TestCheckResourceAttr(resourceName, "compute_configuration.0.instance_type", "t3.medium"),
resource.TestCheckResourceAttr(resourceName, "compute_configuration.0.machine_type", "GENERAL"),
resource.TestCheckResourceAttr(resourceName, "compute_type", "CUSTOM_INSTANCE_TYPE"),
resource.TestCheckResourceAttr(resourceName, "environment_type", "LINUX_CONTAINER"),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttr(resourceName, "overflow_behavior", "QUEUE"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccFleetConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckFleetExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "base_capacity", "1"),
resource.TestCheckResourceAttr(resourceName, "compute_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "compute_type", "BUILD_GENERAL1_SMALL"),
resource.TestCheckResourceAttr(resourceName, "environment_type", "LINUX_CONTAINER"),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttr(resourceName, "overflow_behavior", "ON_DEMAND"),
),
},
},
})
}

func testAccCheckFleetDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).CodeBuildClient(ctx)
Expand Down Expand Up @@ -669,3 +716,18 @@ resource "aws_codebuild_fleet" "test" {
}
`, rName, tagKey1, tagValue1, tagKey2, tagValue2)
}

func testAccFleetConfig_customInstanceType(rName, instanceType string) string {
return fmt.Sprintf(`
resource "aws_codebuild_fleet" "test" {
base_capacity = 1
compute_type = "CUSTOM_INSTANCE_TYPE"
compute_configuration {
instance_type = %[2]q
}
environment_type = "LINUX_CONTAINER"
name = %[1]q
overflow_behavior = "QUEUE"
}
`, rName, instanceType)
}
1 change: 1 addition & 0 deletions website/docs/d/codebuild_fleet.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ This data source exports the following attributes in addition to the arguments a
* `base_capacity` - Number of machines allocated to the fleet.
* `compute_configuration` - Compute configuration of the compute fleet.
* `disk` - Amount of disk space of the instance type included in the fleet.
* `instance_type` - EC2 instance type in the fleet.
* `machine_type` - Machine type of the instance type included in the fleet.
* `memory` - Amount of memory of the instance type included in the fleet.
* `vcpu` - Number of vCPUs of the instance type included in the fleet.
Expand Down
9 changes: 5 additions & 4 deletions website/docs/r/codebuild_fleet.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The following arguments are required:
The following arguments are optional:

* `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).
* `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.
* `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.
* `fleet_service_role` - (Optional) The service role associated with the compute fleet.
* `image_id` - (Optional) The Amazon Machine Image (AMI) of the compute fleet.
* `overflow_behavior` - (Optional) Overflow behavior for compute fleet. Valid values: `ON_DEMAND`, `QUEUE`.
Expand All @@ -63,9 +63,10 @@ The following arguments are optional:
### compute_configuration

* `disk` - (Optional) Amount of disk space of the instance type included in the fleet.
* `machine_type` - (Optional) Machine type of the instance type included in the fleet. Valid values: `GENERAL`, `NVME`.
* `memory` - (Optional) Amount of memory of the instance type included in the fleet.
* `vcpu` - (Optional) Number of vCPUs of the instance type included in the fleet.
* `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).
* `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`.
* `memory` - (Optional) Amount of memory of the instance type included in the fleet. Specify only if `compute_type` is set to `ATTRIBUTE_BASED_COMPUTE`.
* `vcpu` - (Optional) Number of vCPUs of the instance type included in the fleet. Specify only if `compute_type` is set to `ATTRIBUTE_BASED_COMPUTE`.

### scaling_configuration

Expand Down
Loading