Skip to content

Commit

Permalink
Merge pull request #29741 from brittandeyoung/f-aws_licensemanager_grant
Browse files Browse the repository at this point in the history
New Resources: `aws_licensemanager_grant` and `aws_licensemanager_grant_accepter`, New Datasources:  `aws_licensemanager_received_license` , `aws_licensemanager_received_licenses`, and  `aws_licensemanager_grants`
  • Loading branch information
gdavison authored Mar 9, 2023
2 parents c3e4aaf + 58653b9 commit 8555d8c
Show file tree
Hide file tree
Showing 25 changed files with 2,215 additions and 9 deletions.
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

0 comments on commit 8555d8c

Please sign in to comment.