Skip to content

Commit 77e692e

Browse files
committed
Add MDM data assets & declarations
1 parent 1fc3e08 commit 77e692e

12 files changed

+1517
-7
lines changed

docs/resources/mdm_data_asset.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "zentral_mdm_data_asset Resource - terraform-provider-zentral"
4+
subcategory: ""
5+
description: |-
6+
The resource zentral_mdm_data_asset manages MDM data assets.
7+
---
8+
9+
# zentral_mdm_data_asset (Resource)
10+
11+
The resource `zentral_mdm_data_asset` manages MDM data assets.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `artifact_id` (String) `ID` of the data asset artifact.
21+
- `file_sha256` (String) The hexadecimal digest of the sha256 hash of the file.
22+
- `file_uri` (String) The URI of the data asset file.
23+
- `type` (String) The type of the data asset file.
24+
- `version` (Number) Version of the data asset.
25+
26+
### Optional
27+
28+
- `default_shard` (Number) The default shard value. Defaults to `100`.
29+
- `excluded_tag_ids` (Set of Number) Machines tagged with one of these tags will not receive the data asset.
30+
- `ios` (Boolean) Toggles the installation of the data asset on iOS devices.
31+
- `ios_max_version` (String) Devices with this iOS version or higher will **not** receive this data asset.
32+
- `ios_min_version` (String) Devices with this iOS version or higher will receive this data asset.
33+
- `ipados` (Boolean) Toggles the installation of the data asset on iPadOS devices.
34+
- `ipados_max_version` (String) Devices with this iPadOS version or higher will **not** receive this data asset.
35+
- `ipados_min_version` (String) Devices with this iPadOS version or higher will receive this data asset.
36+
- `macos` (Boolean) Toggles the installation of the data asset on macOS devices.
37+
- `macos_max_version` (String) Devices with this macOS version or higher will **not** receive this data asset.
38+
- `macos_min_version` (String) Devices with this macOS version or higher will receive this data asset.
39+
- `shard_modulo` (Number) The modulo used to calculate the shards. Defaults to `100`.
40+
- `tag_shards` (Attributes Set) A set of tag shard values different from the default shard, to determine if the tagged machines will receive the data asset. (see [below for nested schema](#nestedatt--tag_shards))
41+
- `tvos` (Boolean) Toggles the installation of the data asset on tvOS devices.
42+
- `tvos_max_version` (String) Devices with this tvOS version or higher will **not** receive this data asset.
43+
- `tvos_min_version` (String) Devices with this tvOS version or higher will receive this data asset.
44+
45+
### Read-Only
46+
47+
- `file_size` (Number) The size of the data asset file.
48+
- `filename` (String) The name of the data asset file.
49+
- `id` (String) `ID` of the data asset.
50+
51+
<a id="nestedatt--tag_shards"></a>
52+
### Nested Schema for `tag_shards`
53+
54+
Required:
55+
56+
- `shard` (Number) The shard for the tag.
57+
- `tag_id` (Number) The `ID` of the tag.

docs/resources/mdm_declaration.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "zentral_mdm_declaration Resource - terraform-provider-zentral"
4+
subcategory: ""
5+
description: |-
6+
The resource zentral_mdm_declaration manages MDM declarations.
7+
---
8+
9+
# zentral_mdm_declaration (Resource)
10+
11+
The resource `zentral_mdm_declaration` manages MDM declarations.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `artifact_id` (String) `ID` of the declaration artifact.
21+
- `source` (String) The actual DDM declaration (JSON).
22+
- `version` (Number) Version of the declaration.
23+
24+
### Optional
25+
26+
- `default_shard` (Number) The default shard value. Defaults to `100`.
27+
- `excluded_tag_ids` (Set of Number) Machines tagged with one of these tags will not receive the declaration.
28+
- `ios` (Boolean) Toggles the installation of the declaration on iOS devices.
29+
- `ios_max_version` (String) Devices with this iOS version or higher will **not** receive this declaration.
30+
- `ios_min_version` (String) Devices with this iOS version or higher will receive this declaration.
31+
- `ipados` (Boolean) Toggles the installation of the declaration on iPadOS devices.
32+
- `ipados_max_version` (String) Devices with this iPadOS version or higher will **not** receive this declaration.
33+
- `ipados_min_version` (String) Devices with this iPadOS version or higher will receive this declaration.
34+
- `macos` (Boolean) Toggles the installation of the declaration on macOS devices.
35+
- `macos_max_version` (String) Devices with this macOS version or higher will **not** receive this declaration.
36+
- `macos_min_version` (String) Devices with this macOS version or higher will receive this declaration.
37+
- `shard_modulo` (Number) The modulo used to calculate the shards. Defaults to `100`.
38+
- `tag_shards` (Attributes Set) A set of tag shard values different from the default shard, to determine if the tagged machines will receive the declaration. (see [below for nested schema](#nestedatt--tag_shards))
39+
- `tvos` (Boolean) Toggles the installation of the declaration on tvOS devices.
40+
- `tvos_max_version` (String) Devices with this tvOS version or higher will **not** receive this declaration.
41+
- `tvos_min_version` (String) Devices with this tvOS version or higher will receive this declaration.
42+
43+
### Read-Only
44+
45+
- `id` (String) `ID` of the declaration.
46+
47+
<a id="nestedatt--tag_shards"></a>
48+
### Nested Schema for `tag_shards`
49+
50+
Required:
51+
52+
- `shard` (Number) The shard for the tag.
53+
- `tag_id` (Number) The `ID` of the tag.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ require (
66
github.com/hashicorp/terraform-plugin-docs v0.21.0
77
github.com/hashicorp/terraform-plugin-framework v1.15.0
88
github.com/hashicorp/terraform-plugin-framework-validators v0.18.0
9-
github.com/hashicorp/terraform-plugin-go v0.27.0
9+
github.com/hashicorp/terraform-plugin-go v0.28.0
1010
github.com/hashicorp/terraform-plugin-log v0.9.0
1111
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0
12-
github.com/zentralopensource/goztl v0.1.52
12+
github.com/zentralopensource/goztl v0.1.53
1313
)
1414

1515
require (

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ github.com/hashicorp/terraform-plugin-framework v1.15.0 h1:LQ2rsOfmDLxcn5EeIwdXF
112112
github.com/hashicorp/terraform-plugin-framework v1.15.0/go.mod h1:hxrNI/GY32KPISpWqlCoTLM9JZsGH3CyYlir09bD/fI=
113113
github.com/hashicorp/terraform-plugin-framework-validators v0.18.0 h1:OQnlOt98ua//rCw+QhBbSqfW3QbwtVrcdWeQN5gI3Hw=
114114
github.com/hashicorp/terraform-plugin-framework-validators v0.18.0/go.mod h1:lZvZvagw5hsJwuY7mAY6KUz45/U6fiDR0CzQAwWD0CA=
115-
github.com/hashicorp/terraform-plugin-go v0.27.0 h1:ujykws/fWIdsi6oTUT5Or4ukvEan4aN9lY+LOxVP8EE=
116-
github.com/hashicorp/terraform-plugin-go v0.27.0/go.mod h1:FDa2Bb3uumkTGSkTFpWSOwWJDwA7bf3vdP3ltLDTH6o=
115+
github.com/hashicorp/terraform-plugin-go v0.28.0 h1:zJmu2UDwhVN0J+J20RE5huiF3XXlTYVIleaevHZgKPA=
116+
github.com/hashicorp/terraform-plugin-go v0.28.0/go.mod h1:FDa2Bb3uumkTGSkTFpWSOwWJDwA7bf3vdP3ltLDTH6o=
117117
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
118118
github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
119119
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0 h1:NFPMacTrY/IdcIcnUB+7hsore1ZaRWU9cnB6jFoBnIM=
@@ -209,8 +209,8 @@ github.com/zclconf/go-cty v1.16.2 h1:LAJSwc3v81IRBZyUVQDUdZ7hs3SYs9jv0eZJDWHD/70
209209
github.com/zclconf/go-cty v1.16.2/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
210210
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
211211
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
212-
github.com/zentralopensource/goztl v0.1.52 h1:pV3rGAWpYuwm6YBdqAEBqM55l8lHvX+tsVan5hqlTWM=
213-
github.com/zentralopensource/goztl v0.1.52/go.mod h1:gFCBKNeI1hyOCAMX3fQe0CfivknryalcEjWnVNOttGU=
212+
github.com/zentralopensource/goztl v0.1.53 h1:D//VJXzKWnpmeAJJSBe6qFXykQV23dXwAfXFTFMTL7o=
213+
github.com/zentralopensource/goztl v0.1.53/go.mod h1:W1XQpz/QKelUJsJ7pkXQvb0c/FfsXNMqdRiiVrGSIRs=
214214
go.abhg.dev/goldmark/frontmatter v0.2.0 h1:P8kPG0YkL12+aYk2yU3xHv4tcXzeVnN+gU0tJ5JnxRw=
215215
go.abhg.dev/goldmark/frontmatter v0.2.0/go.mod h1:XqrEkZuM57djk7zrlRUB02x8I5J0px76YjkOzhB4YlU=
216216
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=

internal/provider/mdm_artifact_resource.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ func (r *MDMArtifactResource) Schema(ctx context.Context, req resource.SchemaReq
6161
MarkdownDescription: "Type of the artifact.",
6262
Required: true,
6363
Validators: []validator.String{
64-
stringvalidator.OneOf([]string{"Enterprise App", "Profile", "Store App"}...),
64+
stringvalidator.OneOf([]string{
65+
"Activation",
66+
"Asset",
67+
"Configuration",
68+
"Data Asset",
69+
"Enterprise App",
70+
"Configuration (manual)",
71+
"Profile",
72+
"Store App",
73+
}...),
6574
},
6675
},
6776
"channel": schema.StringAttribute{
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package provider
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-framework/types"
5+
"github.com/zentralopensource/goztl"
6+
)
7+
8+
type mdmDataAsset struct {
9+
ID types.String `tfsdk:"id"`
10+
Type types.String `tfsdk:"type"`
11+
FileURI types.String `tfsdk:"file_uri"`
12+
FileSHA256 types.String `tfsdk:"file_sha256"`
13+
FileSize types.Int64 `tfsdk:"file_size"`
14+
Filename types.String `tfsdk:"filename"`
15+
ArtifactID types.String `tfsdk:"artifact_id"`
16+
IOS types.Bool `tfsdk:"ios"`
17+
IOSMaxVersion types.String `tfsdk:"ios_max_version"`
18+
IOSMinVersion types.String `tfsdk:"ios_min_version"`
19+
IPadOS types.Bool `tfsdk:"ipados"`
20+
IPadOSMaxVersion types.String `tfsdk:"ipados_max_version"`
21+
IPadOSMinVersion types.String `tfsdk:"ipados_min_version"`
22+
MacOS types.Bool `tfsdk:"macos"`
23+
MacOSMaxVersion types.String `tfsdk:"macos_max_version"`
24+
MacOSMinVersion types.String `tfsdk:"macos_min_version"`
25+
TVOS types.Bool `tfsdk:"tvos"`
26+
TVOSMaxVersion types.String `tfsdk:"tvos_max_version"`
27+
TVOSMinVersion types.String `tfsdk:"tvos_min_version"`
28+
DefaultShard types.Int64 `tfsdk:"default_shard"`
29+
ShardModulo types.Int64 `tfsdk:"shard_modulo"`
30+
ExcludedTagIDs types.Set `tfsdk:"excluded_tag_ids"`
31+
TagShards types.Set `tfsdk:"tag_shards"`
32+
Version types.Int64 `tfsdk:"version"`
33+
}
34+
35+
func mdmDataAssetForState(mda *goztl.MDMDataAsset, fileURI types.String) mdmDataAsset {
36+
exTagIDs := exTagIDsForState(mda.MDMArtifactVersion)
37+
tagShards := tagShardsForState(mda.MDMArtifactVersion)
38+
39+
return mdmDataAsset{
40+
ID: types.StringValue(mda.ID),
41+
Type: types.StringValue(mda.Type),
42+
FileURI: fileURI,
43+
FileSHA256: types.StringValue(mda.FileSHA256),
44+
FileSize: types.Int64Value(mda.FileSize),
45+
Filename: types.StringValue(mda.Filename),
46+
ArtifactID: types.StringValue(mda.ArtifactID),
47+
IOS: types.BoolValue(mda.IOS),
48+
IOSMaxVersion: types.StringValue(mda.IOSMaxVersion),
49+
IOSMinVersion: types.StringValue(mda.IOSMinVersion),
50+
IPadOS: types.BoolValue(mda.IPadOS),
51+
IPadOSMaxVersion: types.StringValue(mda.IPadOSMaxVersion),
52+
IPadOSMinVersion: types.StringValue(mda.IPadOSMinVersion),
53+
MacOS: types.BoolValue(mda.MacOS),
54+
MacOSMaxVersion: types.StringValue(mda.MacOSMaxVersion),
55+
MacOSMinVersion: types.StringValue(mda.MacOSMinVersion),
56+
TVOS: types.BoolValue(mda.TVOS),
57+
TVOSMaxVersion: types.StringValue(mda.TVOSMaxVersion),
58+
TVOSMinVersion: types.StringValue(mda.TVOSMinVersion),
59+
DefaultShard: types.Int64Value(int64(mda.DefaultShard)),
60+
ShardModulo: types.Int64Value(int64(mda.ShardModulo)),
61+
ExcludedTagIDs: types.SetValueMust(types.Int64Type, exTagIDs),
62+
TagShards: types.SetValueMust(types.ObjectType{AttrTypes: tagShardAttrTypes}, tagShards),
63+
Version: types.Int64Value(int64(mda.Version)),
64+
}
65+
}
66+
67+
func mdmDataAssetRequestWithState(data mdmDataAsset) *goztl.MDMDataAssetRequest {
68+
exTagIDs := make([]int, 0)
69+
for _, exTagID := range data.ExcludedTagIDs.Elements() { // nil if null or unknown → no iterations
70+
exTagIDs = append(exTagIDs, int(exTagID.(types.Int64).ValueInt64()))
71+
}
72+
73+
tagShards := make([]goztl.TagShard, 0)
74+
for _, tagShard := range data.TagShards.Elements() { // nil if null or unknown → no iterations
75+
tagShardMap := tagShard.(types.Object).Attributes()
76+
if tagShardMap != nil {
77+
tagShards = append(
78+
tagShards,
79+
goztl.TagShard{
80+
TagID: int(tagShardMap["tag_id"].(types.Int64).ValueInt64()),
81+
Shard: int(tagShardMap["shard"].(types.Int64).ValueInt64()),
82+
},
83+
)
84+
}
85+
}
86+
87+
return &goztl.MDMDataAssetRequest{
88+
Type: data.Type.ValueString(),
89+
FileURI: data.FileURI.ValueString(),
90+
FileSHA256: data.FileSHA256.ValueString(),
91+
MDMArtifactVersionRequest: goztl.MDMArtifactVersionRequest{
92+
ArtifactID: data.ArtifactID.ValueString(),
93+
IOS: data.IOS.ValueBool(),
94+
IOSMaxVersion: data.IOSMaxVersion.ValueString(),
95+
IOSMinVersion: data.IOSMinVersion.ValueString(),
96+
IPadOS: data.IPadOS.ValueBool(),
97+
IPadOSMaxVersion: data.IPadOSMaxVersion.ValueString(),
98+
IPadOSMinVersion: data.IPadOSMinVersion.ValueString(),
99+
MacOS: data.MacOS.ValueBool(),
100+
MacOSMaxVersion: data.MacOSMaxVersion.ValueString(),
101+
MacOSMinVersion: data.MacOSMinVersion.ValueString(),
102+
TVOS: data.TVOS.ValueBool(),
103+
TVOSMaxVersion: data.TVOSMaxVersion.ValueString(),
104+
TVOSMinVersion: data.TVOSMinVersion.ValueString(),
105+
DefaultShard: int(data.DefaultShard.ValueInt64()),
106+
ShardModulo: int(data.ShardModulo.ValueInt64()),
107+
ExcludedTagIDs: exTagIDs,
108+
TagShards: tagShards,
109+
Version: int(data.Version.ValueInt64()),
110+
},
111+
}
112+
}

0 commit comments

Comments
 (0)