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

New Resources: aws_licensemanager_grant and aws_licensemanager_grant_accepter, New Datasources: aws_licensemanager_received_license , aws_licensemanager_received_licenses, and aws_licensemanager_grants #29741

Merged
merged 61 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4850000
licensemanager: Add grant
brittandeyoung Mar 1, 2023
967f68e
licensemanager: Add grant_test
brittandeyoung Mar 1, 2023
a6219f2
Merge branch 'main' into f-aws_licensemanager_grant
brittandeyoung Mar 1, 2023
4bb06ad
licensemanager: Amend service_package_gen, add aws_licensemanager_grant
brittandeyoung Mar 1, 2023
b1f2b1b
website: Add licensemanager_grant
brittandeyoung Mar 1, 2023
6045312
licensemanager: Amend grant_test, fmt
brittandeyoung Mar 1, 2023
63c5406
licensemanager: Amend grant, prefer AWS Go SDK pointer conversion
brittandeyoung Mar 1, 2023
0e10d60
licensemanager: Amend grant_test, remove service name from serialized…
brittandeyoung Mar 1, 2023
92151f6
changelog: Add 29741 change log
brittandeyoung Mar 1, 2023
b3acaf3
licensemanager: Amend grant_test, remove static arns
brittandeyoung Mar 1, 2023
9644d68
changelog: Amend 29741, add aws_licensemanager_grant_accepter
brittandeyoung Mar 1, 2023
c2ba419
licensemanager: Add grant_accepter
brittandeyoung Mar 1, 2023
fd4b581
licensemanager: Amend grant, update find parameter name
brittandeyoung Mar 1, 2023
b7c112a
website: Add licensemanager_grant_accepter
brittandeyoung Mar 1, 2023
17fc097
licensemanager: Amend grant, Update home_region to computed field
brittandeyoung Mar 7, 2023
07a1644
website: Amend licensemanager_grant, Proper casing for AWS
brittandeyoung Mar 7, 2023
4849882
licensemanager: Amend grant, improve principal description.
brittandeyoung Mar 7, 2023
0c08cf4
website: Amend licensemanager_grant, improve principal description
brittandeyoung Mar 7, 2023
7b1a6da
licensemanager: Amend grant, improve allowed_operations description
brittandeyoung Mar 7, 2023
fee1b2a
website: Amend licensemanagert_grant, improve allowed_operations desc…
brittandeyoung Mar 7, 2023
6f0e624
licensemanager: Amend generate, add pages function for ListReceivedLi…
brittandeyoung Mar 7, 2023
f383fd9
licensemanager: Add common_schema_data_source
brittandeyoung Mar 7, 2023
e6d3e94
licensemanager: Add received_licenses_data_source
brittandeyoung Mar 7, 2023
ebefd22
licensemanager: Add received_licenses_data_source_test
brittandeyoung Mar 7, 2023
b5d7823
licensemanager: Amend service_package_gen, add aws_licensemanager_rec…
brittandeyoung Mar 7, 2023
ed917ad
website: Add licensemanager_received_licenses
brittandeyoung Mar 7, 2023
373b8ed
licensemanager: Add received_license_data_source
brittandeyoung Mar 7, 2023
891ea41
licensemanager: Add received_license_data_source_test
brittandeyoung Mar 7, 2023
4a7a6a3
licensemanager: Amend received_licenses_data_source_test. testacc-lin…
brittandeyoung Mar 7, 2023
4d73298
licensemanager: Amend grant_test, use datasource for allowed_operations
brittandeyoung Mar 7, 2023
c9f460f
licensemanager: Amend grant, update find method to handle rejected st…
brittandeyoung Mar 8, 2023
08239d8
licensemanager: Amend grant_accepter_test, use data source for testing
brittandeyoung Mar 8, 2023
60d270a
licensemanager: Amend grant_test, proper casing of ARN
brittandeyoung Mar 8, 2023
ea5047c
licensemanager: Amend received_license_data_source, prefer AWS Go SDK…
brittandeyoung Mar 8, 2023
4ee0785
website: Amend licensemanager_received_licenses, fmt fix
brittandeyoung Mar 8, 2023
cf049da
licensemanager: Add licensemanager_received_license
brittandeyoung Mar 8, 2023
1d15440
Merge branch 'main' into f-aws_licensemanager_grant
brittandeyoung Mar 8, 2023
2ed8f9f
licensemanager: Amend service_package_gen, regenerate after merge to …
brittandeyoung Mar 8, 2023
22ba962
changelog: Amend 29741 to add new datasources
brittandeyoung Mar 8, 2023
5a76753
licensemanager: Amend grant_accepter_test, use aws_partition data sou…
brittandeyoung Mar 8, 2023
417d013
licensemanager: Amend received_licenses_data_source, removed un used …
brittandeyoung Mar 8, 2023
8fe75aa
licensemanager: Amend received_licenses_data_source_test, removed un …
brittandeyoung Mar 8, 2023
612d104
licensemanager: Add license_grants_data_source
brittandeyoung Mar 8, 2023
d175735
licensemanager: Add license_gratns_data_source_test
brittandeyoung Mar 8, 2023
47cb62e
licensemanager: Add license_grants to service gen
brittandeyoung Mar 8, 2023
eb31077
website: Add licensemanager_grants data source
brittandeyoung Mar 8, 2023
4f0c5a9
licensemanager: Amend license_grants_data_source_test, move to serial…
brittandeyoung Mar 8, 2023
4b586da
licensemanager: Amend license_grants_data_source_test, lint fix
brittandeyoung Mar 8, 2023
f6072c8
changelog: Amend 29741, add new datasource
brittandeyoung Mar 8, 2023
ce8975b
Converts `create_time` to RFC 3339
gdavison Mar 8, 2023
c10ad6d
Updates received licenses data source to use license key
gdavison Mar 8, 2023
3e06a28
Restores license home region to grant tests
gdavison Mar 8, 2023
2bdeb74
Update license grant data source tests to match grant resource tests
gdavison Mar 8, 2023
b444c62
Serializes all grant-related tests
gdavison Mar 8, 2023
14b1659
Adds more precise test values
gdavison Mar 8, 2023
39c10f3
Uses principal for cross-account tests
gdavison Mar 9, 2023
3d43954
Uses `envvar.SkipIfEmpty` to skip tests when environment variables ar…
gdavison Mar 9, 2023
a86c509
Updates environment variables
gdavison Mar 9, 2023
fa0443d
Cleanup
gdavison Mar 9, 2023
b3de5d7
Adds License Manager acceptance tests to Org Account
gdavison Mar 9, 2023
58653b9
terrafmt
gdavison Mar 9, 2023
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
19 changes: 19 additions & 0 deletions .changelog/29741.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```release-note:new-resource
aws_licensemanager_grant
```

```release-note:new-resource
aws_licensemanager_grant_accepter
```

```release-note:new-data-source
aws_licensemanager_received_license
```

```release-note:new-data-source
aws_licensemanager_received_licenses
```

```release-note:new-data-source
aws_licensemanager_grants
```
1 change: 1 addition & 0 deletions .teamcity/components/generated/service_orgacct.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ val orgacctServices = mapOf(
"config" to ServiceSpec("Config" /*"TestAccConfig_serial|TestAccConfigConfigurationAggregator_"*/),
"fms" to ServiceSpec("FMS"),
"guardduty" to ServiceSpec("GuardDuty"),
"licensemanager" to ServiceSpec("License Manager"),
"macie2" to ServiceSpec("Macie2"),
"organizations" to ServiceSpec("Organizations"),
"securityhub" to ServiceSpec(
Expand Down
3 changes: 3 additions & 0 deletions docs/acc-test-environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,7 @@ Environment variables (beyond standard AWS Go SDK ones) used by acceptance testi
| `TEST_AWS_SES_VERIFIED_EMAIL_ARN` | Verified SES Email Identity for use in Cognito User Pool testing. |
| `TF_ACC` | Enables Go tests containing `resource.Test()` and `resource.ParallelTest()`. |
| `TF_ACC_ASSUME_ROLE_ARN` | Amazon Resource Name of existing IAM Role to use for limited permissions acceptance testing. |
| `TF_AWS_LICENSE_MANAGER_GRANT_HOME_REGION` | Region where a License Manager license is imported. |
| `TF_AWS_LICENSE_MANAGER_GRANT_LICENSE_ARN` | ARN for a License Manager license imported into the current account. |
| `TF_AWS_LICENSE_MANAGER_GRANT_PRINCIPAL` | ARN of a principal to share the License Manager license with. Either a root user, Organization, or Organizational Unit. |
| `TF_TEST_CLOUDFRONT_RETAIN` | Flag to disable but dangle CloudFront Distributions during testing to reduce feedback time (must be manually destroyed afterwards) |
61 changes: 61 additions & 0 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,26 @@ func protoV5ProviderFactoriesInit(ctx context.Context, providerNames ...string)
return factories
}

func protoV5ProviderFactoriesNamedInit(ctx context.Context, t *testing.T, providers map[string]*schema.Provider, providerNames ...string) map[string]func() (tfprotov5.ProviderServer, error) {
factories := make(map[string]func() (tfprotov5.ProviderServer, error), len(providerNames))

for _, name := range providerNames {
providerServerFactory, p, err := provider.ProtoV5ProviderServerFactory(ctx)

if err != nil {
t.Fatal(err)
}

factories[name] = func() (tfprotov5.ProviderServer, error) { //nolint:unparam
return providerServerFactory(), nil
}

providers[name] = p
}

return factories
}

func protoV5ProviderFactoriesPlusProvidersInit(ctx context.Context, t *testing.T, providers *[]*schema.Provider, providerNames ...string) map[string]func() (tfprotov5.ProviderServer, error) {
factories := make(map[string]func() (tfprotov5.ProviderServer, error), len(providerNames))

Expand Down Expand Up @@ -158,6 +178,10 @@ func ProtoV5FactoriesPlusProvidersAlternate(ctx context.Context, t *testing.T, p
return protoV5ProviderFactoriesPlusProvidersInit(ctx, t, providers, ProviderName, ProviderNameAlternate)
}

func ProtoV5FactoriesNamed(ctx context.Context, t *testing.T, providers map[string]*schema.Provider) map[string]func() (tfprotov5.ProviderServer, error) {
return protoV5ProviderFactoriesNamedInit(ctx, t, providers, ProviderName, ProviderNameAlternate)
}

func ProtoV5FactoriesAlternate(ctx context.Context, t *testing.T) map[string]func() (tfprotov5.ProviderServer, error) {
return protoV5ProviderFactoriesInit(ctx, ProviderName, ProviderNameAlternate)
}
Expand Down Expand Up @@ -1172,6 +1196,26 @@ func RegionProviderFunc(region string, providers *[]*schema.Provider) func() *sc
}
}

func NamedProviderFunc(name string, providers map[string]*schema.Provider) func() *schema.Provider {
return func() *schema.Provider {
return NamedProvider(name, providers)
}
}

func NamedProvider(name string, providers map[string]*schema.Provider) *schema.Provider {
if name == "" {
log.Printf("[ERROR] No name passed")
}

p, ok := providers[name]
if !ok {
log.Printf("[ERROR] No provider named %q found", name)
return nil
}

return p
}

func DeleteResource(ctx context.Context, resource *schema.Resource, d *schema.ResourceData, meta interface{}) error {
if resource.DeleteContext != nil || resource.DeleteWithoutTimeout != nil {
var diags diag.Diagnostics
Expand Down Expand Up @@ -1228,6 +1272,23 @@ func CheckWithProviders(f TestCheckWithProviderFunc, providers *[]*schema.Provid
}
}

func CheckWithNamedProviders(f TestCheckWithProviderFunc, providers map[string]*schema.Provider) resource.TestCheckFunc {
return func(s *terraform.State) error {
numberOfProviders := len(providers)
for k, provo := range providers {
if provo.Meta() == nil {
log.Printf("[DEBUG] Skipping empty provider %q (total: %d)", k, numberOfProviders)
continue
}
log.Printf("[DEBUG] Calling check with provider %q (total: %d)", k, numberOfProviders)
if err := f(s, provo); err != nil {
return err
}
}
return nil
}
}

// ErrorCheckSkipMessagesContaining skips tests based on error messages that indicate unsupported features
func ErrorCheckSkipMessagesContaining(t *testing.T, messages ...string) resource.ErrorCheckFunc {
return func(err error) error {
Expand Down
4 changes: 2 additions & 2 deletions internal/service/licensemanager/association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestAccLicenseManagerAssociation_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccAssociationConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAssociationExists(ctx, resourceName),
resource.TestCheckResourceAttrPair(resourceName, "license_configuration_arn", "aws_licensemanager_license_configuration.test", "id"),
resource.TestCheckResourceAttrPair(resourceName, "resource_arn", "aws_instance.test", "arn"),
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestAccLicenseManagerAssociation_disappears(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccAssociationConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAssociationExists(ctx, resourceName),
acctest.CheckResourceDisappears(ctx, acctest.Provider, tflicensemanager.ResourceAssociation(), resourceName),
),
Expand Down
45 changes: 45 additions & 0 deletions internal/service/licensemanager/common_schema_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package licensemanager

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/licensemanager"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func BuildFiltersDataSource(set *schema.Set) []*licensemanager.Filter {
var filters []*licensemanager.Filter
for _, v := range set.List() {
m := v.(map[string]interface{})
var filterValues []*string
for _, e := range m["values"].([]interface{}) {
filterValues = append(filterValues, aws.String(e.(string)))
}
filters = append(filters, &licensemanager.Filter{
Name: aws.String(m["name"].(string)),
Values: filterValues,
})
}
return filters
}

func DataSourceFiltersSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},

"values": {
Type: schema.TypeList,
Required: true,
MinItems: 1,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
}
}
2 changes: 1 addition & 1 deletion internal/service/licensemanager/generate.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:generate go run ../../generate/tags/main.go -ServiceTagsSlice -UpdateTags -ContextOnly
//go:generate go run ../../generate/listpages/main.go -ListOps=ListLicenseConfigurations,ListLicenseSpecificationsForResource -ContextOnly
//go:generate go run ../../generate/listpages/main.go -ListOps=ListLicenseConfigurations,ListLicenseSpecificationsForResource,ListReceivedLicenses,ListDistributedGrants -ContextOnly
// ONLY generate directives and package declaration! Do not add anything else to this file.

package licensemanager
Loading