Skip to content

Commit

Permalink
Merge pull request #31037 from hashicorp/f-ds-trust
Browse files Browse the repository at this point in the history
resource/aws_directory_service_trust: New resource
  • Loading branch information
gdavison authored Apr 28, 2023
2 parents 47ad89b + b0fc68c commit 87c47ac
Show file tree
Hide file tree
Showing 31 changed files with 2,962 additions and 300 deletions.
11 changes: 11 additions & 0 deletions .changelog/31037.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:new-resource
aws_directory_service_trust
```

```release-note:enhancement
resource/aws_directory_service_conditional_forwarder: Add plan time validation for `remote_domain_name`
```

```release-note:enhancement
resource/aws_directory_service_directory: Correct plan time validation for `remote_domain_name`
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.20.10
github.com/aws/aws-sdk-go-v2/service/comprehend v1.24.1
github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.22.3
github.com/aws/aws-sdk-go-v2/service/directoryservice v1.17.0
github.com/aws/aws-sdk-go-v2/service/docdbelastic v1.1.9
github.com/aws/aws-sdk-go-v2/service/ec2 v1.95.0
github.com/aws/aws-sdk-go-v2/service/fis v1.14.9
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ github.com/aws/aws-sdk-go-v2/service/comprehend v1.24.1 h1:9xO1KwU+O/46RWd71hD/P
github.com/aws/aws-sdk-go-v2/service/comprehend v1.24.1/go.mod h1:YDZOE9XpbohvywpWpxDCPIEWlpALTsR+o6Ny6UgHXeE=
github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.22.3 h1:en+3QBMfCbuCiR2WQs1usrUXRxpk2nO+jLaMCfWBiG0=
github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.22.3/go.mod h1:5kTfX+bDwent5HUSiSwMtYSDw57gZ7hkQSv+x2jJmtg=
github.com/aws/aws-sdk-go-v2/service/directoryservice v1.17.0 h1:C90Pr/krI6FueltX8Hf5Q5bcRHSGMdZtg2ox/Vydo58=
github.com/aws/aws-sdk-go-v2/service/directoryservice v1.17.0/go.mod h1:tjEH79gyftglvYJMPGSachjqhthFaVYjco94mJ5ANcY=
github.com/aws/aws-sdk-go-v2/service/docdbelastic v1.1.9 h1:i0EcejgfQnu1FlP80hVSkRK1BN6GrAQBTTDFWb/aT2o=
github.com/aws/aws-sdk-go-v2/service/docdbelastic v1.1.9/go.mod h1:PjV/8ElvXTf1jbcjaGvUphvb8Sz4/lTP87GFhQrZGbk=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.95.0 h1:onLRCalR9kNt/XnhaQ3yo/IlYf+VPv6uogJkXD43mGM=
Expand Down
6 changes: 6 additions & 0 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions internal/conns/config_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/framework/validators/arn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"context"

"github.com/aws/aws-sdk-go-v2/aws/arn"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

type arnValidator struct{}

func (validator arnValidator) Description(_ context.Context) string {
return "An Amazon Resource Name"
return "value must be a valid Amazon Resource Name"
}

func (validator arnValidator) MarkdownDescription(ctx context.Context) string {
Expand All @@ -24,10 +24,10 @@ func (validator arnValidator) ValidateString(ctx context.Context, request valida
}

if !arn.IsARN(request.ConfigValue.ValueString()) {
response.Diagnostics.Append(diag.NewAttributeErrorDiagnostic(
response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
request.Path,
validator.Description(ctx),
"value must be a valid ARN",
request.ConfigValue.ValueString(),
))
return
}
Expand Down
24 changes: 14 additions & 10 deletions internal/framework/validators/arn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand All @@ -14,8 +16,8 @@ func TestARNValidator(t *testing.T) {
t.Parallel()

type testCase struct {
val types.String
expectError bool
val types.String
expectedDiagnostics diag.Diagnostics
}

tests := map[string]testCase{
Expand All @@ -29,8 +31,14 @@ func TestARNValidator(t *testing.T) {
val: types.StringValue("arn:aws:iam::aws:policy/CloudWatchReadOnlyAccess"),
},
"invalid_arn": {
val: types.StringValue("arn"),
expectError: true,
val: types.StringValue("arn"),
expectedDiagnostics: diag.Diagnostics{
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value",
`Attribute test value must be a valid Amazon Resource Name, got: arn`,
),
},
},
}

Expand All @@ -47,12 +55,8 @@ func TestARNValidator(t *testing.T) {
response := validator.StringResponse{}
fwvalidators.ARN().ValidateString(context.Background(), request, &response)

if !response.Diagnostics.HasError() && test.expectError {
t.Fatal("expected error, got no error")
}

if response.Diagnostics.HasError() && !test.expectError {
t.Fatalf("got unexpected error: %s", response.Diagnostics)
if diff := cmp.Diff(response.Diagnostics, test.expectedDiagnostics); diff != "" {
t.Errorf("unexpected diagnostics difference: %s", diff)
}
})
}
Expand Down
10 changes: 5 additions & 5 deletions internal/framework/validators/cidr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package validators
import (
"context"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)
Expand All @@ -28,10 +28,10 @@ func (validator ipv4CIDRNetworkAddressValidator) ValidateString(ctx context.Cont
}

if err := verify.ValidateIPv4CIDRBlock(request.ConfigValue.ValueString()); err != nil {
response.Diagnostics.Append(diag.NewAttributeErrorDiagnostic(
response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
request.Path,
validator.Description(ctx),
err.Error(),
request.ConfigValue.ValueString(),
))
return
}
Expand Down Expand Up @@ -67,10 +67,10 @@ func (validator ipv6CIDRNetworkAddressValidator) ValidateString(ctx context.Cont
}

if err := verify.ValidateIPv6CIDRBlock(request.ConfigValue.ValueString()); err != nil {
response.Diagnostics.Append(diag.NewAttributeErrorDiagnostic(
response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
request.Path,
validator.Description(ctx),
err.Error(),
request.ConfigValue.ValueString(),
))

return
Expand Down
94 changes: 64 additions & 30 deletions internal/framework/validators/cidr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand All @@ -14,8 +16,8 @@ func TestIPv4CIDRNetworkAddressValidator(t *testing.T) {
t.Parallel()

type testCase struct {
val types.String
expectError bool
val types.String
expectedDiagnostics diag.Diagnostics
}
tests := map[string]testCase{
"unknown String": {
Expand All @@ -25,19 +27,37 @@ func TestIPv4CIDRNetworkAddressValidator(t *testing.T) {
val: types.StringNull(),
},
"invalid String": {
val: types.StringValue("test-value"),
expectError: true,
val: types.StringValue("test-value"),
expectedDiagnostics: diag.Diagnostics{
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value",
`Attribute test value must be a valid IPv4 CIDR that represents a network address, got: test-value`,
),
},
},
"valid IPv4 CIDR": {
val: types.StringValue("10.2.2.0/24"),
},
"invalid IPv4 CIDR": {
val: types.StringValue("10.2.2.2/24"),
expectError: true,
val: types.StringValue("10.2.2.2/24"),
expectedDiagnostics: diag.Diagnostics{
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value",
`Attribute test value must be a valid IPv4 CIDR that represents a network address, got: 10.2.2.2/24`,
),
},
},
"valid IPv6 CIDR": {
val: types.StringValue("2001:db8::/122"),
expectError: true,
val: types.StringValue("2001:db8::/122"),
expectedDiagnostics: diag.Diagnostics{
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value",
`Attribute test value must be a valid IPv4 CIDR that represents a network address, got: 2001:db8::/122`,
),
},
},
}

Expand All @@ -46,20 +66,18 @@ func TestIPv4CIDRNetworkAddressValidator(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

ctx := context.Background()

request := validator.StringRequest{
Path: path.Root("test"),
PathExpression: path.MatchRoot("test"),
ConfigValue: test.val,
}
response := validator.StringResponse{}
fwvalidators.IPv4CIDRNetworkAddress().ValidateString(context.Background(), request, &response)

if !response.Diagnostics.HasError() && test.expectError {
t.Fatal("expected error, got no error")
}
fwvalidators.IPv4CIDRNetworkAddress().ValidateString(ctx, request, &response)

if response.Diagnostics.HasError() && !test.expectError {
t.Fatalf("got unexpected error: %s", response.Diagnostics)
if diff := cmp.Diff(response.Diagnostics, test.expectedDiagnostics); diff != "" {
t.Errorf("unexpected diagnostics difference: %s", diff)
}
})
}
Expand All @@ -69,8 +87,8 @@ func TestIPv6CIDRNetworkAddressValidator(t *testing.T) {
t.Parallel()

type testCase struct {
val types.String
expectError bool
val types.String
expectedDiagnostics diag.Diagnostics
}
tests := map[string]testCase{
"unknown String": {
Expand All @@ -80,19 +98,37 @@ func TestIPv6CIDRNetworkAddressValidator(t *testing.T) {
val: types.StringNull(),
},
"invalid String": {
val: types.StringValue("test-value"),
expectError: true,
val: types.StringValue("test-value"),
expectedDiagnostics: diag.Diagnostics{
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value",
`Attribute test value must be a valid IPv6 CIDR that represents a network address, got: test-value`,
),
},
},
"valid IPv6 CIDR": {
val: types.StringValue("2001:db8::/122"),
},
"invalid IPv6 CIDR": {
val: types.StringValue("2001::/15"),
expectError: true,
val: types.StringValue("2001::/15"),
expectedDiagnostics: diag.Diagnostics{
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value",
`Attribute test value must be a valid IPv6 CIDR that represents a network address, got: 2001::/15`,
),
},
},
"valid IPv4 CIDR": {
val: types.StringValue("10.2.2.0/24"),
expectError: true,
val: types.StringValue("10.2.2.0/24"),
expectedDiagnostics: diag.Diagnostics{
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value",
`Attribute test value must be a valid IPv6 CIDR that represents a network address, got: 10.2.2.0/24`,
),
},
},
}

Expand All @@ -101,20 +137,18 @@ func TestIPv6CIDRNetworkAddressValidator(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

ctx := context.Background()

request := validator.StringRequest{
Path: path.Root("test"),
PathExpression: path.MatchRoot("test"),
ConfigValue: test.val,
}
response := validator.StringResponse{}
fwvalidators.IPv6CIDRNetworkAddress().ValidateString(context.Background(), request, &response)

if !response.Diagnostics.HasError() && test.expectError {
t.Fatal("expected error, got no error")
}
fwvalidators.IPv6CIDRNetworkAddress().ValidateString(ctx, request, &response)

if response.Diagnostics.HasError() && !test.expectError {
t.Fatalf("got unexpected error: %s", response.Diagnostics)
if diff := cmp.Diff(response.Diagnostics, test.expectedDiagnostics); diff != "" {
t.Errorf("unexpected diagnostics difference: %s", diff)
}
})
}
Expand Down
Loading

0 comments on commit 87c47ac

Please sign in to comment.