-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
aws_appconfig data sources #27054
Merged
Merged
aws_appconfig data sources #27054
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,15 @@ | ||
```release-note:new-data-source | ||
aws_appconfig_environment | ||
``` | ||
|
||
```release-note:new-data-source | ||
aws_appconfig_environments | ||
``` | ||
|
||
```release-note:new-data-source | ||
aws_appconfig_configuration_profile | ||
``` | ||
|
||
```release-note:new-data-source | ||
aws_appconfig_configuration_profiles | ||
``` |
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
146 changes: 146 additions & 0 deletions
146
internal/service/appconfig/configuration_profile_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,146 @@ | ||
package appconfig | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"regexp" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go/aws/arn" | ||
"github.com/aws/aws-sdk-go/service/appconfig" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"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/create" | ||
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
func DataSourceConfigurationProfile() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadWithoutTimeout: dataSourceConfigurationProfileRead, | ||
Schema: map[string]*schema.Schema{ | ||
"application_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringMatch(regexp.MustCompile(`[a-z\d]{4,7}`), ""), | ||
}, | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"configuration_profile_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringMatch(regexp.MustCompile(`[a-z\d]{4,7}`), ""), | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"location_uri": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"retrieval_role_arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tags": tftags.TagsSchemaComputed(), | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"validator": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"content": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
const ( | ||
DSNameConfigurationProfile = "Configuration Profile Data Source" | ||
) | ||
|
||
func dataSourceConfigurationProfileRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*conns.AWSClient).AppConfigConn | ||
|
||
appId := d.Get("application_id").(string) | ||
profileId := d.Get("configuration_profile_id").(string) | ||
ID := fmt.Sprintf("%s:%s", profileId, appId) | ||
|
||
out, err := findConfigurationProfileByApplicationAndProfile(ctx, conn, appId, profileId) | ||
if err != nil { | ||
return create.DiagError(names.AppConfig, create.ErrActionReading, DSNameConfigurationProfile, ID, err) | ||
} | ||
|
||
d.SetId(ID) | ||
|
||
d.Set("application_id", appId) | ||
|
||
arn := arn.ARN{ | ||
AccountID: meta.(*conns.AWSClient).AccountID, | ||
Partition: meta.(*conns.AWSClient).Partition, | ||
Region: meta.(*conns.AWSClient).Region, | ||
Resource: fmt.Sprintf("application/%s/configurationprofile/%s", appId, profileId), | ||
Service: "appconfig", | ||
}.String() | ||
|
||
d.Set("arn", arn) | ||
d.Set("configuration_profile_id", profileId) | ||
d.Set("description", out.Description) | ||
d.Set("location_uri", out.LocationUri) | ||
d.Set("name", out.Name) | ||
d.Set("retrieval_role_arn", out.RetrievalRoleArn) | ||
d.Set("type", out.Type) | ||
|
||
if err := d.Set("validator", flattenValidators(out.Validators)); err != nil { | ||
return create.DiagError(names.AppConfig, create.ErrActionSetting, DSNameConfigurationProfile, ID, err) | ||
} | ||
|
||
tags, err := ListTags(conn, arn) | ||
if err != nil { | ||
return create.DiagError(names.AppConfig, create.ErrActionReading, DSNameConfigurationProfile, ID, err) | ||
} | ||
|
||
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig | ||
tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) | ||
|
||
//lintignore:AWSR002 | ||
if err := d.Set("tags", tags.Map()); err != nil { | ||
return create.DiagError(names.AppConfig, create.ErrActionSetting, DSNameConfigurationProfile, ID, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func findConfigurationProfileByApplicationAndProfile(ctx context.Context, conn *appconfig.AppConfig, appId string, cpId string) (*appconfig.GetConfigurationProfileOutput, error) { | ||
res, err := conn.GetConfigurationProfileWithContext(ctx, &appconfig.GetConfigurationProfileInput{ | ||
ApplicationId: aws.String(appId), | ||
ConfigurationProfileId: aws.String(cpId), | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |
80 changes: 80 additions & 0 deletions
80
internal/service/appconfig/configuration_profile_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,80 @@ | ||
package appconfig_test | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/appconfig" | ||
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
) | ||
|
||
func TestAccAppConfigConfigurationProfileDataSource_basic(t *testing.T) { | ||
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
appName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
appResourceName := "aws_appconfig_application.test" | ||
dataSourceName := "data.aws_appconfig_configuration_profile.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acctest.PreCheck(t) | ||
acctest.PreCheckPartitionHasService(appconfig.EndpointsID, t) | ||
}, | ||
ErrorCheck: acctest.ErrorCheck(t, appconfig.EndpointsID), | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
CheckDestroy: testAccCheckConfigurationProfileDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccConfigurationProfileDataSourceConfig_basic(appName, rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "application_id", appResourceName, "id"), | ||
acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "appconfig", regexp.MustCompile(`application/([a-z\d]{4,7})/configurationprofile/+.`)), | ||
resource.TestMatchResourceAttr(dataSourceName, "configuration_profile_id", regexp.MustCompile(`[a-z\d]{4,7}`)), | ||
resource.TestCheckResourceAttr(dataSourceName, "location_uri", "hosted"), | ||
resource.TestCheckResourceAttr(dataSourceName, "name", rName), | ||
resource.TestCheckResourceAttr(dataSourceName, "retrieval_role_arn", ""), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.key1", "value1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "type", "AWS.Freeform"), | ||
resource.TestCheckTypeSetElemNestedAttrs(dataSourceName, "validator.*", map[string]string{ | ||
"content": "{\"$schema\":\"http://json-schema.org/draft-05/schema#\",\"description\":\"BasicFeatureToggle-1\",\"title\":\"$id$\"}", | ||
"type": appconfig.ValidatorTypeJsonSchema, | ||
}), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccConfigurationProfileDataSourceConfig_basic(appName, rName string) string { | ||
return acctest.ConfigCompose( | ||
testAccApplicationConfig_name(appName), | ||
fmt.Sprintf(` | ||
resource "aws_appconfig_configuration_profile" "test" { | ||
application_id = aws_appconfig_application.test.id | ||
name = %[1]q | ||
location_uri = "hosted" | ||
|
||
validator { | ||
content = jsonencode({ | ||
"$schema" = "http://json-schema.org/draft-05/schema#" | ||
title = "$id$" | ||
description = "BasicFeatureToggle-1" | ||
}) | ||
|
||
type = "JSON_SCHEMA" | ||
} | ||
|
||
tags = { | ||
key1 = "value1" | ||
} | ||
} | ||
|
||
data "aws_appconfig_configuration_profile" "test" { | ||
application_id = aws_appconfig_application.test.id | ||
configuration_profile_id = aws_appconfig_configuration_profile.test.configuration_profile_id | ||
} | ||
`, rName)) | ||
} |
71 changes: 71 additions & 0 deletions
71
internal/service/appconfig/configuration_profiles_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,71 @@ | ||
package appconfig | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/appconfig" | ||
"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" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
func DataSourceConfigurationProfiles() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadWithoutTimeout: dataSourceConfigurationProfilesRead, | ||
Schema: map[string]*schema.Schema{ | ||
"application_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"configuration_profile_ids": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
const ( | ||
DSNameConfigurationProfiles = "Configuration Profiles Data Source" | ||
) | ||
|
||
func dataSourceConfigurationProfilesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*conns.AWSClient).AppConfigConn | ||
appId := d.Get("application_id").(string) | ||
|
||
out, err := findConfigurationProfileSummariesByApplication(ctx, conn, appId) | ||
if err != nil { | ||
return create.DiagError(names.AppConfig, create.ErrActionReading, DSNameConfigurationProfiles, appId, err) | ||
} | ||
|
||
d.SetId(appId) | ||
|
||
var configIds []*string | ||
for _, v := range out { | ||
configIds = append(configIds, v.Id) | ||
} | ||
|
||
d.Set("configuration_profile_ids", aws.StringValueSlice(configIds)) | ||
|
||
return nil | ||
} | ||
|
||
func findConfigurationProfileSummariesByApplication(ctx context.Context, conn *appconfig.AppConfig, applicationId string) ([]*appconfig.ConfigurationProfileSummary, error) { | ||
var outputs []*appconfig.ConfigurationProfileSummary | ||
err := conn.ListConfigurationProfilesPagesWithContext(ctx, &appconfig.ListConfigurationProfilesInput{ | ||
ApplicationId: aws.String(applicationId), | ||
}, func(output *appconfig.ListConfigurationProfilesOutput, lastPage bool) bool { | ||
outputs = append(outputs, output.Items...) | ||
return !lastPage | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return outputs, nil | ||
} |
61 changes: 61 additions & 0 deletions
61
internal/service/appconfig/configuration_profiles_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,61 @@ | ||
package appconfig_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/appconfig" | ||
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
) | ||
|
||
func TestAccAppConfigConfigurationProfilesDataSource_basic(t *testing.T) { | ||
rName1 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
appName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
dataSourceName := "data.aws_appconfig_configuration_profiles.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acctest.PreCheck(t) | ||
acctest.PreCheckPartitionHasService(appconfig.EndpointsID, t) | ||
}, | ||
ErrorCheck: acctest.ErrorCheck(t, appconfig.EndpointsID), | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
CheckDestroy: testAccCheckConfigurationProfileDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccConfigurationProfilesDataSourceConfig_basic(appName, rName1, rName2), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "configuration_profile_ids.#", "2"), | ||
resource.TestCheckTypeSetElemAttrPair(dataSourceName, "configuration_profile_ids.*", "aws_appconfig_configuration_profile.test_1", "configuration_profile_id"), | ||
resource.TestCheckTypeSetElemAttrPair(dataSourceName, "configuration_profile_ids.*", "aws_appconfig_configuration_profile.test_2", "configuration_profile_id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccConfigurationProfilesDataSourceConfig_basic(appName, rName1, rName2 string) string { | ||
return acctest.ConfigCompose( | ||
testAccApplicationConfig_name(appName), | ||
fmt.Sprintf(` | ||
resource "aws_appconfig_configuration_profile" "test_1" { | ||
application_id = aws_appconfig_application.test.id | ||
name = %[1]q | ||
location_uri = "hosted" | ||
} | ||
|
||
resource "aws_appconfig_configuration_profile" "test_2" { | ||
application_id = aws_appconfig_application.test.id | ||
name = %[2]q | ||
location_uri = "hosted" | ||
} | ||
|
||
data "aws_appconfig_configuration_profiles" "test" { | ||
application_id = aws_appconfig_application.test.id | ||
depends_on = [aws_appconfig_configuration_profile.test_1, aws_appconfig_configuration_profile.test_2] | ||
} | ||
`, rName1, rName2)) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍