-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instance config file checksum handled properly
- Loading branch information
1 parent
8050e53
commit 5fde82f
Showing
5 changed files
with
56 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package instance | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/wttech/terraform-provider-aem/internal/utils" | ||
) | ||
|
||
func ConfigFileChecksumPlanModifier() planmodifier.String { | ||
return &configFileChecksumPlanModifier{} | ||
} | ||
|
||
type configFileChecksumPlanModifier struct{} | ||
|
||
func (m *configFileChecksumPlanModifier) Description(ctx context.Context) string { | ||
return "Updates AEM configuration file checksum when contents change." | ||
} | ||
|
||
func (m *configFileChecksumPlanModifier) MarkdownDescription(ctx context.Context) string { | ||
return m.Description(ctx) | ||
} | ||
|
||
func (m *configFileChecksumPlanModifier) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) { | ||
var configFile types.String | ||
diags := req.Plan.GetAttribute(ctx, path.Root("compose").AtName("config_file"), &configFile) | ||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
if !configFile.IsNull() { | ||
configFilePath := configFile.ValueString() | ||
checksum, err := utils.HashFileMD5(configFilePath) | ||
if err != nil { | ||
resp.Diagnostics.AddError("Unable to calculate checksum of AEM configuration file", fmt.Sprintf("path '%s', error: %s", configFilePath, err)) | ||
return | ||
} | ||
resp.PlanValue = types.StringValue(checksum) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters