From 2492d30650989f6618dff51d6fb3101754be40cd Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 20 Jan 2022 18:04:51 +0200 Subject: [PATCH 1/3] devicefarm test grid projecy --- internal/provider/provider.go | 11 +- internal/service/devicefarm/find.go | 25 ++ internal/service/devicefarm/sweep.go | 59 ++++ .../service/devicefarm/test_grid_project.go | 239 ++++++++++++++ .../devicefarm/test_grid_project_test.go | 302 ++++++++++++++++++ ...devicefarm_test_grid_project.html.markdown | 57 ++++ 6 files changed, 688 insertions(+), 5 deletions(-) create mode 100644 internal/service/devicefarm/test_grid_project.go create mode 100644 internal/service/devicefarm/test_grid_project_test.go create mode 100644 website/docs/r/devicefarm_test_grid_project.html.markdown diff --git a/internal/provider/provider.go b/internal/provider/provider.go index cf2d7cfa952..a7eafaad53a 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -1010,11 +1010,12 @@ func Provider() *schema.Provider { "aws_dax_parameter_group": dax.ResourceParameterGroup(), "aws_dax_subnet_group": dax.ResourceSubnetGroup(), - "aws_devicefarm_device_pool": devicefarm.ResourceDevicePool(), - "aws_devicefarm_instance_profile": devicefarm.ResourceInstanceProfile(), - "aws_devicefarm_network_profile": devicefarm.ResourceNetworkProfile(), - "aws_devicefarm_project": devicefarm.ResourceProject(), - "aws_devicefarm_upload": devicefarm.ResourceUpload(), + "aws_devicefarm_device_pool": devicefarm.ResourceDevicePool(), + "aws_devicefarm_instance_profile": devicefarm.ResourceInstanceProfile(), + "aws_devicefarm_network_profile": devicefarm.ResourceNetworkProfile(), + "aws_devicefarm_project": devicefarm.ResourceProject(), + "aws_devicefarm_test_grid_project": devicefarm.ResourceTestGridProject(), + "aws_devicefarm_upload": devicefarm.ResourceUpload(), "aws_detective_graph": detective.ResourceGraph(), "aws_detective_invitation_accepter": detective.ResourceInvitationAccepter(), diff --git a/internal/service/devicefarm/find.go b/internal/service/devicefarm/find.go index 8a52c2fd780..b60dd608d9d 100644 --- a/internal/service/devicefarm/find.go +++ b/internal/service/devicefarm/find.go @@ -132,3 +132,28 @@ func FindInstanceProfileByArn(conn *devicefarm.DeviceFarm, arn string) (*devicef return output.InstanceProfile, nil } + +func FindTestGridProjectByArn(conn *devicefarm.DeviceFarm, arn string) (*devicefarm.TestGridProject, error) { + + input := &devicefarm.GetTestGridProjectInput{ + ProjectArn: aws.String(arn), + } + output, err := conn.GetTestGridProject(input) + + if tfawserr.ErrCodeEquals(err, devicefarm.ErrCodeNotFoundException) { + return nil, &resource.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil || output.TestGridProject == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + return output.TestGridProject, nil +} diff --git a/internal/service/devicefarm/sweep.go b/internal/service/devicefarm/sweep.go index e5517412a51..989c4d37912 100644 --- a/internal/service/devicefarm/sweep.go +++ b/internal/service/devicefarm/sweep.go @@ -20,6 +20,11 @@ func init() { Name: "aws_devicefarm_project", F: sweepProjects, }) + + resource.AddTestSweepers("aws_devicefarm_test_grid_project", &resource.Sweeper{ + Name: "aws_devicefarm_test_grid_project", + F: sweepTestGridProjects, + }) } func sweepProjects(region string) error { @@ -75,3 +80,57 @@ func sweepProjects(region string) error { return errs.ErrorOrNil() } + +func sweepTestGridProjects(region string) error { + client, err := sweep.SharedRegionalSweepClient(region) + + if err != nil { + return fmt.Errorf("error getting client: %w", err) + } + + conn := client.(*conns.AWSClient).DeviceFarmConn + sweepResources := make([]*sweep.SweepResource, 0) + var errs *multierror.Error + + input := &devicefarm.ListTestGridProjectsInput{} + + err = conn.ListTestGridProjectsPages(input, func(page *devicefarm.ListTestGridProjectsOutput, lastPage bool) bool { + if page == nil { + return !lastPage + } + + for _, project := range page.TestGridProjects { + r := ResourceTestGridProject() + d := r.Data(nil) + + id := aws.StringValue(project.Arn) + d.SetId(id) + + if err != nil { + err := fmt.Errorf("error reading DeviceFarm Project (%s): %w", id, err) + log.Printf("[ERROR] %s", err) + errs = multierror.Append(errs, err) + continue + } + + sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) + } + + return !lastPage + }) + + if err != nil { + errs = multierror.Append(errs, fmt.Errorf("error listing DeviceFarm Test Grid Project for %s: %w", region, err)) + } + + if err := sweep.SweepOrchestrator(sweepResources); err != nil { + errs = multierror.Append(errs, fmt.Errorf("error sweeping DeviceFarm Test Grid Project for %s: %w", region, err)) + } + + if sweep.SkipSweepError(err) { + log.Printf("[WARN] Skipping DeviceFarm Test Grid Project sweep for %s: %s", region, errs) + return nil + } + + return errs.ErrorOrNil() +} diff --git a/internal/service/devicefarm/test_grid_project.go b/internal/service/devicefarm/test_grid_project.go new file mode 100644 index 00000000000..ecb64be035a --- /dev/null +++ b/internal/service/devicefarm/test_grid_project.go @@ -0,0 +1,239 @@ +package devicefarm + +import ( + "fmt" + "log" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/devicefarm" + "github.com/hashicorp/aws-sdk-go-base/tfawserr" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/flex" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/internal/verify" +) + +func ResourceTestGridProject() *schema.Resource { + return &schema.Resource{ + Create: resourceTestGridProjectCreate, + Read: resourceTestGridProjectRead, + Update: resourceTestGridProjectUpdate, + Delete: resourceTestGridProjectDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringLenBetween(0, 256), + }, + "description": { + Type: schema.TypeString, + Optional: true, + }, + "tags": tftags.TagsSchema(), + "tags_all": tftags.TagsSchemaComputed(), + "vpc_config": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "security_group_ids": { + Type: schema.TypeSet, + MinItems: 1, + Elem: &schema.Schema{Type: schema.TypeString}, + Required: true, + }, + "subnet_ids": { + Type: schema.TypeSet, + MinItems: 1, + Elem: &schema.Schema{Type: schema.TypeString}, + Required: true, + }, + "vpc_id": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + }, + CustomizeDiff: verify.SetTagsDiff, + } +} + +func resourceTestGridProjectCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*conns.AWSClient).DeviceFarmConn + defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig + tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{}))) + + name := d.Get("name").(string) + input := &devicefarm.CreateTestGridProjectInput{ + Name: aws.String(name), + } + + if v, ok := d.GetOk("description"); ok { + input.Description = aws.String(v.(string)) + } + + if v, ok := d.GetOk("vpc_config"); ok { + input.VpcConfig = expandTestGridProjectVpcConfig(v.([]interface{})) + } + + log.Printf("[DEBUG] Creating DeviceFarm Test Grid Project: %s", name) + out, err := conn.CreateTestGridProject(input) + if err != nil { + return fmt.Errorf("Error creating DeviceFarm Test Grid Project: %w", err) + } + + arn := aws.StringValue(out.TestGridProject.Arn) + log.Printf("[DEBUG] Successsfully Created DeviceFarm Test Grid Project: %s", arn) + d.SetId(arn) + + if len(tags) > 0 { + if err := UpdateTags(conn, arn, nil, tags); err != nil { + return fmt.Errorf("error updating DeviceFarm Test Grid Project (%s) tags: %w", arn, err) + } + } + + return resourceTestGridProjectRead(d, meta) +} + +func resourceTestGridProjectRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*conns.AWSClient).DeviceFarmConn + defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig + ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig + + project, err := FindTestGridProjectByArn(conn, d.Id()) + + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] DeviceFarm Test Grid Project (%s) not found, removing from state", d.Id()) + d.SetId("") + return nil + } + + if err != nil { + return fmt.Errorf("error reading DeviceFarm Test Grid Project (%s): %w", d.Id(), err) + } + + arn := aws.StringValue(project.Arn) + d.Set("name", project.Name) + d.Set("arn", arn) + d.Set("description", project.Description) + if err := d.Set("vpc_config", flattenTestGridProjectVpcConfig(project.VpcConfig)); err != nil { + return fmt.Errorf("error setting vpc_config: %w", err) + } + + tags, err := ListTags(conn, arn) + + if err != nil { + return fmt.Errorf("error listing tags for DeviceFarm Test Grid Project (%s): %w", arn, err) + } + + tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) + + //lintignore:AWSR002 + if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { + return fmt.Errorf("error setting tags: %w", err) + } + + if err := d.Set("tags_all", tags.Map()); err != nil { + return fmt.Errorf("error setting tags_all: %w", err) + } + + return nil +} + +func resourceTestGridProjectUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*conns.AWSClient).DeviceFarmConn + + if d.HasChangesExcept("tags", "tags_all") { + input := &devicefarm.UpdateTestGridProjectInput{ + ProjectArn: aws.String(d.Id()), + } + + if d.HasChange("name") { + input.Name = aws.String(d.Get("name").(string)) + } + + if d.HasChange("description") { + input.Description = aws.String(d.Get("description").(string)) + } + + log.Printf("[DEBUG] Updating DeviceFarm Test Grid Project: %s", d.Id()) + _, err := conn.UpdateTestGridProject(input) + if err != nil { + return fmt.Errorf("Error Updating DeviceFarm Test Grid Project: %w", err) + } + } + + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") + + if err := UpdateTags(conn, d.Get("arn").(string), o, n); err != nil { + return fmt.Errorf("error updating DeviceFarm Test Grid Project (%s) tags: %w", d.Get("arn").(string), err) + } + } + + return resourceTestGridProjectRead(d, meta) +} + +func resourceTestGridProjectDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*conns.AWSClient).DeviceFarmConn + + input := &devicefarm.DeleteTestGridProjectInput{ + ProjectArn: aws.String(d.Id()), + } + + log.Printf("[DEBUG] Deleting DeviceFarm Test Grid Project: %s", d.Id()) + _, err := conn.DeleteTestGridProject(input) + if err != nil { + if tfawserr.ErrCodeEquals(err, devicefarm.ErrCodeNotFoundException) { + return nil + } + return fmt.Errorf("Error deleting DeviceFarm Test Grid Project: %w", err) + } + + return nil +} + +func expandTestGridProjectVpcConfig(l []interface{}) *devicefarm.TestGridVpcConfig { + if len(l) == 0 { + return nil + } + + m := l[0].(map[string]interface{}) + + config := &devicefarm.TestGridVpcConfig{ + VpcId: aws.String(m["vpc_id"].(string)), + SubnetIds: flex.ExpandStringSet(m["subnet_ids"].(*schema.Set)), + SecurityGroupIds: flex.ExpandStringSet(m["security_group_ids"].(*schema.Set)), + } + + return config +} + +func flattenTestGridProjectVpcConfig(conf *devicefarm.TestGridVpcConfig) []interface{} { + if conf == nil { + return []interface{}{} + } + + m := map[string]interface{}{ + "vpc_id": aws.StringValue(conf.VpcId), + "subnet_ids": flex.FlattenStringSet(conf.SubnetIds), + "security_group_ids": flex.FlattenStringSet(conf.SecurityGroupIds), + } + + return []interface{}{m} +} diff --git a/internal/service/devicefarm/test_grid_project_test.go b/internal/service/devicefarm/test_grid_project_test.go new file mode 100644 index 00000000000..47d5c7b3d93 --- /dev/null +++ b/internal/service/devicefarm/test_grid_project_test.go @@ -0,0 +1,302 @@ +package devicefarm_test + +import ( + "fmt" + "regexp" + "testing" + + "github.com/aws/aws-sdk-go/aws/endpoints" + "github.com/aws/aws-sdk-go/service/devicefarm" + sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + tfdevicefarm "github.com/hashicorp/terraform-provider-aws/internal/service/devicefarm" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" +) + +func TestAccDeviceFarmTestGridProject_basic(t *testing.T) { + var proj devicefarm.TestGridProject + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rNameUpdated := sdkacctest.RandomWithPrefix("tf-acc-test-updated") + resourceName := "aws_devicefarm_test_grid_project.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(devicefarm.EndpointsID, t) + // Currently, DeviceFarm is only supported in us-west-2 + // https://docs.aws.amazon.com/general/latest/gr/devicefarm.html + acctest.PreCheckRegion(t, endpoints.UsWest2RegionID) + }, + ErrorCheck: acctest.ErrorCheck(t, devicefarm.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckDeviceFarmProjectTestGridProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDeviceFarmProjectTestGridProjectConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckDeviceFarmProjectTestGridProjectExists(resourceName, &proj), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "vpc_config.#", "0"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "devicefarm", regexp.MustCompile(`testgrid-project:.+`)), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDeviceFarmProjectTestGridProjectConfig(rNameUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckDeviceFarmProjectTestGridProjectExists(resourceName, &proj), + resource.TestCheckResourceAttr(resourceName, "name", rNameUpdated), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "devicefarm", regexp.MustCompile(`testgrid-project:.+`)), + ), + }, + }, + }) +} + +func TestAccDeviceFarmTestGridProject_vpc(t *testing.T) { + var proj devicefarm.TestGridProject + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_devicefarm_test_grid_project.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(devicefarm.EndpointsID, t) + // Currently, DeviceFarm is only supported in us-west-2 + // https://docs.aws.amazon.com/general/latest/gr/devicefarm.html + acctest.PreCheckRegion(t, endpoints.UsWest2RegionID) + }, + ErrorCheck: acctest.ErrorCheck(t, devicefarm.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckDeviceFarmProjectTestGridProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDeviceFarmProjectTestGridProjectVpcConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckDeviceFarmProjectTestGridProjectExists(resourceName, &proj), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "vpc_config.#", "1"), + resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.vpc_id", "aws_vpc.test", "id"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccDeviceFarmTestGridProject_tags(t *testing.T) { + var proj devicefarm.TestGridProject + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_devicefarm_test_grid_project.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(devicefarm.EndpointsID, t) + // Currently, DeviceFarm is only supported in us-west-2 + // https://docs.aws.amazon.com/general/latest/gr/devicefarm.html + acctest.PreCheckRegion(t, endpoints.UsWest2RegionID) + }, + ErrorCheck: acctest.ErrorCheck(t, devicefarm.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckDeviceFarmProjectTestGridProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDeviceFarmProjectTestGridProjectConfigTags1(rName, "key1", "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckDeviceFarmProjectTestGridProjectExists(resourceName, &proj), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDeviceFarmProjectTestGridProjectConfigTags2(rName, "key1", "value1updated", "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckDeviceFarmProjectTestGridProjectExists(resourceName, &proj), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccDeviceFarmProjectTestGridProjectConfigTags1(rName, "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckDeviceFarmProjectTestGridProjectExists(resourceName, &proj), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + }, + }) +} + +func TestAccDeviceFarmTestGridProject_disappears(t *testing.T) { + var proj devicefarm.TestGridProject + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_devicefarm_test_grid_project.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(devicefarm.EndpointsID, t) + // Currently, DeviceFarm is only supported in us-west-2 + // https://docs.aws.amazon.com/general/latest/gr/devicefarm.html + acctest.PreCheckRegion(t, endpoints.UsWest2RegionID) + }, + ErrorCheck: acctest.ErrorCheck(t, devicefarm.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckDeviceFarmProjectTestGridProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDeviceFarmProjectTestGridProjectConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckDeviceFarmProjectTestGridProjectExists(resourceName, &proj), + acctest.CheckResourceDisappears(acctest.Provider, tfdevicefarm.ResourceTestGridProject(), resourceName), + acctest.CheckResourceDisappears(acctest.Provider, tfdevicefarm.ResourceTestGridProject(), resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func testAccCheckDeviceFarmProjectTestGridProjectExists(n string, v *devicefarm.TestGridProject) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No ID is set") + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).DeviceFarmConn + resp, err := tfdevicefarm.FindTestGridProjectByArn(conn, rs.Primary.ID) + if err != nil { + return err + } + if resp == nil { + return fmt.Errorf("DeviceFarm Test Grid Project not found") + } + + *v = *resp + + return nil + } +} + +func testAccCheckDeviceFarmProjectTestGridProjectDestroy(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).DeviceFarmConn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_devicefarm_test_grid_project" { + continue + } + + // Try to find the resource + _, err := tfdevicefarm.FindTestGridProjectByArn(conn, rs.Primary.ID) + if tfresource.NotFound(err) { + continue + } + + if err != nil { + return err + } + + return fmt.Errorf("DeviceFarm Test Grid Project %s still exists", rs.Primary.ID) + } + + return nil +} + +func testAccDeviceFarmProjectTestGridProjectConfig(rName string) string { + return fmt.Sprintf(` +resource "aws_devicefarm_test_grid_project" "test" { + name = %[1]q +} +`, rName) +} + +func testAccDeviceFarmProjectTestGridProjectVpcConfig(rName string) string { + return acctest.ConfigCompose( + acctest.ConfigAvailableAZsNoOptIn(), + fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" +} + +resource "aws_subnet" "test" { + count = 2 + availability_zone = data.aws_availability_zones.available.names[count.index] + cidr_block = "10.0.${count.index}.0/24" + vpc_id = aws_vpc.test.id +} + +resource "aws_security_group" "test" { + count = 2 + + name = "%[1]s-${count.index}" + description = "Allow all inbound traffic" + vpc_id = aws_vpc.test.id + ingress { + protocol = "6" + from_port = 80 + to_port = 8000 + cidr_blocks = [aws_vpc.test.cidr_block] + } +} + +resource "aws_devicefarm_test_grid_project" "test" { + name = %[1]q + + vpc_config { + vpc_id = aws_vpc.test.id + subnet_ids = aws_subnet.test.*.id + security_group_ids = aws_security_group.test.*.id + } +} +`, rName)) +} + +func testAccDeviceFarmProjectTestGridProjectConfigTags1(rName, tagKey1, tagValue1 string) string { + return fmt.Sprintf(` +resource "aws_devicefarm_test_grid_project" "test" { + name = %[1]q + + tags = { + %[2]q = %[3]q + } +} +`, rName, tagKey1, tagValue1) +} + +func testAccDeviceFarmProjectTestGridProjectConfigTags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return fmt.Sprintf(` +resource "aws_devicefarm_test_grid_project" "test" { + name = %[1]q + + tags = { + %[2]q = %[3]q + %[4]q = %[5]q + } +} +`, rName, tagKey1, tagValue1, tagKey2, tagValue2) +} diff --git a/website/docs/r/devicefarm_test_grid_project.html.markdown b/website/docs/r/devicefarm_test_grid_project.html.markdown new file mode 100644 index 00000000000..1221091c93f --- /dev/null +++ b/website/docs/r/devicefarm_test_grid_project.html.markdown @@ -0,0 +1,57 @@ +--- +subcategory: "Device Farm" +layout: "aws" +page_title: "AWS: aws_devicefarm_test_grid_project" +description: |- + Provides a Devicefarm test_grid_project +--- + +# Resource: aws_devicefarm_test_grid_project + +Provides a resource to manage AWS Device Farm Test Grid Projects. + +~> **NOTE:** AWS currently has limited regional support for Device Farm (e.g., `us-west-2`). See [AWS Device Farm endpoints and quotas](https://docs.aws.amazon.com/general/latest/gr/devicefarm.html) for information on supported regions. + +## Example Usage + + +```terraform +resource "aws_devicefarm_test_grid_project" "example" { + name = "example" + + vpc_config { + vpc_id = aws_vpc.example.id + subnet_ids = aws_subnet.example.*.id + security_group_ids = aws_security_group.example.*.id + } +} +``` + +## Argument Reference + +* `name` - (Required) The name of the Selenium testing project. +* `description` - (Optional) Human-readable description of the project. +* `vpc_config` - (Required) The VPC security groups and subnets that are attached to a project. See [VPC Config](#vpc-config) below. +* `tags` - (Optional) A map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. + +### VPC Config + +* `security_group_ids` - (Required) A list of VPC security group IDs in your Amazon VPC. +* `subnet_ids` - (Required) A list of VPC subnet IDs in your Amazon VPC. +* `vpc_id` - (Required) The ID of the Amazon VPC. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `arn` - The Amazon Resource Name of this Test Grid Project. +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block). + + +## Import + +DeviceFarm Test Grid Projects can be imported by their arn: + +``` +$ terraform import aws_devicefarm_test_grid_project.example arn:aws:devicefarm:us-west-2:123456789012:test_grid_project:4fa784c7-ccb4-4dbf-ba4f-02198320daa1 +``` From c1006c23be4ee61ff3383a0acd702b56917993b0 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 20 Jan 2022 18:07:12 +0200 Subject: [PATCH 2/3] fix import stmt --- website/docs/r/devicefarm_test_grid_project.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/devicefarm_test_grid_project.html.markdown b/website/docs/r/devicefarm_test_grid_project.html.markdown index 1221091c93f..5a1ecd964dd 100644 --- a/website/docs/r/devicefarm_test_grid_project.html.markdown +++ b/website/docs/r/devicefarm_test_grid_project.html.markdown @@ -53,5 +53,5 @@ In addition to all arguments above, the following attributes are exported: DeviceFarm Test Grid Projects can be imported by their arn: ``` -$ terraform import aws_devicefarm_test_grid_project.example arn:aws:devicefarm:us-west-2:123456789012:test_grid_project:4fa784c7-ccb4-4dbf-ba4f-02198320daa1 +$ terraform import aws_devicefarm_test_grid_project.example arn:aws:devicefarm:us-west-2:123456789012:testgrid-project:4fa784c7-ccb4-4dbf-ba4f-02198320daa1 ``` From 5d97e13031a3de4827220f03c4cdbd35c993d004 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 20 Jan 2022 23:41:22 +0200 Subject: [PATCH 3/3] changelog --- .changelog/22688.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/22688.txt diff --git a/.changelog/22688.txt b/.changelog/22688.txt new file mode 100644 index 00000000000..74b0010df9c --- /dev/null +++ b/.changelog/22688.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +aws_devicefarm_test_grid_project +```