Skip to content

Commit 4876b3d

Browse files
authored
feat: add version rule as parameter for mta resource (#130)
1 parent 707052a commit 4876b3d

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

docs/resources/mta.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ EOT
8787
- `mtar_url` (String) The remote URL where the MTA archive is present
8888
- `namespace` (String) The namespace of the MTA. Should be of valid host format
8989
- `source_code_hash` (String) SHA256 hash of the file specified. Terraform relies on this to detect the file changes.
90+
- `version_rule` (String) The rule to apply to determine how the application version number is used to trigger an application-update deployment operation.
9091

9192
### Read-Only
9293

internal/provider/datasource_mtas_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type MtaResourceModelPtr struct {
3333
Id *string
3434
SourceCodeHash *string
3535
DeployStrategy *string
36+
VersionRule *string
3637
}
3738

3839
func hclDataSourceMtas(mdsmp *MtasDataSourceModelPtr) string {
@@ -103,6 +104,9 @@ func hclResourceMta(mrmp *MtaResourceModelPtr) string {
103104
{{if .DeployStrategy}}
104105
deploy_strategy = "{{.DeployStrategy}}"
105106
{{- end -}}
107+
{{if .VersionRule}}
108+
version_rule = "{{.VersionRule}}"
109+
{{- end -}}
106110
{{if .DeployUrl}}
107111
deploy_url = "{{.DeployUrl}}"
108112
{{- end }}

internal/provider/resource_mta.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ __Note:__
123123
stringvalidator.OneOf("deploy", "blue-green-deploy"),
124124
},
125125
},
126+
"version_rule": schema.StringAttribute{
127+
MarkdownDescription: "The rule to apply to determine how the application version number is used to trigger an application-update deployment operation.",
128+
Optional: true,
129+
Validators: []validator.String{
130+
stringvalidator.OneOf("HIGHER", "SAME_HIGHER", "ALL"),
131+
},
132+
},
126133
"mta": schema.SingleNestedAttribute{
127134
MarkdownDescription: "contains the details of the MTA object",
128135
Computed: true,
@@ -380,6 +387,10 @@ func (r *mtaResource) upsert(ctx context.Context, reqPlan *tfsdk.Plan, reqState
380387
operationParams.ProcessType = "DEPLOY"
381388
}
382389

390+
if !mtarType.VersionRule.IsNull() {
391+
operationParams.Parameters["versionRule"] = mtarType.VersionRule.ValueString()
392+
}
393+
383394
if extensionDescriptors != "" {
384395
operationParams.Parameters["mtaExtDescriptorId"] = extensionDescriptors
385396
}

internal/provider/resource_mta_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func TestMtaResource_Configure(t *testing.T) {
1919
sourceCodeHash = "fca8f8d1c499a1d0561c274ab974faf09355d513bb36475fe67577d850562801"
2020
normalDeploy = "deploy"
2121
bgDeploy = "blue-green-deploy"
22+
versionRuleAll = "ALL"
2223
extensionDescriptorsString = `[
2324
<<EOT
2425
_schema-version: 3.3.0
@@ -69,6 +70,7 @@ EOT
6970
Space: strtostrptr(spaceGuid),
7071
Namespace: strtostrptr(namespace),
7172
DeployStrategy: strtostrptr(normalDeploy),
73+
VersionRule: strtostrptr(versionRuleAll),
7274
}),
7375
Check: resource.ComposeAggregateTestCheckFunc(
7476
resource.TestCheckResourceAttr(resourceName, "mtar_path", mtarPath),
@@ -126,6 +128,7 @@ EOT
126128
Namespace: strtostrptr(namespace),
127129
ExtensionDescriptors: strtostrptr(extensionDescriptors),
128130
DeployStrategy: strtostrptr(normalDeploy),
131+
VersionRule: strtostrptr(versionRuleAll),
129132
}),
130133
Check: resource.ComposeAggregateTestCheckFunc(
131134
resource.TestCheckResourceAttr(resourceName, "mtar_path", mtarPath2),
@@ -143,6 +146,7 @@ EOT
143146
ExtensionDescriptors: strtostrptr(extensionDescriptors),
144147
SourceCodeHash: strtostrptr(sourceCodeHash),
145148
DeployStrategy: strtostrptr(bgDeploy),
149+
VersionRule: strtostrptr(versionRuleAll),
146150
}),
147151
Check: resource.ComposeAggregateTestCheckFunc(
148152
resource.TestCheckResourceAttr(resourceName, "mtar_path", mtarPath2),
@@ -161,6 +165,7 @@ EOT
161165
ExtensionDescriptorsString: strtostrptr(extensionDescriptorsString),
162166
SourceCodeHash: strtostrptr(sourceCodeHash),
163167
DeployStrategy: strtostrptr(bgDeploy),
168+
VersionRule: strtostrptr(versionRuleAll),
164169
}),
165170
Check: resource.ComposeAggregateTestCheckFunc(
166171
resource.TestCheckResourceAttr(resourceName, "mtar_path", mtarPath2),

internal/provider/types_mta.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type MtarType struct {
2121
Id types.String `tfsdk:"id"`
2222
SourceCodeHash types.String `tfsdk:"source_code_hash"`
2323
DeployStrategy types.String `tfsdk:"deploy_strategy"`
24+
VersionRule types.String `tfsdk:"version_rule"`
2425
}
2526

2627
type MtasDataSourceType struct {

0 commit comments

Comments
 (0)