Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

f-CodeCatalyst-DevEnvironment Datasource #32886

Merged
merged 8 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/32886.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-data-source
aws_codecatalyst_dev_environment
```

```release-note:note
data-source/aws_codecatalyst_dev_environment: Because we cannot easily test this functionality, it is best effort and we ask for community help in testing
```
156 changes: 156 additions & 0 deletions internal/service/codecatalyst/dev_environment_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package codecatalyst

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)

// Function annotations are used for datasource registration to the Provider. DO NOT EDIT.
// @SDKDataSource("aws_codecatalyst_dev_environment", name="Dev Environment")
func DataSourceDevEnvironment() *schema.Resource {
return &schema.Resource{

ReadWithoutTimeout: dataSourceDevEnvironmentRead,

Schema: map[string]*schema.Schema{
"alias": {
Type: schema.TypeString,
Optional: true,
},
"creator_id": {
Type: schema.TypeString,
Optional: true,
},
"env_id": {
Type: schema.TypeString,
Required: true,
},
"ides": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"runtime": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"inactivity_timeout_minutes": {
Type: schema.TypeInt,
Computed: true,
},
"instance_type": {
Type: schema.TypeString,
Computed: true,
},
"last_updated_time": {
Type: schema.TypeString,
Computed: true,
},
"persistent_storage": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"size": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"project_name": {
Type: schema.TypeString,
Required: true,
},
"repositories": {
Type: schema.TypeList,
Optional: true,
MaxItems: 100,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"branch_name": {
Type: schema.TypeString,
Computed: true,
},
"repository_name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"space_name": {
Type: schema.TypeString,
Required: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"status_reason": {
Type: schema.TypeString,
Computed: true,
},
"tags": tftags.TagsSchemaComputed(),
},
}
}

const (
DSNameDevEnvironment = "Dev Environment Data Source"
)

func dataSourceDevEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

conn := meta.(*conns.AWSClient).CodeCatalystClient(ctx)

spaceName := aws.String(d.Get("space_name").(string))
projectName := aws.String(d.Get("project_name").(string))
env_id := d.Get("env_id").(string)

out, err := findDevEnvironmentByID(ctx, conn, env_id, spaceName, projectName)
if err != nil {
return append(diags, create.DiagError(names.CodeCatalyst, create.ErrActionReading, DSNameDevEnvironment, d.Id(), err)...)
}

d.SetId(aws.ToString(out.Id))

d.Set("alias", out.Alias)
d.Set("creator_id", out.CreatorId)
d.Set("project_name", out.ProjectName)
d.Set("space_name", out.SpaceName)
d.Set("instance_type", out.InstanceType)
d.Set("last_updated_time", out.LastUpdatedTime.String())
d.Set("inactivity_timeout_minutes", out.InactivityTimeoutMinutes)
d.Set("persistent_storage", flattenPersistentStorage(out.PersistentStorage))
d.Set("status", out.Status)
d.Set("status_reason", out.StatusReason)

if err := d.Set("ides", flattenIdes(out.Ides)); err != nil {
return append(diags, create.DiagError(names.CodeCatalyst, create.ErrActionSetting, ResNameDevEnvironment, d.Id(), err)...)
}

if err := d.Set("repositories", flattenRepositories(out.Repositories)); err != nil {
return append(diags, create.DiagError(names.CodeCatalyst, create.ErrActionSetting, ResNameDevEnvironment, d.Id(), err)...)
}

return diags
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package codecatalyst_test

import (
"fmt"
"testing"

sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/names"
)

func TestAccCodeCatalystDevEnvironmentDataSource_basic(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
dataSourceName := "data.aws_codecatalyst_dev_environment.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CodeCatalyst)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CodeCatalyst),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDevEnvironmentDataSourceConfig_basic(rName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "space_name", "tf-cc-aws-provider"),
resource.TestCheckResourceAttr(dataSourceName, "project_name", "tf-cc"),
),
},
},
})
}

func testAccDevEnvironmentDataSourceConfig_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_codecatalyst_dev_environment" "test" {
alias = %[1]q
space_name = "tf-cc-aws-provider"
project_name = "tf-cc"
instance_type = "dev.standard1.small"
persistent_storage {
size = 16
}
ides {
name = "VSCode"
}
}

data "aws_codecatalyst_dev_environment" "test" {
space_name = "tf-cc-aws-provider"
project_name = "tf-cc"
env_id = aws_codecatalyst_dev_environment.test.id
}
`, rName)
}
19 changes: 16 additions & 3 deletions internal/service/codecatalyst/dev_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ func TestAccCodeCatalystDevEnvironment_basic(t *testing.T) {
resourceName := "aws_codecatalyst_dev_environment.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CodeCatalyst)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CodeCatalyst),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDevEnvironmentDestroy(ctx),
Expand Down Expand Up @@ -58,7 +62,11 @@ func TestAccCodeCatalystDevEnvironment_withRepositories(t *testing.T) {
resourceName := "aws_codecatalyst_dev_environment.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CodeCatalyst)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CodeCatalyst),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDevEnvironmentDestroy(ctx),
Expand Down Expand Up @@ -87,8 +95,13 @@ func TestAccCodeCatalystDevEnvironment_disappears(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
var DevEnvironment codecatalyst.GetDevEnvironmentOutput
resourceName := "aws_codecatalyst_dev_environment.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CodeCatalyst)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CodeCatalyst),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDevEnvironmentDestroy(ctx),
Expand Down
17 changes: 10 additions & 7 deletions internal/service/codecatalyst/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ import (

func TestAccCodeCatalystProject_basic(t *testing.T) {
ctx := acctest.Context(t)

var project codecatalyst.GetProjectOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_codecatalyst_project.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CodeCatalyst)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CodeCatalyst),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckProjectDestroy(ctx),
Expand All @@ -50,16 +53,16 @@ func TestAccCodeCatalystProject_basic(t *testing.T) {

func TestAccCodeCatalystProject_disappears(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var project codecatalyst.GetProjectOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_codecatalyst_project.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.CodeCatalyst)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.CodeCatalyst),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckProjectDestroy(ctx),
Expand Down
8 changes: 7 additions & 1 deletion internal/service/codecatalyst/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions website/docs/d/codecatalyst_dev_environment.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
subcategory: "CodeCatalyst"
layout: "aws"
page_title: "AWS: aws_codecatalyst_dev_environment"
description: |-
Terraform data source for managing an AWS CodeCatalyst Dev Environment.
---
# Data Source: aws_codecatalyst_dev_environment

Terraform data source for managing an AWS CodeCatalyst Dev Environment.

## Example Usage

### Basic Usage

```terraform
data "aws_codecatalyst_dev_environment" "example" {
space_name = "myspace"
project_name = "myproject"
env_id = aws_codecatalyst_dev_environment.example.id
}
```

## Argument Reference

The following arguments are required:

* `env_id` - - (Required) The system-generated unique ID of the Dev Environment for which you want to view information. To retrieve a list of Dev Environment IDs, use [ListDevEnvironments](https://docs.aws.amazon.com/codecatalyst/latest/APIReference/API_ListDevEnvironments.html).
* `project_name` - (Required) The name of the project in the space.
* `space_name` - (Required) The name of the space.

## Attribute Reference

This data source exports the following attributes in addition to the arguments above:

* `alias` - The user-specified alias for the Dev Environment.
* `creator_id` - The system-generated unique ID of the user who created the Dev Environment.
* `ides` - Information about the integrated development environment (IDE) configured for a Dev Environment.
* `inactivity_timeout_minutes` - The amount of time the Dev Environment will run without any activity detected before stopping, in minutes. Only whole integers are allowed. Dev Environments consume compute minutes when running.
* `instance_type` - The Amazon EC2 instace type to use for the Dev Environment.
* `last_updated_time` - The time when the Dev Environment was last updated, in coordinated universal time (UTC) timestamp format as specified in [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339#section-5.6).
* `persistent_storage` - Information about the amount of storage allocated to the Dev Environment.
* `repositories` - The source repository that contains the branch to clone into the Dev Environment.
* `status` - The current status of the Dev Environment. From: PENDING | RUNNING | STARTING | STOPPING | STOPPED | FAILED | DELETING | DELETED.
* `status_reason` - The reason for the status.
Loading