generated from hashicorp/terraform-provider-scaffolding-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Monolith sub manifest pkg info resource
- Loading branch information
Showing
7 changed files
with
536 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "zentral_monolith_sub_manifest_pkg_info Resource - terraform-provider-zentral" | ||
subcategory: "" | ||
description: |- | ||
The resource zentral_monolith_sub_manifest_pkg_info manages Monolith sub manifest pkg infos. | ||
--- | ||
|
||
# zentral_monolith_sub_manifest_pkg_info (Resource) | ||
|
||
The resource `zentral_monolith_sub_manifest_pkg_info` manages Monolith sub manifest pkg infos. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `key` (String) Sub manifest key under which this pkg info will be included. | ||
- `pkg_info_name` (String) The name of the pkg info to include. | ||
- `sub_manifest_id` (Number) The `ID` of the sub manifest this pkg info is attached to. | ||
|
||
### Optional | ||
|
||
- `condition_id` (Number) The `ID` of the condition that is evaluated to decide if this pkg info is included. | ||
- `default_shard` (Number) The default shard value. Defaults to `100`. | ||
- `excluded_tag_ids` (Set of Number) Machines tagged with one of these tags will not receive the pkg info. | ||
- `featured_item` (Boolean) If `true`, this pkg info will be displayed in the featured items section in Managed Software Center. Defaults to `false`. | ||
- `shard_modulo` (Number) The modulo used to calculate the shards. Defaults to `100`. | ||
- `tag_shards` (Attributes Set) A set of tag shard values different from the default shard, to determine if the tagged machines will receive the pkg info. (see [below for nested schema](#nestedatt--tag_shards)) | ||
|
||
### Read-Only | ||
|
||
- `id` (Number) `ID` of the sub manifest pkg info. | ||
|
||
<a id="nestedatt--tag_shards"></a> | ||
### Nested Schema for `tag_shards` | ||
|
||
Required: | ||
|
||
- `shard` (Number) The shard for the tag. | ||
- `tag_id` (Number) The `ID` of the tag. | ||
|
||
|
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,104 @@ | ||
package provider | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/zentralopensource/goztl" | ||
) | ||
|
||
type monolithSubManifestPkgInfo struct { | ||
ID types.Int64 `tfsdk:"id"` | ||
SubManifestID types.Int64 `tfsdk:"sub_manifest_id"` | ||
Key types.String `tfsdk:"key"` | ||
PkgInfoName types.String `tfsdk:"pkg_info_name"` | ||
FeaturedItem types.Bool `tfsdk:"featured_item"` | ||
ConditionID types.Int64 `tfsdk:"condition_id"` | ||
ShardModulo types.Int64 `tfsdk:"shard_modulo"` | ||
DefaultShard types.Int64 `tfsdk:"default_shard"` | ||
ExcludedTagIDs types.Set `tfsdk:"excluded_tag_ids"` | ||
TagShards types.Set `tfsdk:"tag_shards"` | ||
} | ||
|
||
var tagShardAttrTypes = map[string]attr.Type{ | ||
"tag_id": types.Int64Type, | ||
"shard": types.Int64Type, | ||
} | ||
|
||
func monolithSubManifestPkgInfoForState(msmpi *goztl.MonolithSubManifestPkgInfo) monolithSubManifestPkgInfo { | ||
var cID types.Int64 | ||
if msmpi.ConditionID != nil { | ||
cID = types.Int64Value(int64(*msmpi.ConditionID)) | ||
} else { | ||
cID = types.Int64Null() | ||
} | ||
|
||
exTagIDs := make([]attr.Value, 0) | ||
for _, exTagID := range msmpi.ExcludedTagIDs { | ||
exTagIDs = append(exTagIDs, types.Int64Value(int64(exTagID))) | ||
} | ||
|
||
tagShards := make([]attr.Value, 0) | ||
for _, tagShard := range msmpi.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 monolithSubManifestPkgInfo{ | ||
ID: types.Int64Value(int64(msmpi.ID)), | ||
SubManifestID: types.Int64Value(int64(msmpi.SubManifestID)), | ||
Key: types.StringValue(msmpi.Key), | ||
PkgInfoName: types.StringValue(msmpi.PkgInfoName), | ||
FeaturedItem: types.BoolValue(msmpi.FeaturedItem), | ||
ConditionID: cID, | ||
ShardModulo: types.Int64Value(int64(msmpi.ShardModulo)), | ||
DefaultShard: types.Int64Value(int64(msmpi.DefaultShard)), | ||
ExcludedTagIDs: types.SetValueMust(types.Int64Type, exTagIDs), | ||
TagShards: types.SetValueMust(types.ObjectType{AttrTypes: tagShardAttrTypes}, tagShards), | ||
} | ||
} | ||
|
||
func monolithSubManifestPkgInfoRequestWithState(data monolithSubManifestPkgInfo) *goztl.MonolithSubManifestPkgInfoRequest { | ||
var cID *int | ||
if !data.ConditionID.IsNull() { | ||
cID = goztl.Int(int(data.ConditionID.ValueInt64())) | ||
} | ||
|
||
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.MonolithSubManifestPkgInfoRequest{ | ||
SubManifestID: int(data.SubManifestID.ValueInt64()), | ||
Key: data.Key.ValueString(), | ||
PkgInfoName: data.PkgInfoName.ValueString(), | ||
FeaturedItem: data.FeaturedItem.ValueBool(), | ||
ConditionID: cID, | ||
ShardModulo: int(data.ShardModulo.ValueInt64()), | ||
DefaultShard: int(data.DefaultShard.ValueInt64()), | ||
ExcludedTagIDs: exTagIDs, | ||
TagShards: tagShards, | ||
} | ||
} |
Oops, something went wrong.