Skip to content

Commit 231a1bb

Browse files
committed
Add Resource Identity and List Resource for
aws_neptunegraph_graph
1 parent 7f2b21b commit 231a1bb

12 files changed

Lines changed: 387 additions & 4 deletions

File tree

internal/service/neptunegraph/graph.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ import (
4242
)
4343

4444
// @FrameworkResource("aws_neptunegraph_graph", name="Graph")
45+
// @IdentityAttribute("id")
4546
// @Tags(identifierAttribute="arn")
47+
// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/neptunegraph;neptunegraph.GetGraphOutput")
48+
// @Testing(preIdentityVersion="v6.44.0")
4649
func newGraphResource(_ context.Context) (resource.ResourceWithConfigure, error) {
4750
r := &graphResource{}
4851

@@ -55,7 +58,7 @@ func newGraphResource(_ context.Context) (resource.ResourceWithConfigure, error)
5558

5659
type graphResource struct {
5760
framework.ResourceWithModel[graphResourceModel]
58-
framework.WithImportByID
61+
framework.WithImportByIdentity
5962
framework.WithTimeouts
6063
}
6164

@@ -332,7 +335,7 @@ func (r *graphResource) Create(ctx context.Context, request resource.CreateReque
332335
create.WithConfiguredName(data.Name.ValueString()),
333336
create.WithConfiguredPrefix(data.NamePrefix.ValueString()),
334337
create.WithDefaultPrefix("tf-"),
335-
).Generate()
338+
).Generate(ctx)
336339

337340
// Determine whether to use CreateGraphUsingImportTask or CreateGraph API
338341
if !data.ImportTask.IsNull() && !data.ImportTask.IsUnknown() {
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright IBM Corp. 2014, 2026
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package neptunegraph
5+
6+
import (
7+
"context"
8+
"fmt"
9+
"iter"
10+
11+
"github.com/aws/aws-sdk-go-v2/aws"
12+
"github.com/aws/aws-sdk-go-v2/service/neptunegraph"
13+
awstypes "github.com/aws/aws-sdk-go-v2/service/neptunegraph/types"
14+
"github.com/hashicorp/terraform-plugin-framework/list"
15+
"github.com/hashicorp/terraform-plugin-log/tflog"
16+
"github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag"
17+
"github.com/hashicorp/terraform-provider-aws/internal/framework"
18+
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
19+
"github.com/hashicorp/terraform-provider-aws/internal/logging"
20+
"github.com/hashicorp/terraform-provider-aws/names"
21+
)
22+
23+
// Function annotations are used for list resource registration to the Provider. DO NOT EDIT.
24+
// @FrameworkListResource("aws_neptunegraph_graph")
25+
func newGraphResourceAsListResource() list.ListResourceWithConfigure {
26+
return &listResourceGraph{}
27+
}
28+
29+
var _ list.ListResource = &listResourceGraph{}
30+
31+
type listResourceGraph struct {
32+
graphResource
33+
framework.WithList
34+
}
35+
36+
type listGraphModel struct {
37+
framework.WithRegionModel
38+
}
39+
40+
func (l *listResourceGraph) List(ctx context.Context, request list.ListRequest, stream *list.ListResultsStream) {
41+
var query listGraphModel
42+
if request.Config.Raw.IsKnown() && !request.Config.Raw.IsNull() {
43+
if diags := request.Config.Get(ctx, &query); diags.HasError() {
44+
stream.Results = list.ListResultsStreamDiagnostics(diags)
45+
return
46+
}
47+
}
48+
49+
conn := l.Meta().NeptuneGraphClient(ctx)
50+
51+
tflog.Info(ctx, "Listing Neptune Analytics Graphs")
52+
53+
stream.Results = func(yield func(list.ListResult) bool) {
54+
var input neptunegraph.ListGraphsInput
55+
for item, err := range listGraphs(ctx, conn, &input) {
56+
if err != nil {
57+
result := fwdiag.NewListResultErrorDiagnostic(err)
58+
yield(result)
59+
return
60+
}
61+
62+
id := aws.ToString(item.Id)
63+
ctx := tflog.SetField(ctx, logging.ResourceAttributeKey(names.AttrID), id)
64+
65+
result := request.NewListResult(ctx)
66+
67+
var data graphResourceModel
68+
l.SetResult(ctx, l.Meta(), request.IncludeResource, &data, &result, func() {
69+
if request.IncludeResource {
70+
graph, err := findGraphByID(ctx, conn, id)
71+
if err != nil {
72+
tflog.Error(ctx, "Reading Neptune Analytics Graph", map[string]any{
73+
"error": err.Error(),
74+
})
75+
return
76+
}
77+
result.Diagnostics.Append(fwflex.Flatten(ctx, graph, &data)...)
78+
} else {
79+
data.ID = fwflex.StringToFramework(ctx, item.Id)
80+
}
81+
result.DisplayName = aws.ToString(item.Name)
82+
})
83+
84+
if result.Diagnostics.HasError() {
85+
yield(result)
86+
return
87+
}
88+
89+
if !yield(result) {
90+
return
91+
}
92+
}
93+
}
94+
}
95+
96+
func listGraphs(ctx context.Context, conn *neptunegraph.Client, input *neptunegraph.ListGraphsInput) iter.Seq2[awstypes.GraphSummary, error] {
97+
return func(yield func(awstypes.GraphSummary, error) bool) {
98+
pages := neptunegraph.NewListGraphsPaginator(conn, input)
99+
for pages.HasMorePages() {
100+
page, err := pages.NextPage(ctx)
101+
if err != nil {
102+
yield(awstypes.GraphSummary{}, fmt.Errorf("listing Neptune Analytics Graph resources: %w", err))
103+
return
104+
}
105+
106+
for _, item := range page.Graphs {
107+
if !yield(item, nil) {
108+
return
109+
}
110+
}
111+
}
112+
}
113+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// Copyright IBM Corp. 2014, 2026
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package neptunegraph_test
5+
6+
import (
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-testing/config"
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
12+
"github.com/hashicorp/terraform-plugin-testing/querycheck"
13+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
14+
"github.com/hashicorp/terraform-plugin-testing/tfversion"
15+
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
16+
tfquerycheck "github.com/hashicorp/terraform-provider-aws/internal/acctest/querycheck"
17+
tfqueryfilter "github.com/hashicorp/terraform-provider-aws/internal/acctest/queryfilter"
18+
tfstatecheck "github.com/hashicorp/terraform-provider-aws/internal/acctest/statecheck"
19+
"github.com/hashicorp/terraform-provider-aws/names"
20+
)
21+
22+
func TestAccNeptuneGraphGraph_List_basic(t *testing.T) {
23+
ctx := acctest.Context(t)
24+
25+
resourceName := "aws_neptunegraph_graph.test"
26+
rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
27+
28+
identity := tfstatecheck.Identity()
29+
30+
acctest.ParallelTest(ctx, t, resource.TestCase{
31+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
32+
tfversion.SkipBelow(tfversion.Version1_14_0),
33+
},
34+
PreCheck: func() { acctest.PreCheck(ctx, t) },
35+
ErrorCheck: acctest.ErrorCheck(t, names.NeptuneGraphServiceID),
36+
CheckDestroy: testAccCheckGraphDestroy(ctx, t),
37+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
38+
Steps: []resource.TestStep{
39+
{
40+
ConfigDirectory: config.StaticDirectory("testdata/Graph/list_basic/"),
41+
ConfigVariables: config.Variables{
42+
acctest.CtRName: config.StringVariable(rName),
43+
},
44+
ConfigStateChecks: []statecheck.StateCheck{
45+
identity.GetIdentity(resourceName),
46+
},
47+
},
48+
{
49+
Query: true,
50+
ConfigDirectory: config.StaticDirectory("testdata/Graph/list_basic/"),
51+
ConfigVariables: config.Variables{
52+
acctest.CtRName: config.StringVariable(rName),
53+
},
54+
QueryResultChecks: []querycheck.QueryResultCheck{
55+
tfquerycheck.ExpectIdentityFunc("aws_neptunegraph_graph.test", identity.Checks()),
56+
querycheck.ExpectResourceDisplayName("aws_neptunegraph_graph.test", tfqueryfilter.ByResourceIdentityFunc(identity.Checks()), knownvalue.StringExact(rName)),
57+
tfquerycheck.ExpectNoResourceObject("aws_neptunegraph_graph.test", tfqueryfilter.ByResourceIdentityFunc(identity.Checks())),
58+
},
59+
},
60+
},
61+
})
62+
}
63+
64+
func TestAccNeptuneGraphGraph_List_includeResource(t *testing.T) {
65+
ctx := acctest.Context(t)
66+
67+
resourceName := "aws_neptunegraph_graph.test"
68+
rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
69+
70+
identity := tfstatecheck.Identity()
71+
72+
acctest.ParallelTest(ctx, t, resource.TestCase{
73+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
74+
tfversion.SkipBelow(tfversion.Version1_14_0),
75+
},
76+
PreCheck: func() { acctest.PreCheck(ctx, t) },
77+
ErrorCheck: acctest.ErrorCheck(t, names.NeptuneGraphServiceID),
78+
CheckDestroy: testAccCheckGraphDestroy(ctx, t),
79+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
80+
Steps: []resource.TestStep{
81+
{
82+
ConfigDirectory: config.StaticDirectory("testdata/Graph/list_include_resource/"),
83+
ConfigVariables: config.Variables{
84+
acctest.CtRName: config.StringVariable(rName),
85+
},
86+
ConfigStateChecks: []statecheck.StateCheck{
87+
identity.GetIdentity(resourceName),
88+
},
89+
},
90+
{
91+
Query: true,
92+
ConfigDirectory: config.StaticDirectory("testdata/Graph/list_include_resource/"),
93+
ConfigVariables: config.Variables{
94+
acctest.CtRName: config.StringVariable(rName),
95+
},
96+
QueryResultChecks: []querycheck.QueryResultCheck{
97+
tfquerycheck.ExpectIdentityFunc("aws_neptunegraph_graph.test", identity.Checks()),
98+
querycheck.ExpectResourceDisplayName("aws_neptunegraph_graph.test", tfqueryfilter.ByResourceIdentityFunc(identity.Checks()), knownvalue.StringExact(rName)),
99+
},
100+
},
101+
},
102+
})
103+
}
104+
105+
func TestAccNeptuneGraphGraph_List_regionOverride(t *testing.T) {
106+
ctx := acctest.Context(t)
107+
108+
resourceName := "aws_neptunegraph_graph.test"
109+
rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
110+
111+
identity := tfstatecheck.Identity()
112+
113+
acctest.ParallelTest(ctx, t, resource.TestCase{
114+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
115+
tfversion.SkipBelow(tfversion.Version1_14_0),
116+
},
117+
PreCheck: func() {
118+
acctest.PreCheck(ctx, t)
119+
acctest.PreCheckMultipleRegion(t, 2)
120+
},
121+
ErrorCheck: acctest.ErrorCheck(t, names.NeptuneGraphServiceID),
122+
CheckDestroy: testAccCheckGraphDestroy(ctx, t),
123+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
124+
Steps: []resource.TestStep{
125+
{
126+
ConfigDirectory: config.StaticDirectory("testdata/Graph/list_region_override/"),
127+
ConfigVariables: config.Variables{
128+
acctest.CtRName: config.StringVariable(rName),
129+
"region": config.StringVariable(acctest.AlternateRegion()),
130+
},
131+
ConfigStateChecks: []statecheck.StateCheck{
132+
identity.GetIdentity(resourceName),
133+
},
134+
},
135+
{
136+
Query: true,
137+
ConfigDirectory: config.StaticDirectory("testdata/Graph/list_region_override/"),
138+
ConfigVariables: config.Variables{
139+
acctest.CtRName: config.StringVariable(rName),
140+
"region": config.StringVariable(acctest.AlternateRegion()),
141+
},
142+
QueryResultChecks: []querycheck.QueryResultCheck{
143+
tfquerycheck.ExpectIdentityFunc("aws_neptunegraph_graph.test", identity.Checks()),
144+
},
145+
},
146+
},
147+
})
148+
}

internal/service/neptunegraph/graph_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ func TestAccNeptuneGraphGraph_fromNeptuneDB(t *testing.T) {
841841
rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
842842
resourceName := "aws_neptunegraph_graph.test"
843843

844-
resource.Test(t, resource.TestCase{
844+
acctest.Test(ctx, t, resource.TestCase{
845845
PreCheck: func() {
846846
acctest.PreCheck(ctx, t)
847847
testAccPreCheck(ctx, t)

internal/service/neptunegraph/service_package_gen.go

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright IBM Corp. 2014, 2026
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
resource "aws_neptunegraph_graph" "test" {
5+
graph_name = var.rName
6+
provisioned_memory = 16
7+
deletion_protection = false
8+
}
9+
10+
variable "rName" {
11+
description = "Name for resource"
12+
type = string
13+
nullable = false
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright IBM Corp. 2014, 2026
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
list "aws_neptunegraph_graph" "test" {
5+
provider = aws
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright IBM Corp. 2014, 2026
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
resource "aws_neptunegraph_graph" "test" {
5+
graph_name = var.rName
6+
provisioned_memory = 16
7+
deletion_protection = false
8+
}
9+
10+
variable "rName" {
11+
description = "Name for resource"
12+
type = string
13+
nullable = false
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright IBM Corp. 2014, 2026
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
list "aws_neptunegraph_graph" "test" {
5+
provider = aws
6+
7+
include_resource = true
8+
}

0 commit comments

Comments
 (0)