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 14 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
7 changes: 7 additions & 0 deletions .changelog/29741.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-resource
aws_licensemanager_grant
```

```release-note:new-resource
aws_licensemanager_grant_accepter
```
233 changes: 233 additions & 0 deletions internal/service/licensemanager/grant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
package licensemanager

import (
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/licensemanager"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"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"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
)

const (
ResGrant = "Grant"
)

// @SDKResource("aws_licensemanager_grant")
func ResourceGrant() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceGrantCreate,
ReadWithoutTimeout: resourceGrantRead,
UpdateWithoutTimeout: resourceGrantUpdate,
DeleteWithoutTimeout: resourceGrantDelete,

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: map[string]*schema.Schema{
"allowed_operations": {
Type: schema.TypeSet,
Required: true,
MinItems: 1,
MaxItems: len(licensemanager.AllowedOperation_Values()),
brittandeyoung marked this conversation as resolved.
Show resolved Hide resolved
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice(licensemanager.AllowedOperation_Values(), true),
},
Description: "Allowed operations for the grant.",
brittandeyoung marked this conversation as resolved.
Show resolved Hide resolved
},
"arn": {
Type: schema.TypeString,
Computed: true,
Description: "Amazon Resource Name (ARN) of the grant.",
},
"home_region": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Home Region of the grant.",
},
brittandeyoung marked this conversation as resolved.
Show resolved Hide resolved
"license_arn": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: verify.ValidARN,
Description: "License ARN.",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the grant.",
},
"parent_arn": {
Type: schema.TypeString,
Computed: true,
Description: "Parent ARN.",
},
"principal": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: verify.ValidARN,
Description: "The grantee principal ARN.",
brittandeyoung marked this conversation as resolved.
Show resolved Hide resolved
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Grant status.",
},
"version": {
Type: schema.TypeString,
Computed: true,
Description: "Grant version.",
},
},
}
}

func resourceGrantCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).LicenseManagerConn()

in := &licensemanager.CreateGrantInput{
AllowedOperations: aws.StringSlice(expandAllowedOperations(d.Get("allowed_operations").(*schema.Set).List())),
ClientToken: aws.String(resource.UniqueId()),
GrantName: aws.String(d.Get("name").(string)),
HomeRegion: aws.String(d.Get("home_region").(string)),
LicenseArn: aws.String(d.Get("license_arn").(string)),
Principals: aws.StringSlice([]string{d.Get("principal").(string)}),
}

out, err := conn.CreateGrantWithContext(ctx, in)

if err != nil {
return create.DiagError(names.LicenseManager, create.ErrActionCreating, ResGrant, d.Get("name").(string), err)
}

d.SetId(aws.StringValue(out.GrantArn))

return resourceGrantRead(ctx, d, meta)
}

func resourceGrantRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).LicenseManagerConn()

out, err := FindGrantByARN(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
create.LogNotFoundRemoveState(names.LicenseManager, create.ErrActionReading, ResGrant, d.Id())
d.SetId("")
return nil
}

if err != nil {
return create.DiagError(names.LicenseManager, create.ErrActionReading, ResGrant, d.Id(), err)
}

d.Set("allowed_operations", out.GrantedOperations)
d.Set("arn", out.GrantArn)
d.Set("home_region", out.HomeRegion)
d.Set("license_arn", out.LicenseArn)
d.Set("name", out.GrantName)
d.Set("parent_arn", out.ParentArn)
d.Set("principal", out.GranteePrincipalArn)
d.Set("status", out.GrantStatus)
d.Set("version", out.Version)

return nil
}

func resourceGrantUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).LicenseManagerConn()

in := &licensemanager.CreateGrantVersionInput{
GrantArn: aws.String(d.Id()),
ClientToken: aws.String(resource.UniqueId()),
}

if d.HasChange("allowed_operations") {
in.AllowedOperations = aws.StringSlice(d.Get("allowed_operations").([]string))
}

if d.HasChange("name") {
in.GrantName = aws.String(d.Get("name").(string))
}

_, err := conn.CreateGrantVersionWithContext(ctx, in)

if err != nil {
return create.DiagError(names.LicenseManager, create.ErrActionUpdating, ResGrant, d.Id(), err)
}

return resourceGrantRead(ctx, d, meta)
}

func resourceGrantDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).LicenseManagerConn()

out, err := FindGrantByARN(ctx, conn, d.Id())

if err != nil {
return create.DiagError(names.LicenseManager, create.ErrActionReading, ResGrant, d.Id(), err)
}

in := &licensemanager.DeleteGrantInput{
GrantArn: aws.String(d.Id()),
Version: aws.String(*out.Version),
}

_, err = conn.DeleteGrantWithContext(ctx, in)

if err != nil {
return create.DiagError(names.LicenseManager, create.ErrActionDeleting, ResGrant, d.Id(), err)
}

return nil
}

func FindGrantByARN(ctx context.Context, conn *licensemanager.LicenseManager, arn string) (*licensemanager.Grant, error) {
in := &licensemanager.GetGrantInput{
GrantArn: aws.String(arn),
}

out, err := conn.GetGrantWithContext(ctx, in)

if tfawserr.ErrCodeEquals(err, licensemanager.ErrCodeResourceNotFoundException) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: in,
}
}

if err != nil {
return nil, err
}

if out == nil || out.Grant == nil || aws.StringValue(out.Grant.GrantStatus) == licensemanager.GrantStatusDeleted {
return nil, tfresource.NewEmptyResultError(in)
}

return out.Grant, nil
}

func expandAllowedOperations(rawOperations []interface{}) []string {
if rawOperations == nil {
return nil
}

operations := make([]string, 0, 8)

for _, item := range rawOperations {
operations = append(operations, item.(string))
}

return operations
}
Loading