Skip to content

Commit

Permalink
refactor: add ForceNew fields
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Feb 7, 2025
1 parent ca3d3fc commit 67b39b4
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 54 deletions.
1 change: 1 addition & 0 deletions internal/sdkprovider/service/account/account_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func resourceAccountTeamRead(ctx context.Context, d *schema.ResourceData, client
d,
resp,
schemautil.RenameAlias("team_name", "name"),
schemautil.AddForceNew("account_id", accountID),
); err != nil {
return err
}
Expand Down
11 changes: 2 additions & 9 deletions internal/sdkprovider/service/account/account_team_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,11 @@ func resourceAccountTeamMemberRead(ctx context.Context, d *schema.ResourceData,
aivenAccountTeamMemberSchema,
d,
invite,
schemautil.RenameAliases(map[string]string{}),
schemautil.AddForceNew("account_id", accountID),
); err != nil {
return err
}

if err = d.Set("account_id", accountID); err != nil {
return err
}

// if a user is in the invitations list, it means invitation was sent but not yet accepted
if err = d.Set("accepted", false); err != nil {
return err
Expand All @@ -149,14 +145,11 @@ func resourceAccountTeamMemberRead(ctx context.Context, d *schema.ResourceData,
aivenAccountTeamMemberSchema,
d,
member,
schemautil.AddForceNew("account_id", accountID),
); err != nil {
return err
}

if err = d.Set("account_id", accountID); err != nil {
return err
}

// when a user accepts an invitation, it will appear in the member's list
// and disappear from invitations list
if err = d.Set("accepted", true); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ func resourceAlloyDBOmniDatabaseRead(ctx context.Context, d *schema.ResourceData
return err
}

return schemautil.ResourceDataSet(aivenAlloyDBOmniDatabaseSchema, d, db)
return schemautil.ResourceDataSet(
aivenAlloyDBOmniDatabaseSchema, d, db,
schemautil.AddForceNew("project", projectName),
schemautil.AddForceNew("service_name", serviceName),
)
}

func resourceAlloyDBOmniDatabaseDelete(ctx context.Context, d *schema.ResourceData, client avngen.Client) error {
Expand Down
6 changes: 4 additions & 2 deletions internal/sdkprovider/service/flink/flink_jar_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func flinkJarApplicationCreate(ctx context.Context, d *schema.ResourceData, clie
}

func flinkJarApplicationRead(ctx context.Context, d *schema.ResourceData, client avngen.Client) error {
project, serviceName, applicationID, err := schemautil.SplitResourceID3(d.Id())
projectName, serviceName, applicationID, err := schemautil.SplitResourceID3(d.Id())
if err != nil {
return err
}

rsp, err := client.ServiceFlinkGetJarApplication(ctx, project, serviceName, applicationID)
rsp, err := client.ServiceFlinkGetJarApplication(ctx, projectName, serviceName, applicationID)
if err != nil {
return schemautil.ResourceReadHandleNotFound(err, d)
}
Expand All @@ -65,6 +65,8 @@ func flinkJarApplicationRead(ctx context.Context, d *schema.ResourceData, client
return schemautil.ResourceDataSet(
flinkJarApplicationSchema(), d, rsp,
schemautil.RenameAliasesReverse(flinkJarApplicationRename()),
schemautil.AddForceNew("project", projectName),
schemautil.AddForceNew("service_name", serviceName),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,21 @@ func flinkApplicationDeploymentDelete(ctx context.Context, d *schema.ResourceDat
}

func flinkApplicationDeploymentRead(ctx context.Context, d *schema.ResourceData, client avngen.Client) error {
project, serviceName, applicationID, deploymentID, err := schemautil.SplitResourceID4(d.Id())
projectName, serviceName, applicationID, deploymentID, err := schemautil.SplitResourceID4(d.Id())
if err != nil {
return err
}

rsp, err := client.ServiceFlinkGetJarApplicationDeployment(ctx, project, serviceName, applicationID, deploymentID)
rsp, err := client.ServiceFlinkGetJarApplicationDeployment(ctx, projectName, serviceName, applicationID, deploymentID)
if err != nil {
return err
}

return schemautil.ResourceDataSet(
flinkJarApplicationDeploymentSchema(), d, rsp,
schemautil.RenameAliasesReverse(flinkJarApplicationDeploymentRename()),
schemautil.AddForceNew("project", projectName),
schemautil.AddForceNew("service_name", serviceName),
schemautil.AddForceNew("application_id", applicationID),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ func flinkJarApplicationVersionCreate(ctx context.Context, d *schema.ResourceDat
}

func flinkJarApplicationVersionRead(ctx context.Context, d *schema.ResourceData, client avngen.Client) error {
project, serviceName, applicationID, version, err := schemautil.SplitResourceID4(d.Id())
projectName, serviceName, applicationID, version, err := schemautil.SplitResourceID4(d.Id())
if err != nil {
return err
}

rsp, err := client.ServiceFlinkGetJarApplicationVersion(ctx, project, serviceName, applicationID, version)
rsp, err := client.ServiceFlinkGetJarApplicationVersion(ctx, projectName, serviceName, applicationID, version)
if err != nil {
return schemautil.ResourceReadHandleNotFound(err, d)
}
Expand All @@ -136,6 +136,9 @@ func flinkJarApplicationVersionRead(ctx context.Context, d *schema.ResourceData,
return schemautil.ResourceDataSet(
flinkJarApplicationVersionSchema(), d, rsp,
schemautil.RenameAliasesReverse(flinkJarApplicationVersionRename()),
schemautil.AddForceNew("project", projectName),
schemautil.AddForceNew("service_name", serviceName),
schemautil.AddForceNew("application_id", applicationID),
)
}

Expand Down
22 changes: 15 additions & 7 deletions internal/sdkprovider/service/kafka/kafka_native_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,45 +91,53 @@ func resourceKafkaNativeACLCreate(ctx context.Context, d *schema.ResourceData, c
return err
}

project := d.Get("project").(string)
projectName := d.Get("project").(string)
serviceName := d.Get("service_name").(string)

acl, err := client.ServiceKafkaNativeAclAdd(
ctx,
project,
projectName,
serviceName,
&req,
)
if err != nil {
return err
}

err = schemautil.ResourceDataSet(aivenKafkaNativeACLSchema, d, acl)
err = schemautil.ResourceDataSet(
aivenKafkaNativeACLSchema, d, acl,
schemautil.AddForceNew("project", projectName),
schemautil.AddForceNew("service_name", serviceName),
)
if err != nil {
return err
}

d.SetId(schemautil.BuildResourceID(project, serviceName, acl.Id))
d.SetId(schemautil.BuildResourceID(projectName, serviceName, acl.Id))
return resourceKafkaNativeACLRead(ctx, d, client)
}

func resourceKafkaNativeACLRead(ctx context.Context, d *schema.ResourceData, client avngen.Client) error {
project, serviceName, aclID, err := schemautil.SplitResourceID3(d.Id())
projectName, serviceName, aclID, err := schemautil.SplitResourceID3(d.Id())
if err != nil {
return err
}

acl, err := client.ServiceKafkaNativeAclGet(
ctx,
project,
projectName,
serviceName,
aclID,
)
if err != nil {
return err
}

err = schemautil.ResourceDataSet(aivenKafkaNativeACLSchema, d, acl)
err = schemautil.ResourceDataSet(
aivenKafkaNativeACLSchema, d, acl,
schemautil.AddForceNew("project", projectName),
schemautil.AddForceNew("service_name", serviceName),
)
return err
}

Expand Down
6 changes: 4 additions & 2 deletions internal/sdkprovider/service/kafka/kafka_quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func resourceKafkaQuotaUpdate(ctx context.Context, d *schema.ResourceData, clien
}

func resourceKafkaQuotaRead(ctx context.Context, d *schema.ResourceData, client avngen.Client) error {
project, serviceName, clientID, user, err := schemautil.SplitResourceID4(d.Id())
projectName, serviceName, clientID, user, err := schemautil.SplitResourceID4(d.Id())
if err != nil {
return err
}
Expand All @@ -171,7 +171,7 @@ func resourceKafkaQuotaRead(ctx context.Context, d *schema.ResourceData, client

resp, err := client.ServiceKafkaQuotaDescribe(
ctx,
project,
projectName,
serviceName,
params...,
)
Expand All @@ -184,6 +184,8 @@ func resourceKafkaQuotaRead(ctx context.Context, d *schema.ResourceData, client
d,
resp,
schemautil.RenameAliasesReverse(quotaFieldsAliases),
schemautil.AddForceNew("project", projectName),
schemautil.AddForceNew("service_name", serviceName),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,10 @@ func resourceMirrorMakerReplicationFlowRead(ctx context.Context, d *schema.Resou
return schemautil.ResourceReadHandleNotFound(err, d)
}

if err := d.Set("project", project); err != nil {
return err
}
if err := d.Set("service_name", serviceName); err != nil {
return err
}

err = schemautil.ResourceDataSet(
aivenMirrorMakerReplicationFlowSchema, d, dto,
schemautil.AddForceNew("project", project),
schemautil.AddForceNew("service_name", serviceName),
schemautil.RenameAliasesReverse(dtoFieldsAliases),
func(m map[string]any) error {
if v, ok := m[configPropsKey]; ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,15 @@ func resourceOrganizationApplicationUserRead(ctx context.Context, d *schema.Reso
}

// Sets name and user_id
err = schemautil.ResourceDataSet(aivenOrganizationApplicationUserSchema, d, user)
err = schemautil.ResourceDataSet(
aivenOrganizationApplicationUserSchema, d, user,
schemautil.RenameAlias("user_email", "email"),
schemautil.AddForceNew("organization_id", orgID),
)
if err != nil {
return err
}

// This field has "email" in the schema and "user_email" in the request
if err = d.Set("email", user.UserEmail); err != nil {
return err
}

// This is for import command
if err = d.Set("organization_id", orgID); err != nil {
return err
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ func resourceOrganizationApplicationUserTokenRead(ctx context.Context, d *schema
return fmt.Errorf("application user token not found")
}

err = schemautil.ResourceDataSet(aivenOrganizationApplicationUserTokenSchema, d, token)
err = schemautil.ResourceDataSet(
aivenOrganizationApplicationUserTokenSchema, d, token,
schemautil.AddForceNew("organization_id", orgID),
schemautil.AddForceNew("user_id", userID),
)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,13 @@ func resourceOrganizationUserGroupRead(ctx context.Context, d *schema.ResourceDa
aivenOrganizationUserGroupSchema,
d,
resp,
schemautil.RenameAliases(map[string]string{
"user_group_name": "name",
"user_group_id": "group_id",
}),
schemautil.RenameAlias("user_group_name", "name"),
schemautil.RenameAlias("user_group_id", "group_id"),
schemautil.AddForceNew("organization_id", orgID),
); err != nil {
return err
}

// set the organization_id directly as it is not returned by the API and may not be set in case of import
if err = d.Set("organization_id", orgID); err != nil {
return err
}

return nil
}

Expand Down
6 changes: 5 additions & 1 deletion internal/sdkprovider/service/pg/pg_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ func ResourcePGUserRead(ctx context.Context, d schemautil.ResourceData, client a
return schemautil.ResourceReadHandleNotFound(err, d)
}

err = schemautil.ResourceDataSet(ResourcePGUserSchema, d, user)
err = schemautil.ResourceDataSet(
ResourcePGUserSchema, d, user,
schemautil.AddForceNew("project", projectName),
schemautil.AddForceNew("service_name", serviceName),
)
if err != nil {
return err
}
Expand Down

0 comments on commit 67b39b4

Please sign in to comment.