generated from hashicorp/terraform-provider-scaffolding-framework
/
mdm_blueprint_artifact.go
114 lines (106 loc) · 4.55 KB
/
mdm_blueprint_artifact.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package provider
import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/zentralopensource/goztl"
)
type mdmBlueprintArtifact struct {
ID types.Int64 `tfsdk:"id"`
BlueprintID types.Int64 `tfsdk:"blueprint_id"`
ArtifactID types.String `tfsdk:"artifact_id"`
IOS types.Bool `tfsdk:"ios"`
IOSMaxVersion types.String `tfsdk:"ios_max_version"`
IOSMinVersion types.String `tfsdk:"ios_min_version"`
IPadOS types.Bool `tfsdk:"ipados"`
IPadOSMaxVersion types.String `tfsdk:"ipados_max_version"`
IPadOSMinVersion types.String `tfsdk:"ipados_min_version"`
MacOS types.Bool `tfsdk:"macos"`
MacOSMaxVersion types.String `tfsdk:"macos_max_version"`
MacOSMinVersion types.String `tfsdk:"macos_min_version"`
TVOS types.Bool `tfsdk:"tvos"`
TVOSMaxVersion types.String `tfsdk:"tvos_max_version"`
TVOSMinVersion types.String `tfsdk:"tvos_min_version"`
DefaultShard types.Int64 `tfsdk:"default_shard"`
ShardModulo types.Int64 `tfsdk:"shard_modulo"`
ExcludedTagIDs types.Set `tfsdk:"excluded_tag_ids"`
TagShards types.Set `tfsdk:"tag_shards"`
}
func mdmBlueprintArtifactForState(mba *goztl.MDMBlueprintArtifact) mdmBlueprintArtifact {
exTagIDs := make([]attr.Value, 0)
for _, exTagID := range mba.ExcludedTagIDs {
exTagIDs = append(exTagIDs, types.Int64Value(int64(exTagID)))
}
tagShards := make([]attr.Value, 0)
for _, tagShard := range mba.TagShards {
tagShards = append(
tagShards,
types.ObjectValueMust(
tagShardAttrTypes,
map[string]attr.Value{
"tag_id": types.Int64Value(int64(tagShard.TagID)),
"shard": types.Int64Value(int64(tagShard.Shard)),
},
),
)
}
return mdmBlueprintArtifact{
ID: types.Int64Value(int64(mba.ID)),
BlueprintID: types.Int64Value(int64(mba.BlueprintID)),
ArtifactID: types.StringValue(mba.ArtifactID),
IOS: types.BoolValue(mba.IOS),
IOSMaxVersion: types.StringValue(mba.IOSMaxVersion),
IOSMinVersion: types.StringValue(mba.IOSMinVersion),
IPadOS: types.BoolValue(mba.IPadOS),
IPadOSMaxVersion: types.StringValue(mba.IPadOSMaxVersion),
IPadOSMinVersion: types.StringValue(mba.IPadOSMinVersion),
MacOS: types.BoolValue(mba.MacOS),
MacOSMaxVersion: types.StringValue(mba.MacOSMaxVersion),
MacOSMinVersion: types.StringValue(mba.MacOSMinVersion),
TVOS: types.BoolValue(mba.TVOS),
TVOSMaxVersion: types.StringValue(mba.TVOSMaxVersion),
TVOSMinVersion: types.StringValue(mba.TVOSMinVersion),
DefaultShard: types.Int64Value(int64(mba.DefaultShard)),
ShardModulo: types.Int64Value(int64(mba.ShardModulo)),
ExcludedTagIDs: types.SetValueMust(types.Int64Type, exTagIDs),
TagShards: types.SetValueMust(types.ObjectType{AttrTypes: tagShardAttrTypes}, tagShards),
}
}
func mdmBlueprintArtifactRequestWithState(data mdmBlueprintArtifact) *goztl.MDMBlueprintArtifactRequest {
exTagIDs := make([]int, 0)
for _, exTagID := range data.ExcludedTagIDs.Elements() { // nil if null or unknown → no iterations
exTagIDs = append(exTagIDs, int(exTagID.(types.Int64).ValueInt64()))
}
tagShards := make([]goztl.TagShard, 0)
for _, tagShard := range data.TagShards.Elements() { // nil if null or unknown → no iterations
tagShardMap := tagShard.(types.Object).Attributes()
if tagShardMap != nil {
tagShards = append(
tagShards,
goztl.TagShard{
TagID: int(tagShardMap["tag_id"].(types.Int64).ValueInt64()),
Shard: int(tagShardMap["shard"].(types.Int64).ValueInt64()),
},
)
}
}
return &goztl.MDMBlueprintArtifactRequest{
BlueprintID: int(data.BlueprintID.ValueInt64()),
ArtifactID: data.ArtifactID.ValueString(),
IOS: data.IOS.ValueBool(),
IOSMaxVersion: data.IOSMaxVersion.ValueString(),
IOSMinVersion: data.IOSMinVersion.ValueString(),
IPadOS: data.IPadOS.ValueBool(),
IPadOSMaxVersion: data.IPadOSMaxVersion.ValueString(),
IPadOSMinVersion: data.IPadOSMinVersion.ValueString(),
MacOS: data.MacOS.ValueBool(),
MacOSMaxVersion: data.MacOSMaxVersion.ValueString(),
MacOSMinVersion: data.MacOSMinVersion.ValueString(),
TVOS: data.TVOS.ValueBool(),
TVOSMaxVersion: data.TVOSMaxVersion.ValueString(),
TVOSMinVersion: data.TVOSMinVersion.ValueString(),
DefaultShard: int(data.DefaultShard.ValueInt64()),
ShardModulo: int(data.ShardModulo.ValueInt64()),
ExcludedTagIDs: exTagIDs,
TagShards: tagShards,
}
}