Skip to content

Commit

Permalink
Merge pull request #24665 from hashicorp/t-littlecopy-betterthandep
Browse files Browse the repository at this point in the history
iam: Little copying better than little dependency
  • Loading branch information
YakDriver authored May 6, 2022
2 parents b7cac3f + 81d2393 commit 3cdebe9
Show file tree
Hide file tree
Showing 177 changed files with 851 additions and 296 deletions.
12 changes: 12 additions & 0 deletions .semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,15 @@ rules:
patterns:
- pattern: tfawserr.ErrMessageContains(err, ..., "")
severity: ERROR

- id: avoid-dependency-for-one-constant
languages: [go]
message: Use constant in the same package rather than importing iam for a constant
paths:
include:
- internal/
exclude:
- internal/service/iam
patterns:
- pattern: tfiam.PropagationTimeout
severity: ERROR
3 changes: 1 addition & 2 deletions internal/service/apigateway/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

Expand Down Expand Up @@ -99,7 +98,7 @@ func resourceAccountUpdate(d *schema.ResourceData, meta interface{}) error {
otherErrMsg := "API Gateway could not successfully write to CloudWatch Logs using the ARN specified"
var out *apigateway.Account
var err error
err = resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err = resource.Retry(propagationTimeout, func() *resource.RetryError {
out, err = conn.UpdateAccount(&input)

if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions internal/service/apigateway/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package apigateway

import "time"

const (
propagationTimeout = 2 * time.Minute
)
7 changes: 7 additions & 0 deletions internal/service/appautoscaling/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package appautoscaling

import "time"

const (
propagationTimeout = 2 * time.Minute
)
7 changes: 3 additions & 4 deletions internal/service/appautoscaling/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"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"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

Expand Down Expand Up @@ -213,7 +212,7 @@ func resourcePolicyCreate(d *schema.ResourceData, meta interface{}) error {

log.Printf("[DEBUG] ApplicationAutoScaling PutScalingPolicy: %#v", params)
var resp *applicationautoscaling.PutScalingPolicyOutput
err = resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err = resource.Retry(propagationTimeout, func() *resource.RetryError {
var err error
resp, err = conn.PutScalingPolicy(&params)
if err != nil {
Expand Down Expand Up @@ -305,7 +304,7 @@ func resourcePolicyUpdate(d *schema.ResourceData, meta interface{}) error {
}

log.Printf("[DEBUG] Application Autoscaling Update Scaling Policy: %#v", params)
err := resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err := resource.Retry(propagationTimeout, func() *resource.RetryError {
_, err := conn.PutScalingPolicy(&params)
if err != nil {
if tfawserr.ErrCodeEquals(err, applicationautoscaling.ErrCodeFailedResourceAccessException) {
Expand Down Expand Up @@ -345,7 +344,7 @@ func resourcePolicyDelete(d *schema.ResourceData, meta interface{}) error {
ServiceNamespace: aws.String(d.Get("service_namespace").(string)),
}
log.Printf("[DEBUG] Deleting Application AutoScaling Policy opts: %#v", params)
err = resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err = resource.Retry(propagationTimeout, func() *resource.RetryError {
_, err = conn.DeleteScalingPolicy(&params)

if tfawserr.ErrCodeEquals(err, applicationautoscaling.ErrCodeFailedResourceAccessException) {
Expand Down
3 changes: 1 addition & 2 deletions internal/service/appautoscaling/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

Expand Down Expand Up @@ -76,7 +75,7 @@ func resourceTargetPut(d *schema.ResourceData, meta interface{}) error {

log.Printf("[DEBUG] Application autoscaling target create configuration %s", targetOpts)
var err error
err = resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err = resource.Retry(propagationTimeout, func() *resource.RetryError {
_, err = conn.RegisterScalableTarget(&targetOpts)

if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions internal/service/apprunner/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package apprunner

import "time"

const (
propagationTimeout = 2 * time.Minute
)
3 changes: 1 addition & 2 deletions internal/service/apprunner/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -416,7 +415,7 @@ func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, meta int

var output *apprunner.CreateServiceOutput

err := resource.RetryContext(ctx, tfiam.PropagationTimeout, func() *resource.RetryError {
err := resource.RetryContext(ctx, propagationTimeout, func() *resource.RetryError {
var err error
output, err = conn.CreateServiceWithContext(ctx, input)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package autoscaling

import "time"

const (
TagResourceTypeGroup = `auto-scaling-group`
)

const (
propagationTimeout = 2 * time.Minute
)
3 changes: 1 addition & 2 deletions internal/service/autoscaling/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import ( // nosemgrep: aws-sdk-go-multiple-service-imports
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/experimental/nullable"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)
Expand Down Expand Up @@ -776,7 +775,7 @@ func resourceGroupCreate(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Auto Scaling Group create configuration: %#v", createOpts)

// Retry for IAM eventual consistency
err := resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err := resource.Retry(propagationTimeout, func() *resource.RetryError {
_, err := conn.CreateAutoScalingGroup(&createOpts)

// ValidationError: You must use a valid fully-formed launch template. Value (tf-acc-test-6643732652421074386) for parameter iamInstanceProfile.name is invalid. Invalid IAM Instance Profile name
Expand Down
3 changes: 1 addition & 2 deletions internal/service/autoscaling/launch_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import ( // nosemgrep: aws-sdk-go-multiple-service-imports
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)
Expand Down Expand Up @@ -516,7 +515,7 @@ func resourceLaunchConfigurationCreate(d *schema.ResourceData, meta interface{})

// IAM profiles can take ~10 seconds to propagate in AWS:
// http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#launch-instance-with-role-console
err = resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err = resource.Retry(propagationTimeout, func() *resource.RetryError {
_, err := autoscalingconn.CreateLaunchConfiguration(&createLaunchConfigurationOpts)
if err != nil {
if tfawserr.ErrMessageContains(err, "ValidationError", "Invalid IamInstanceProfile") {
Expand Down
3 changes: 1 addition & 2 deletions internal/service/backup/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)
Expand Down Expand Up @@ -200,7 +199,7 @@ func resourceSelectionCreate(d *schema.ResourceData, meta interface{}) error {

// Retry for IAM eventual consistency
var output *backup.CreateBackupSelectionOutput
err := resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err := resource.Retry(propagationTimeout, func() *resource.RetryError {
var err error
output, err = conn.CreateBackupSelection(input)

Expand Down
3 changes: 1 addition & 2 deletions internal/service/budgets/budget_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)
Expand Down Expand Up @@ -228,7 +227,7 @@ func resourceBudgetActionCreate(d *schema.ResourceData, meta interface{}) error
}

log.Printf("[DEBUG] Creating Budget Action: %s", input)
outputRaw, err := tfresource.RetryWhenAWSErrCodeEquals(tfiam.PropagationTimeout, func() (interface{}, error) {
outputRaw, err := tfresource.RetryWhenAWSErrCodeEquals(propagationTimeout, func() (interface{}, error) {
return conn.CreateBudgetAction(input)
}, budgets.ErrCodeAccessDeniedException)

Expand Down
7 changes: 7 additions & 0 deletions internal/service/budgets/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package budgets

import "time"

const (
propagationTimeout = 2 * time.Minute
)
7 changes: 7 additions & 0 deletions internal/service/cloud9/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cloud9

import "time"

const (
propagationTimeout = 2 * time.Minute
)
3 changes: 1 addition & 2 deletions internal/service/cloud9/environment_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"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"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -130,7 +129,7 @@ func resourceEnvironmentEC2Create(d *schema.ResourceData, meta interface{}) erro

log.Printf("[INFO] Creating Cloud9 EC2 Environment: %s", input)
var output *cloud9.CreateEnvironmentEC2Output
err := resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err := resource.Retry(propagationTimeout, func() *resource.RetryError {
var err error
output, err = conn.CreateEnvironmentEC2(input)

Expand Down
6 changes: 6 additions & 0 deletions internal/service/cloudformation/consts.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package cloudformation

import "time"

const (
ResStack = "Stack"
)

const (
propagationTimeout = 2 * time.Minute
)
5 changes: 2 additions & 3 deletions internal/service/cloudformation/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -185,7 +184,7 @@ func resourceStackCreate(d *schema.ResourceData, meta interface{}) error {
}

log.Printf("[DEBUG] Creating CloudFormation Stack: %s", input)
outputRaw, err := tfresource.RetryWhen(tfiam.PropagationTimeout,
outputRaw, err := tfresource.RetryWhen(propagationTimeout,
func() (interface{}, error) {
return conn.CreateStack(input)
},
Expand Down Expand Up @@ -383,7 +382,7 @@ func resourceStackUpdate(d *schema.ResourceData, meta interface{}) error {
}

log.Printf("[DEBUG] Updating CloudFormation Stack: %s", input)
_, err := tfresource.RetryWhen(tfiam.PropagationTimeout,
_, err := tfresource.RetryWhen(propagationTimeout,
func() (interface{}, error) {
return conn.UpdateStack(input)
},
Expand Down
3 changes: 1 addition & 2 deletions internal/service/cloudformation/stack_set_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)
Expand Down Expand Up @@ -195,7 +194,7 @@ func resourceStackSetInstanceCreate(d *schema.ResourceData, meta interface{}) er

log.Printf("[DEBUG] Creating CloudFormation StackSet Instance: %s", input)
_, err := tfresource.RetryWhen(
tfiam.PropagationTimeout,
propagationTimeout,
func() (interface{}, error) {
input.OperationId = aws.String(resource.UniqueId())

Expand Down
5 changes: 2 additions & 3 deletions internal/service/cloudtrail/cloudtrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -290,7 +289,7 @@ func resourceCloudTrailCreate(d *schema.ResourceData, meta interface{}) error {
}

var t *cloudtrail.CreateTrailOutput
err := resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err := resource.Retry(propagationTimeout, func() *resource.RetryError {
var err error
t, err = conn.CreateTrail(&input)
if err != nil {
Expand Down Expand Up @@ -502,7 +501,7 @@ func resourceCloudTrailUpdate(d *schema.ResourceData, meta interface{}) error {
}

log.Printf("[DEBUG] Updating CloudTrail: %s", input)
err := resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err := resource.Retry(propagationTimeout, func() *resource.RetryError {
var err error
_, err = conn.UpdateTrail(&input)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions internal/service/cloudtrail/consts.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cloudtrail

import "time"

const (
ResCloudTrail = "Trail"

Expand Down Expand Up @@ -35,3 +37,7 @@ func field_Values() []string {
fieldResourcesType,
}
}

const (
propagationTimeout = 2 * time.Minute
)
6 changes: 6 additions & 0 deletions internal/service/codebuild/consts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package codebuild

import "time"

const (
ResReportGroup = "Report Group"
ResWebhook = "Webhook"
)

const (
propagationTimeout = 2 * time.Minute
)
3 changes: 1 addition & 2 deletions internal/service/codebuild/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -1575,7 +1574,7 @@ func resourceProjectUpdate(d *schema.ResourceData, meta interface{}) error {
params.Tags = Tags(tags.IgnoreAWS())

// Handle IAM eventual consistency
err := resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err := resource.Retry(propagationTimeout, func() *resource.RetryError {
_, err := conn.UpdateProject(params)
if err != nil {
// InvalidInputException: CodeBuild is not authorized to perform
Expand Down
3 changes: 1 addition & 2 deletions internal/service/codepipeline/codepipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -225,7 +224,7 @@ func resourceCreate(d *schema.ResourceData, meta interface{}) error {
}

var resp *codepipeline.CreatePipelineOutput
err = resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err = resource.Retry(propagationTimeout, func() *resource.RetryError {
var err error

resp, err = conn.CreatePipeline(params)
Expand Down
6 changes: 6 additions & 0 deletions internal/service/codepipeline/consts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package codepipeline

import "time"

const (
ResWebhook = "Webhook"
ResCodePipeline = "Pipeline"
)

const (
propagationTimeout = 2 * time.Minute
)
Loading

0 comments on commit 3cdebe9

Please sign in to comment.