-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 #32091 from bschaatsbergen/iam-session-security-token
New Resource - IAM Security Token Service Preferences
- Loading branch information
Showing
6 changed files
with
162 additions
and
0 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,3 @@ | ||
```release-note:new-resource | ||
aws_iam_security_token_service_preferences | ||
``` |
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
71 changes: 71 additions & 0 deletions
71
internal/service/iam/security_token_service_preferences.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 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package iam | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/iam" | ||
"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/errs/sdkdiag" | ||
) | ||
|
||
// @SDKResource("aws_iam_security_token_service_preferences", name="Security Token Service Preferences") | ||
func ResourceSecurityTokenServicePreferences() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateWithoutTimeout: resourceSecurityTokenServicePreferencesUpsert, | ||
ReadWithoutTimeout: resourceSecurityTokenServicePreferencesRead, | ||
UpdateWithoutTimeout: resourceSecurityTokenServicePreferencesUpsert, | ||
DeleteWithoutTimeout: schema.NoopContext, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"global_endpoint_token_version": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringInSlice(iam.GlobalEndpointTokenVersion_Values(), false), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceSecurityTokenServicePreferencesUpsert(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
conn := meta.(*conns.AWSClient).IAMConn(ctx) | ||
|
||
input := &iam.SetSecurityTokenServicePreferencesInput{ | ||
GlobalEndpointTokenVersion: aws.String(d.Get("global_endpoint_token_version").(string)), | ||
} | ||
|
||
_, err := conn.SetSecurityTokenServicePreferencesWithContext(ctx, input) | ||
|
||
if err != nil { | ||
return sdkdiag.AppendErrorf(diags, "setting IAM Security Token Service Preferences: %s", err) | ||
} | ||
|
||
if d.IsNewResource() { | ||
d.SetId(meta.(*conns.AWSClient).AccountID) | ||
} | ||
|
||
return append(diags, resourceSecurityTokenServicePreferencesRead(ctx, d, meta)...) | ||
} | ||
|
||
func resourceSecurityTokenServicePreferencesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
conn := meta.(*conns.AWSClient).IAMConn(ctx) | ||
|
||
output, err := conn.GetAccountSummaryWithContext(ctx, &iam.GetAccountSummaryInput{}) | ||
|
||
if err != nil { | ||
return sdkdiag.AppendErrorf(diags, "reading IAM Account Summary: %s", err) | ||
} | ||
|
||
d.Set("global_endpoint_token_version", fmt.Sprintf("v%dToken", aws.Int64Value(output.SummaryMap[iam.SummaryKeyTypeGlobalEndpointTokenVersion]))) | ||
|
||
return diags | ||
} |
38 changes: 38 additions & 0 deletions
38
internal/service/iam/security_token_service_preferences_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,38 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package iam_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/iam" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
) | ||
|
||
func TestAccIAMSecurityTokenServicePreferences_basic(t *testing.T) { | ||
ctx := acctest.Context(t) | ||
resourceName := "aws_iam_security_token_service_preferences.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(ctx, t) }, | ||
ErrorCheck: acctest.ErrorCheck(t, iam.EndpointsID), | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
CheckDestroy: acctest.CheckDestroyNoop, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccSecurityTokenServicePreferencesConfig_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceName, "global_endpoint_token_version", "v2Token"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccSecurityTokenServicePreferencesConfig_basic = ` | ||
resource "aws_iam_security_token_service_preferences" "test" { | ||
global_endpoint_token_version = "v2Token" | ||
} | ||
` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
website/docs/r/iam_security_token_service_preferences.html.markdown
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,31 @@ | ||
--- | ||
subcategory: "IAM (Identity & Access Management)" | ||
layout: "aws" | ||
page_title: "AWS: aws_iam_security_token_service_preferences" | ||
description: |- | ||
Provides an IAM Security Token Service Preferences resource. | ||
--- | ||
|
||
# Resource: aws_iam_security_token_service_preferences | ||
|
||
Provides an IAM Security Token Service Preferences resource. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "aws_iam_security_token_service_preferences" "example" { | ||
global_endpoint_token_version = "v2Token" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
This resource supports the following arguments: | ||
|
||
* `global_endpoint_token_version` - (Required) The version of the STS global endpoint token. Valid values: `v1Token`, `v2Token`. | ||
|
||
## Attribute Reference | ||
|
||
This resource exports the following attributes in addition to the arguments above: | ||
|
||
* `id` - The AWS Account ID. |