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

Add support for registering new domains via aws_route53domains_registered_domain #37885

Open
wants to merge 72 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
5229919
feat(aws_route53domains_registered_domain): support registration of n…
davidmohar Jun 7, 2024
e0a213c
chore: add changelog entry
davidmohar Jun 7, 2024
2afc0fd
fix: correctly handle contacts and additional attributes for registra…
davidmohar Jun 26, 2024
786c9b6
test: registration should fail if we don't explicitly consent
davidmohar Jun 26, 2024
ec6a56f
Revert "test: registration should fail if we don't explicitly consent"
ewbankkit Dec 11, 2024
545b71c
Revert "fix: correctly handle contacts and additional attributes for …
ewbankkit Dec 11, 2024
d60551c
Revert "chore: add changelog entry"
ewbankkit Dec 11, 2024
0b45191
Revert "feat(aws_route53domains_registered_domain): support registrat…
ewbankkit Dec 11, 2024
59a4594
Merge branch 'main' into HEAD
ewbankkit Dec 11, 2024
14cfd25
route53domains: Move some functions around.
ewbankkit Dec 11, 2024
e02b63d
Rename source file.
ewbankkit Dec 11, 2024
fdbebad
r/aws_route53domains_domain: Skeleton of new resource.
ewbankkit Dec 11, 2024
847506c
r/aws_route53domains_domain: Add schema and model.
ewbankkit Dec 11, 2024
25fa820
Merge branch 'main' into HEAD
ewbankkit Dec 11, 2024
b9d9210
r/aws_route53domains_domain: Use 'CaseInsensitiveString' for 'domain_…
ewbankkit Dec 11, 2024
85e08de
r/aws_route53domains_domain: Implement CRD.
ewbankkit Dec 12, 2024
3a404b5
r/aws_route53domains_domain: Tag on create.
ewbankkit Dec 12, 2024
b7e983f
Add tags to 'domainResourceModel'.
ewbankkit Dec 12, 2024
c4a97f2
Don't AutoFlEx 'ExtraParams'.
ewbankkit Dec 23, 2024
aa89eae
Always null out newly created Terraform types.
ewbankkit Dec 23, 2024
4c2004d
r/aws_route53domains_domain: Remove 'id' attribute.
ewbankkit Dec 23, 2024
d145dc8
Add 'framework.ResourceOptionalComputedListOfObjectAttribute'.
ewbankkit Dec 28, 2024
41a2110
'billing_contact' is Optional+Computed.
ewbankkit Dec 28, 2024
90eb7d3
Merge branch 'main' into HEAD
ewbankkit Jan 9, 2025
cf3c0f4
'framework.ResourceComputedListOfObjectAttribute' -> 'framework.Resou…
ewbankkit Jan 9, 2025
b2fe6de
'framework.ResourceOptionalComputedListOfObjectAttribute' -> 'framewo…
ewbankkit Jan 9, 2025
49fd87f
'extra_params' as Map -> 'extra_param' as ListNestedBlock.
ewbankkit Jan 9, 2025
5245e94
Fix 'Provider produced inconsistent result after apply' on Create.
ewbankkit Jan 9, 2025
d742795
route53: Add 'deleteHostedZone'.
ewbankkit Jan 9, 2025
4f23daa
route53: Add 'findHostedZone(s)'.
ewbankkit Jan 9, 2025
4fae307
route53: Add 'findPublicHostedZoneByDomainName'.
ewbankkit Jan 10, 2025
fb3ff84
r/aws_route53domain_domain: Add 'hosted_zone_id' attribute.
ewbankkit Jan 10, 2025
88b8a72
r/aws_route53domain_domain: Delete associated hosted zone.
ewbankkit Jan 10, 2025
159d533
'framework.ResourceOptionalComputedListOfSingleObjectAttribute' -> 'f…
ewbankkit Jan 10, 2025
305be8f
r/aws_route53domain_domain: Read associated hosted zone for Import.
ewbankkit Jan 10, 2025
a47f09a
r/aws_route53domain_domain: Add documentation.
ewbankkit Jan 10, 2025
1ee1f5f
r/aws_route53domain_domain: Enhance 'fixupContactDetail'.
ewbankkit Jan 10, 2025
f41b210
r/aws_route53domain_domain: Handler 'transfer_lock' during Create.
ewbankkit Jan 10, 2025
03c11c2
r/aws_route53domains_domain: Handle contact details updates.
ewbankkit Jan 13, 2025
9b2c850
r/aws_route53domains_domain: Handle contact privacy updates.
ewbankkit Jan 13, 2025
d0f4534
r/aws_route53domains_domain: Handle auto-renew updates.
ewbankkit Jan 13, 2025
0d3debb
r/aws_route53domains_domain: Handle nameserver updates.
ewbankkit Jan 13, 2025
5e93f98
r/aws_route53domains_domain: Handle transfer lock updates.
ewbankkit Jan 13, 2025
4f9bc6e
r/aws_route53domain_domain: Set Unknowns after Update.
ewbankkit Jan 13, 2025
fca6154
Add 'planmodifier.ListNotConfigurableOnCreate'.
ewbankkit Jan 14, 2025
fb55c98
Merge branch 'main' into HEAD
ewbankkit Jan 14, 2025
93e3b16
'framework.ResourceComputedListOfObjectAttribute' -> 'framework.Resou…
ewbankkit Jan 14, 2025
01cc530
Test (and correct) 'planmodifiers.ListNotConfigurableOnCreate'.
ewbankkit Jan 14, 2025
b362bd1
r/aws_route53domains_domain: 'name_server' is not configurable on Cre…
ewbankkit Jan 14, 2025
fa7887b
r/aws_route53domains_domain: Public hosted zone may have been deleted.
ewbankkit Jan 14, 2025
ac75d33
Add 'ListDefaultValueFromPath' plan modifier.
ewbankkit Jan 14, 2025
ce7a15a
Test 'ListDefaultValueFromPath' plan modifier.
ewbankkit Jan 14, 2025
78e3312
r/aws_route53_domains_domain: Default value of 'billing_contact' is t…
ewbankkit Jan 14, 2025
c220a00
r/aws_route53domains_domain: Modify nameservers on Create.
ewbankkit Jan 14, 2025
7971de0
Add 'fixupDomainDetail'.
ewbankkit Jan 14, 2025
0d2edfe
Add 'flex.Int64ValueFromFramework'.
ewbankkit Jan 16, 2025
b47922a
r/aws_route53domains_domain: Handle domain renewal.
ewbankkit Jan 16, 2025
8bccc7c
Merge branch 'main' into HEAD
ewbankkit Jan 16, 2025
ca284c1
Document how domains are renewed.
ewbankkit Jan 16, 2025
e099985
r/aws_route53domains_domain: Add acceptance tests.
ewbankkit Jan 16, 2025
9fe6568
Acceptance test output:
ewbankkit Jan 16, 2025
940ef81
Correct golangci-lint 'mnd' exclusion.
ewbankkit Jan 16, 2025
8bd5a36
Run 'make fix-constants'.
ewbankkit Jan 16, 2025
1a2b5d9
Fix semgrep 'ci.email-address'.
ewbankkit Jan 16, 2025
dca4091
Run 'make gen'.
ewbankkit Jan 16, 2025
5f4d862
Fix golangci-lint 'wastedassign'.
ewbankkit Jan 16, 2025
ef9c883
Fix golangci-lint 'stylecheck'.
ewbankkit Jan 16, 2025
9a1dcd1
'ResourceOptionalComputedListOfObjectAttribute' -> 'ResourceOptionalC…
ewbankkit Jan 16, 2025
5935f06
Fix golangci-lint 'mnd'.
ewbankkit Jan 16, 2025
2f1d05e
Better handling of transfer lock on Create.
ewbankkit Jan 17, 2025
f961335
r/aws_route53domains_domain: Acceptance test fixes.
ewbankkit Jan 17, 2025
2cf176f
Add CHANGELOG entry.
ewbankkit Jan 17, 2025
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
4 changes: 4 additions & 0 deletions .changelog/37885.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```new-resource
aws_route53domains_domain
```

12 changes: 10 additions & 2 deletions internal/framework/flex/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ func Int64FromFramework(ctx context.Context, v basetypes.Int64Valuable) *int64 {
return output
}

func Int64ValueFromFramework(ctx context.Context, v basetypes.Int64Valuable) int64 {
var output int64

must(Expand(ctx, v, &output))

return output
}

// Int64ToFramework converts an int64 pointer to a Framework Int64 value.
// A nil int64 pointer is converted to a null Int64.
func Int64ToFramework(ctx context.Context, v *int64) types.Int64 {
Expand Down Expand Up @@ -61,7 +69,7 @@ func Int32ToFrameworkLegacy(_ context.Context, v *int32) types.Int64 {

// Int32FromFramework coverts a Framework Int64 value to an int32 pointer.
// A null Int64 is converted to a nil int32 pointer.
func Int32FromFramework(ctx context.Context, v types.Int64) *int32 {
func Int32FromFramework(ctx context.Context, v basetypes.Int64Valuable) *int32 {
var output *int32

must(Expand(ctx, v, &output))
Expand All @@ -71,7 +79,7 @@ func Int32FromFramework(ctx context.Context, v types.Int64) *int32 {

// Int32ValueFromFramework coverts a Framework Int64 value to an int32 pointer.
// A null Int64 is converted to a nil int32 pointer.
func Int32ValueFromFramework(ctx context.Context, v types.Int64) int32 {
func Int32ValueFromFramework(ctx context.Context, v basetypes.Int64Valuable) int32 {
var output int32

must(Expand(ctx, v, &output))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package planmodifiers

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

// ListDefaultValueFromPath returns a plan modifier that sets a list's default value
// from the planned value at another path.
func ListDefaultValueFromPath[T basetypes.ListValuable](path path.Path) planmodifier.List {
return listDefaultValueFromPath[T]{
path: path,
}
}

type listDefaultValueFromPath[T basetypes.ListValuable] struct {
path path.Path
}

func (m listDefaultValueFromPath[T]) Description(ctx context.Context) string {
return m.MarkdownDescription(ctx)
}

func (m listDefaultValueFromPath[T]) MarkdownDescription(context.Context) string {
return "The default value of this attribute is another attribute's value."
}

func (m listDefaultValueFromPath[T]) PlanModifyList(ctx context.Context, request planmodifier.ListRequest, response *planmodifier.ListResponse) {
// Do nothing if there is a known planned value.
if !request.PlanValue.IsUnknown() {
return
}

var t T
response.Diagnostics.Append(request.Plan.GetAttribute(ctx, m.path, &t)...)
if response.Diagnostics.HasError() {
return
}

v, diags := t.ToListValue(ctx)
response.Diagnostics.Append(diags...)
if response.Diagnostics.HasError() {
return
}

response.PlanValue = v
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package planmodifiers_test

import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tftypes"
fwplanmodifiers "github.com/hashicorp/terraform-provider-aws/internal/framework/planmodifiers"
)

func TestListDefaultValueFromPath(t *testing.T) {
t.Parallel()

type testCase struct {
request planmodifier.ListRequest
expected planmodifier.ListResponse
}

testSchema := schema.Schema{
Attributes: map[string]schema.Attribute{
"src": schema.ListAttribute{
ElementType: types.StringType,
},
"dst": schema.ListAttribute{
ElementType: types.StringType,
},
},
}
nullState := tfsdk.State{
Schema: testSchema,
Raw: tftypes.NewValue(
testSchema.Type().TerraformType(context.Background()),
nil,
),
}
testPlan := func(src, dst types.List) tfsdk.Plan {
tfSrc, err := src.ToTerraformValue(context.Background())

if err != nil {
panic("ToTerraformValue error: " + err.Error())
}

tfDst, err := dst.ToTerraformValue(context.Background())

if err != nil {
panic("ToTerraformValue error: " + err.Error())
}

return tfsdk.Plan{
Schema: testSchema,
Raw: tftypes.NewValue(
testSchema.Type().TerraformType(context.Background()),
map[string]tftypes.Value{
"src": tfSrc,
"dst": tfDst,
},
),
}
}
testState := func(src, dst types.List) tfsdk.State {
tfSrc, err := src.ToTerraformValue(context.Background())

if err != nil {
panic("ToTerraformValue error: " + err.Error())
}

tfDst, err := dst.ToTerraformValue(context.Background())

if err != nil {
panic("ToTerraformValue error: " + err.Error())
}

return tfsdk.State{
Schema: testSchema,
Raw: tftypes.NewValue(
testSchema.Type().TerraformType(context.Background()),
map[string]tftypes.Value{
"src": tfSrc,
"dst": tfDst,
},
),
}
}
defaultValue := types.ListValueMust(types.StringType, []attr.Value{types.StringValue("default-value")})
computedValue := types.ListValueMust(types.StringType, []attr.Value{types.StringValue("computed-value")})
configuredValue := types.ListValueMust(types.StringType, []attr.Value{types.StringValue("configured-value")})

tests := map[string]testCase{
"unknown value on create": {
request: planmodifier.ListRequest{
State: nullState,
StateValue: types.ListNull(types.StringType),
Plan: testPlan(defaultValue, types.ListUnknown(types.StringType)),
PlanValue: types.ListUnknown(types.StringType),
},
expected: planmodifier.ListResponse{
PlanValue: defaultValue,
},
},
"unknown value on update": {
request: planmodifier.ListRequest{
State: testState(defaultValue, computedValue),
StateValue: computedValue,
Plan: testPlan(defaultValue, types.ListUnknown(types.StringType)),
PlanValue: types.ListUnknown(types.StringType),
},
expected: planmodifier.ListResponse{
PlanValue: defaultValue,
},
},
"null known value on create": {
request: planmodifier.ListRequest{
State: nullState,
StateValue: types.ListNull(types.StringType),
Plan: testPlan(types.ListNull(types.StringType), types.ListUnknown(types.StringType)),
PlanValue: types.ListUnknown(types.StringType),
},
expected: planmodifier.ListResponse{
PlanValue: types.ListNull(types.StringType),
},
},
"null known value on update": {
request: planmodifier.ListRequest{
State: testState(defaultValue, computedValue),
StateValue: computedValue,
Plan: testPlan(types.ListNull(types.StringType), types.ListUnknown(types.StringType)),
PlanValue: types.ListUnknown(types.StringType),
},
expected: planmodifier.ListResponse{
PlanValue: types.ListNull(types.StringType),
},
},
"non-null known value on create": {
request: planmodifier.ListRequest{
State: nullState,
StateValue: types.ListNull(types.StringType),
Plan: testPlan(defaultValue, configuredValue),
PlanValue: configuredValue,
},
expected: planmodifier.ListResponse{
PlanValue: configuredValue,
},
},
"non-null known value on update": {
request: planmodifier.ListRequest{
State: testState(defaultValue, computedValue),
StateValue: computedValue,
Plan: testPlan(defaultValue, configuredValue),
PlanValue: configuredValue,
},
expected: planmodifier.ListResponse{
PlanValue: configuredValue,
},
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()

response := planmodifier.ListResponse{
PlanValue: test.request.PlanValue,
}
fwplanmodifiers.ListDefaultValueFromPath[types.List](path.Root("src")).PlanModifyList(context.Background(), test.request, &response)

if diff := cmp.Diff(test.expected, response); diff != "" {
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
}
})
}
}
19 changes: 8 additions & 11 deletions internal/framework/resource_list_of_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand All @@ -17,7 +16,7 @@ import (

// NewResourceComputedListOfObjectSchema returns a new schema.ListAttribute for objects of the specified type.
// The list is Computed-only.
func ResourceComputedListOfObjectAttribute[T any](ctx context.Context) schema.ListAttribute {
func ResourceComputedListOfObjectsAttribute[T any](ctx context.Context) schema.ListAttribute {
return schema.ListAttribute{
CustomType: fwtypes.NewListNestedObjectTypeOf[T](ctx),
Computed: true,
Expand All @@ -27,18 +26,16 @@ func ResourceComputedListOfObjectAttribute[T any](ctx context.Context) schema.Li
}
}

// ResourceOptionalComputedListOfObjectAttribute returns a new schema.ListAttribute for objects of the specified type.
// ResourceOptionalComputedListOfObjectsAttribute returns a new schema.ListAttribute for objects of the specified type.
// The list is Optional+Computed.
func ResourceOptionalComputedListOfObjectAttribute[T any](ctx context.Context) schema.ListAttribute {
func ResourceOptionalComputedListOfObjectsAttribute[T any](ctx context.Context, sizeAtMost int, planModifiers ...planmodifier.List) schema.ListAttribute {
return schema.ListAttribute{
CustomType: fwtypes.NewListNestedObjectTypeOf[T](ctx),
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.List{
listplanmodifier.UseStateForUnknown(),
},
CustomType: fwtypes.NewListNestedObjectTypeOf[T](ctx),
Optional: true,
Computed: true,
PlanModifiers: planModifiers,
Validators: []validator.List{
listvalidator.SizeAtMost(1),
listvalidator.SizeAtMost(sizeAtMost),
},
ElementType: types.ObjectType{
AttrTypes: fwtypes.AttributeTypesMust[T](ctx),
Expand Down
11 changes: 9 additions & 2 deletions internal/framework/types/objectof.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,16 @@ func (t objectTypeOf[T]) ValueFromObjectPtr(ctx context.Context, ptr any) (attr.
return nil, diags
}

func objectTypeNewObjectPtr[T any](context.Context) (*T, diag.Diagnostics) {
func objectTypeNewObjectPtr[T any](ctx context.Context) (*T, diag.Diagnostics) {
var diags diag.Diagnostics
return new(T), diags

t := new(T)
diags.Append(NullOutObjectPtrFields(ctx, t)...)
if diags.HasError() {
return nil, diags
}

return t, diags
}

// NullOutObjectPtrFields sets all applicable fields of the specified object pointer to their null values.
Expand Down
4 changes: 2 additions & 2 deletions internal/service/bedrock/custom_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ func (r *customModelResource) Schema(ctx context.Context, request resource.Schem
},
names.AttrTags: tftags.TagsAttribute(),
names.AttrTagsAll: tftags.TagsAttributeComputedOnly(),
"training_metrics": framework.ResourceComputedListOfObjectAttribute[trainingMetricsModel](ctx),
"validation_metrics": framework.ResourceComputedListOfObjectAttribute[validatorMetricModel](ctx),
"training_metrics": framework.ResourceComputedListOfObjectsAttribute[trainingMetricsModel](ctx),
"validation_metrics": framework.ResourceComputedListOfObjectsAttribute[validatorMetricModel](ctx),
},
Blocks: map[string]schema.Block{
"output_data_config": schema.ListNestedBlock{
Expand Down
2 changes: 1 addition & 1 deletion internal/service/bedrock/inference_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *resourceInferenceProfile) Metadata(_ context.Context, req resource.Meta
}

func (r *resourceInferenceProfile) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
modelsAttribute := framework.ResourceComputedListOfObjectAttribute[resourceInferenceProfileModelModel](ctx)
modelsAttribute := framework.ResourceComputedListOfObjectsAttribute[resourceInferenceProfileModelModel](ctx)
modelsAttribute.PlanModifiers = []planmodifier.List{
listplanmodifier.UseStateForUnknown(),
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/logs/delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (r *deliveryResource) Schema(ctx context.Context, request resource.SchemaRe
listplanmodifier.UseStateForUnknown(),
},
},
"s3_delivery_configuration": framework.ResourceOptionalComputedListOfObjectAttribute[s3DeliveryConfigurationModel](ctx),
"s3_delivery_configuration": framework.ResourceOptionalComputedListOfObjectsAttribute[s3DeliveryConfigurationModel](ctx, 1, listplanmodifier.UseStateForUnknown()),
names.AttrTags: tftags.TagsAttribute(),
names.AttrTagsAll: tftags.TagsAttributeComputedOnly(),
},
Expand Down
10 changes: 10 additions & 0 deletions internal/service/route53/exports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package route53

// Exports for use in other modules.
var (
DeleteHostedZone = deleteHostedZone
FindPublicHostedZoneIDByDomainName = findPublicHostedZoneIDByDomainName
)
Loading
Loading