-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32886 from nrajb/f-CodeCatalyst-DevEnv-Ds
f-CodeCatalyst-DevEnvironment Datasource
- Loading branch information
Showing
7 changed files
with
303 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
156
internal/service/codecatalyst/dev_environment_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
62 changes: 62 additions & 0 deletions
62
internal/service/codecatalyst/dev_environment_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |