Skip to content

Commit 22266d2

Browse files
authored
Merge pull request #45217 from alexbacchin/f-iam_outbound_web_identity_federation
new resource `aws_iam_outbound_web_identity_federation`
2 parents f35da9e + d0a7ec0 commit 22266d2

File tree

12 files changed

+509
-26
lines changed

12 files changed

+509
-26
lines changed

.changelog/45217.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
aws_iam_outbound_web_identity_federation
3+
```

internal/acctest/import.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package acctest
55

66
import (
7+
"context"
78
"errors"
89
"fmt"
910
"regexp"
@@ -84,3 +85,9 @@ func ImportCheckResourceAttrSet(key string) resource.ImportStateCheckFunc {
8485
return nil
8586
}
8687
}
88+
89+
func ImportStateIDAccountID(ctx context.Context) resource.ImportStateIdFunc {
90+
return func(*terraform.State) (string, error) {
91+
return AccountID(ctx), nil
92+
}
93+
}

internal/generate/identitytests/resource_test.go.gtpl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ ImportPlanChecks: resource.ImportPlanChecks{
138138
{{ else if .IsRegionalSingleton -}}
139139
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrID), knownvalue.StringExact(acctest.Region())),
140140
{{ else if .IsGlobalSingleton -}}
141-
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrID), tfknownvalue.AccountID()),
141+
{{ if .HasIdentityDuplicateAttrs -}}
142+
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrID), tfknownvalue.AccountID()),
143+
{{ end -}}
142144
{{ else if .HasIDAttrDuplicates -}}
143145
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New({{ .IDAttrDuplicates }}), knownvalue.NotNull()),
144146
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrID), knownvalue.NotNull()),
@@ -181,7 +183,9 @@ ImportPlanChecks: resource.ImportPlanChecks{
181183
{{ else if .IsRegionalSingleton -}}
182184
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrID), knownvalue.StringExact(acctest.AlternateRegion())),
183185
{{ else if .IsGlobalSingleton -}}
184-
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrID), tfknownvalue.AccountID()),
186+
{{ if .HasIdentityDuplicateAttrs -}}
187+
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrID), tfknownvalue.AccountID()),
188+
{{ end -}}
185189
{{ else if gt (len .IdentityAttributes) 0 -}}
186190
{{ range .IdentityAttributes -}}
187191
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New({{ .Name }}), knownvalue.NotNull()),
@@ -272,7 +276,9 @@ func {{ template "testname" . }}_Identity_Basic(t *testing.T) {
272276
{{ end -}}
273277
{{ end -}}
274278
{{ if .IsGlobalSingleton -}}
275-
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrID), tfknownvalue.AccountID()),
279+
{{ if .HasIdentityDuplicateAttrs -}}
280+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrID), tfknownvalue.AccountID()),
281+
{{ end -}}
276282
{{ else if .HasIdentityDuplicateAttrs -}}
277283
{{ range .IdentityDuplicateAttrs -}}
278284
statecheck.CompareValuePairs(resourceName, tfjsonpath.New({{ . }}), resourceName, tfjsonpath.New({{ $.IdentityAttribute }}), compare.ValuesSame()),

internal/generate/servicepackage/service_package_gen.go.gtpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*inttypes.Ser
249249
{{- end -}}
250250
{{- template "CommonIdentityOpts" . -}}
251251
),
252-
{{ else }}
252+
{{- else }}
253253
inttypes.RegionalSingletonIdentity(
254254
{{- if .HasIdentityDuplicateAttrs -}}
255255
inttypes.WithIdentityDuplicateAttrs({{ range .IdentityDuplicateAttrs }}{{ . }}, {{ end }}),
@@ -379,7 +379,7 @@ func (p *servicePackage) FrameworkListResources(ctx context.Context) iter.Seq[*i
379379
{{- end -}}
380380
{{- template "CommonIdentityOpts" . -}}
381381
),
382-
{{ else }}
382+
{{- else }}
383383
inttypes.RegionalSingletonIdentity(
384384
{{- if .HasIdentityDuplicateAttrs -}}
385385
inttypes.WithIdentityDuplicateAttrs({{ range .IdentityDuplicateAttrs }}{{ . }}, {{ end }}),

internal/service/iam/exports_test.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,28 @@ var (
1010
ResourceAccountPasswordPolicy = resourceAccountPasswordPolicy
1111
ResourceGroup = resourceGroup
1212
// ResourceGroupMembership = resourceGroupMembership
13-
ResourceGroupPolicy = resourceGroupPolicy
14-
ResourceGroupPolicyAttachment = resourceGroupPolicyAttachment
15-
ResourceInstanceProfile = resourceInstanceProfile
16-
ResourceOpenIDConnectProvider = resourceOpenIDConnectProvider
17-
ResourceOrganizationsFeatures = newOrganizationsFeaturesResource
18-
ResourcePolicy = resourcePolicy
19-
ResourcePolicyAttachment = resourcePolicyAttachment
20-
ResourceRolePolicy = resourceRolePolicy
21-
ResourceRolePolicyAttachment = resourceRolePolicyAttachment
22-
ResourceSAMLProvider = resourceSAMLProvider
23-
ResourceServerCertificate = resourceServerCertificate
24-
ResourceServiceLinkedRole = resourceServiceLinkedRole
25-
ResourceServiceSpecificCredential = resourceServiceSpecificCredential
26-
ResourceSigningCertificate = resourceSigningCertificate
27-
ResourceUser = resourceUser
28-
ResourceUserGroupMembership = resourceUserGroupMembership
29-
ResourceUserLoginProfile = resourceUserLoginProfile
30-
ResourceUserPolicy = resourceUserPolicy
31-
ResourceUserPolicyAttachment = resourceUserPolicyAttachment
32-
ResourceUserSSHKey = resourceUserSSHKey
33-
ResourceVirtualMFADevice = resourceVirtualMFADevice
13+
ResourceGroupPolicy = resourceGroupPolicy
14+
ResourceGroupPolicyAttachment = resourceGroupPolicyAttachment
15+
ResourceInstanceProfile = resourceInstanceProfile
16+
ResourceOpenIDConnectProvider = resourceOpenIDConnectProvider
17+
ResourceOrganizationsFeatures = newOrganizationsFeaturesResource
18+
ResourceOutboundWebIdentityFederation = newOutboundWebIdentityFederationResource
19+
ResourcePolicy = resourcePolicy
20+
ResourcePolicyAttachment = resourcePolicyAttachment
21+
ResourceRolePolicy = resourceRolePolicy
22+
ResourceRolePolicyAttachment = resourceRolePolicyAttachment
23+
ResourceSAMLProvider = resourceSAMLProvider
24+
ResourceServerCertificate = resourceServerCertificate
25+
ResourceServiceLinkedRole = resourceServiceLinkedRole
26+
ResourceServiceSpecificCredential = resourceServiceSpecificCredential
27+
ResourceSigningCertificate = resourceSigningCertificate
28+
ResourceUser = resourceUser
29+
ResourceUserGroupMembership = resourceUserGroupMembership
30+
ResourceUserLoginProfile = resourceUserLoginProfile
31+
ResourceUserPolicy = resourceUserPolicy
32+
ResourceUserPolicyAttachment = resourceUserPolicyAttachment
33+
ResourceUserSSHKey = resourceUserSSHKey
34+
ResourceVirtualMFADevice = resourceVirtualMFADevice
3435

3536
FindAccessKeyByTwoPartKey = findAccessKeyByTwoPartKey
3637
FindAccountAlias = findAccountAlias
@@ -49,6 +50,7 @@ var (
4950
FindInstanceProfileByName = findInstanceProfileByName
5051
FindOpenIDConnectProviderByARN = findOpenIDConnectProviderByARN
5152
FindOrganizationsFeatures = findOrganizationsFeatures
53+
FindOutboundWebIdentityFederation = findOutboundWebIdentityFederation
5254
FindPolicyByARN = findPolicyByARN
5355
FindRolePolicyByTwoPartKey = findRolePolicyByTwoPartKey
5456
FindRolePoliciesByName = findRolePoliciesByName
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package iam
5+
6+
import (
7+
"context"
8+
9+
"github.com/aws/aws-sdk-go-v2/service/iam"
10+
awstypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
11+
"github.com/hashicorp/terraform-plugin-framework/path"
12+
"github.com/hashicorp/terraform-plugin-framework/resource"
13+
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
14+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
15+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
16+
"github.com/hashicorp/terraform-plugin-framework/types"
17+
"github.com/hashicorp/terraform-provider-aws/internal/errs"
18+
"github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag"
19+
"github.com/hashicorp/terraform-provider-aws/internal/framework"
20+
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
21+
"github.com/hashicorp/terraform-provider-aws/internal/retry"
22+
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
23+
)
24+
25+
// @FrameworkResource("aws_iam_outbound_web_identity_federation", name="Outbound Web Identity Federation")
26+
// @SingletonIdentity
27+
// @Testing(hasNoPreExistingResource=true)
28+
// @Testing(serialize=true)
29+
// @Testing(importStateIdFunc=importStateIDAccountID", importStateIdAttribute="issuer_identifier")
30+
// @Testing(generator=false)
31+
// @Testing(existsTakesT=true, destroyTakesT=true)
32+
func newOutboundWebIdentityFederationResource(_ context.Context) (resource.ResourceWithConfigure, error) {
33+
r := &outboundWebIdentityFederationResource{}
34+
35+
return r, nil
36+
}
37+
38+
type outboundWebIdentityFederationResource struct {
39+
framework.ResourceWithModel[outboundWebIdentityFederationResourceModel]
40+
framework.WithNoUpdate
41+
framework.WithImportByIdentity
42+
}
43+
44+
func (r *outboundWebIdentityFederationResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
45+
resp.Schema = schema.Schema{
46+
Attributes: map[string]schema.Attribute{
47+
"issuer_identifier": schema.StringAttribute{
48+
Computed: true,
49+
PlanModifiers: []planmodifier.String{
50+
stringplanmodifier.UseStateForUnknown(),
51+
},
52+
},
53+
},
54+
}
55+
}
56+
57+
func (r *outboundWebIdentityFederationResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
58+
var data outboundWebIdentityFederationResourceModel
59+
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
60+
if resp.Diagnostics.HasError() {
61+
return
62+
}
63+
64+
conn := r.Meta().IAMClient(ctx)
65+
66+
var input iam.EnableOutboundWebIdentityFederationInput
67+
out, err := conn.EnableOutboundWebIdentityFederation(ctx, &input)
68+
if err != nil {
69+
resp.Diagnostics.AddError("enabling IAM Outbound Web Identity Federation", err.Error())
70+
return
71+
}
72+
73+
// Set values for unknowns.
74+
data.IssuerIdentifier = fwflex.StringToFramework(ctx, out.IssuerIdentifier)
75+
76+
resp.Diagnostics.Append(resp.State.Set(ctx, data)...)
77+
}
78+
79+
func (r *outboundWebIdentityFederationResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
80+
var data outboundWebIdentityFederationResourceModel
81+
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
82+
if resp.Diagnostics.HasError() {
83+
return
84+
}
85+
86+
conn := r.Meta().IAMClient(ctx)
87+
88+
out, err := findOutboundWebIdentityFederation(ctx, conn)
89+
if retry.NotFound(err) {
90+
resp.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
91+
resp.State.RemoveResource(ctx)
92+
return
93+
}
94+
if err != nil {
95+
resp.Diagnostics.AddError("reading IAM Outbound Web Identity Federation", err.Error())
96+
return
97+
}
98+
99+
// Set attributes for import.
100+
data.IssuerIdentifier = fwflex.StringToFramework(ctx, out.IssuerIdentifier)
101+
102+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
103+
}
104+
105+
func (r *outboundWebIdentityFederationResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
106+
conn := r.Meta().IAMClient(ctx)
107+
108+
var input iam.DisableOutboundWebIdentityFederationInput
109+
_, err := conn.DisableOutboundWebIdentityFederation(ctx, &input)
110+
if errs.IsA[*awstypes.FeatureDisabledException](err) {
111+
return
112+
}
113+
if err != nil {
114+
resp.Diagnostics.AddError("disabling IAM Outbound Web Identity Federation", err.Error())
115+
return
116+
}
117+
}
118+
119+
func (r *outboundWebIdentityFederationResource) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) {
120+
r.WithImportByIdentity.ImportState(ctx, request, response)
121+
122+
// Touch a value to bypass a Framework check
123+
response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("issuer_identifier"), types.StringUnknown())...)
124+
}
125+
126+
func findOutboundWebIdentityFederation(ctx context.Context, conn *iam.Client) (*iam.GetOutboundWebIdentityFederationInfoOutput, error) {
127+
var input iam.GetOutboundWebIdentityFederationInfoInput
128+
out, err := conn.GetOutboundWebIdentityFederationInfo(ctx, &input)
129+
130+
if errs.IsA[*awstypes.FeatureDisabledException](err) {
131+
return nil, &retry.NotFoundError{
132+
LastError: err,
133+
}
134+
}
135+
136+
if err != nil {
137+
return nil, err
138+
}
139+
140+
if out == nil {
141+
return nil, tfresource.NewEmptyResultError(&input)
142+
}
143+
144+
return out, nil
145+
}
146+
147+
type outboundWebIdentityFederationResourceModel struct {
148+
IssuerIdentifier types.String `tfsdk:"issuer_identifier"`
149+
}

internal/service/iam/outbound_web_identity_federation_identity_gen_test.go

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)