88
99 "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
1010 secretmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/models"
11+ "github.com/hashicorp/terraform-plugin-framework-validators/objectvalidator"
1112 "github.com/hashicorp/terraform-plugin-framework/diag"
1213 "github.com/hashicorp/terraform-plugin-framework/path"
1314 "github.com/hashicorp/terraform-plugin-framework/resource"
@@ -18,11 +19,19 @@ import (
1819 "github.com/hashicorp/terraform-plugin-framework/types"
1920 "github.com/hashicorp/terraform-plugin-framework/types/basetypes"
2021 "github.com/hashicorp/terraform-provider-hcp/internal/clients"
22+ "github.com/hashicorp/terraform-provider-hcp/internal/provider/modifiers"
2123)
2224
2325var _ hvsResource = & Sync {}
2426
27+ var exactlyOneSyncConfigFieldsValidator = objectvalidator .ExactlyOneOf (
28+ path.Expressions {
29+ path .MatchRoot ("gitlab_config" ),
30+ }... ,
31+ )
32+
2533type Sync struct {
34+ ID types.String `tfsdk:"id"`
2635 Name types.String `tfsdk:"name"`
2736 IntegrationName types.String `tfsdk:"integration_name"`
2837 ProjectID types.String `tfsdk:"project_id"`
@@ -35,11 +44,14 @@ type Sync struct {
3544 gitlabConfig * secretmodels.Secrets20231128SyncConfigGitlab `tfsdk:"-"`
3645}
3746
47+ func (s * Sync ) projectID () types.String {
48+ return s .ProjectID
49+ }
50+
3851type gitlabConfigParams struct {
39- EnvironmentScope types.String `tfsdk:"environment_scope"`
40- Scope types.String `tfsdk:"scope"`
41- GroupID types.String `tfsdk:"group_id"`
42- ProjectID types.String `tfsdk:"project_id"`
52+ Scope types.String `tfsdk:"scope"`
53+ GroupID types.String `tfsdk:"group_id"`
54+ ProjectID types.String `tfsdk:"project_id"`
4355}
4456
4557func (s * Sync ) initModel (ctx context.Context , orgID , projID string ) diag.Diagnostics {
@@ -56,23 +68,18 @@ func (s *Sync) initModel(ctx context.Context, orgID, projID string) diag.Diagnos
5668 scope := secretmodels .SyncConfigGitlabScope (config .Scope .ValueString ())
5769
5870 s .gitlabConfig = & secretmodels.Secrets20231128SyncConfigGitlab {
59- EnvironmentScope : config .EnvironmentScope .ValueString (),
60- GroupID : config .GroupID .ValueString (),
61- ProjectID : config .ProjectID .ValueString (),
62- Protected : false ,
63- Raw : false ,
64- Scope : & scope ,
71+ GroupID : config .GroupID .ValueString (),
72+ ProjectID : config .ProjectID .ValueString (),
73+ Protected : false ,
74+ Raw : false ,
75+ Scope : & scope ,
6576 }
6677 }
6778
6879 return diag.Diagnostics {}
6980}
7081
71- func (s * Sync ) projectID () types.String {
72- return s .ProjectID
73- }
74-
75- func (s * Sync ) fromModel (_ context.Context , orgID , projID string , model any ) diag.Diagnostics {
82+ func (s * Sync ) fromModel (ctx context.Context , orgID , projID string , model any ) diag.Diagnostics {
7683 diags := diag.Diagnostics {}
7784
7885 syncModel , ok := model .(* secretmodels.Secrets20231128Sync )
@@ -85,11 +92,15 @@ func (s *Sync) fromModel(_ context.Context, orgID, projID string, model any) dia
8592 s .IntegrationName = types .StringValue (syncModel .IntegrationName )
8693 s .OrganizationID = types .StringValue (orgID )
8794 s .ProjectID = types .StringValue (projID )
95+ s .ID = types .StringValue (syncModel .ResourceID )
8896
8997 return diags
9098}
9199
92100var _ resource.Resource = & resourceVaultSecretsSync {}
101+ var _ resource.ResourceWithConfigure = & resourceVaultSecretsSync {}
102+ var _ resource.ResourceWithModifyPlan = & resourceVaultSecretsSync {}
103+ var _ resource.ResourceWithImportState = & resourceVaultSecretsSync {}
93104
94105func NewVaultSecretsSyncResource () resource.Resource {
95106 return & resourceVaultSecretsSync {}
@@ -149,7 +160,7 @@ func (r *resourceVaultSecretsSync) Schema(_ context.Context, _ resource.SchemaRe
149160 },
150161 },
151162 Validators : []validator.Object {
152- exactlyOneIntegrationTypeFieldsValidator ,
163+ exactlyOneSyncConfigFieldsValidator ,
153164 },
154165 },
155166 }
@@ -162,6 +173,25 @@ func (r *resourceVaultSecretsSync) Schema(_ context.Context, _ resource.SchemaRe
162173 }
163174}
164175
176+ func (r * resourceVaultSecretsSync ) Configure (_ context.Context , req resource.ConfigureRequest , resp * resource.ConfigureResponse ) {
177+ if req .ProviderData == nil {
178+ return
179+ }
180+ client , ok := req .ProviderData .(* clients.Client )
181+ if ! ok {
182+ resp .Diagnostics .AddError (
183+ "Unexpected Data Source Configure Type" ,
184+ fmt .Sprintf ("Expected *clients.Client, got: %T. Please report this issue to the provider developers." , req .ProviderData ),
185+ )
186+ return
187+ }
188+ r .client = client
189+ }
190+
191+ func (r * resourceVaultSecretsSync ) ModifyPlan (ctx context.Context , req resource.ModifyPlanRequest , resp * resource.ModifyPlanResponse ) {
192+ modifiers .ModifyPlanForDefaultProjectChange (ctx , r .client .Config .ProjectID , req .State , req .Config , req .Plan , resp )
193+ }
194+
165195func (r * resourceVaultSecretsSync ) Read (ctx context.Context , req resource.ReadRequest , resp * resource.ReadResponse ) {
166196 resp .Diagnostics .Append (decorateOperation [* Sync ](ctx , r .client , & resp .State , req .State .Get , "reading" , func (i hvsResource ) (any , error ) {
167197 sync , ok := i .(* Sync )
0 commit comments