diff --git a/.changelog/43449.txt b/.changelog/43449.txt new file mode 100644 index 000000000000..07f02dfcfac0 --- /dev/null +++ b/.changelog/43449.txt @@ -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 +``` diff --git a/internal/service/codebuild/fleet.go b/internal/service/codebuild/fleet.go index 7f7d06489df2..537d4f51e643 100644 --- a/internal/service/codebuild/fleet.go +++ b/internal/service/codebuild/fleet.go @@ -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": { @@ -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)) } @@ -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) } diff --git a/internal/service/codebuild/fleet_data_source.go b/internal/service/codebuild/fleet_data_source.go index ab3e0aaff47b..514701f9715b 100644 --- a/internal/service/codebuild/fleet_data_source.go +++ b/internal/service/codebuild/fleet_data_source.go @@ -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, diff --git a/internal/service/codebuild/fleet_data_source_test.go b/internal/service/codebuild/fleet_data_source_test.go index 7d0f3697a9bb..1a46362ce24a 100644 --- a/internal/service/codebuild/fleet_data_source_test.go +++ b/internal/service/codebuild/fleet_data_source_test.go @@ -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" { @@ -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) +} diff --git a/internal/service/codebuild/fleet_test.go b/internal/service/codebuild/fleet_test.go index 9b43c6b00450..eae708711332 100644 --- a/internal/service/codebuild/fleet_test.go +++ b/internal/service/codebuild/fleet_test.go @@ -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) @@ -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) +} diff --git a/website/docs/d/codebuild_fleet.html.markdown b/website/docs/d/codebuild_fleet.html.markdown index 0b92ff3ec7d3..7a5fc9f1f264 100644 --- a/website/docs/d/codebuild_fleet.html.markdown +++ b/website/docs/d/codebuild_fleet.html.markdown @@ -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. diff --git a/website/docs/r/codebuild_fleet.html.markdown b/website/docs/r/codebuild_fleet.html.markdown index acf66bd39c72..8ec6f76bc40b 100644 --- a/website/docs/r/codebuild_fleet.html.markdown +++ b/website/docs/r/codebuild_fleet.html.markdown @@ -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`. @@ -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