Skip to content

Commit

Permalink
Regenerate, update implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tobio committed Sep 1, 2024
1 parent d023e7b commit b794328
Show file tree
Hide file tree
Showing 5 changed files with 9,576 additions and 21 deletions.
90 changes: 82 additions & 8 deletions generated/fleet/fleet.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 30 additions & 10 deletions internal/fleet/agent_policy_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,27 @@ func resourceAgentPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta
return diag.FromErr(fmt.Errorf("'global_data_tags' is supported only for Elasticsearch v%s and above", minVersionGlobalDataTags.String()))
}

globalDataTags := make([]fleetapi.GlobalDataTag, 0, len(tagMap))
for key, value := range tagMap {
globalDataTags = append(globalDataTags, fleetapi.GlobalDataTag{
Name: key,
Value: value.(string),
globalDataTags := []map[string]fleetapi.AgentPolicyUpdateRequest_GlobalDataTags_AdditionalProperties{}
for key, val := range tagMap {
var name, value fleetapi.AgentPolicyUpdateRequest_GlobalDataTags_AdditionalProperties
err := name.FromAgentPolicyUpdateRequestGlobalDataTags0(key)
if err != nil {
return diag.FromErr(err)
}

err = value.FromAgentPolicyUpdateRequestGlobalDataTags0(val.(string))
if err != nil {
return diag.FromErr(err)
}

globalDataTags = append(globalDataTags, map[string]fleetapi.AgentPolicyUpdateRequest_GlobalDataTags_AdditionalProperties{
"name": name,
"value": value,
})
}
req.GlobalDataTags = globalDataTags
req.GlobalDataTags = &globalDataTags
} else {
req.GlobalDataTags = make([]fleetapi.GlobalDataTag, 0) // Ensure it's an empty array
req.GlobalDataTags = &[]map[string]fleetapi.AgentPolicyUpdateRequest_GlobalDataTags_AdditionalProperties{} // Ensure it's an empty array
}

_, diags = fleet.UpdateAgentPolicy(ctx, fleetClient, d.Id(), req)
Expand Down Expand Up @@ -351,9 +362,18 @@ func resourceAgentPolicyRead(ctx context.Context, d *schema.ResourceData, meta i

if agentPolicy.GlobalDataTags != nil {

globalDataTags := make(map[string]string, len(agentPolicy.GlobalDataTags))
for _, tag := range agentPolicy.GlobalDataTags {
globalDataTags[tag.Name] = tag.Value.(string)
globalDataTags := make(map[string]string, len(*agentPolicy.GlobalDataTags))
for _, tag := range *agentPolicy.GlobalDataTags {
name, err := tag["name"].AsAgentPolicyGlobalDataTags0()
if err != nil {
return diag.FromErr(err)
}

value, err := tag["value"].AsAgentPolicyGlobalDataTags0()
if err != nil {
return diag.FromErr(err)
}
globalDataTags[name] = value
}

if err := d.Set("global_data_tags", globalDataTags); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/fleet/integration_policy_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

fleetapi "github.com/elastic/terraform-provider-elasticstack/generated/fleet"
"github.com/elastic/terraform-provider-elasticstack/internal/clients/fleet"
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
)

func ResourceIntegrationPolicy() *schema.Resource {
Expand Down Expand Up @@ -135,7 +136,7 @@ func resourceIntegrationPolicyCreate(ctx context.Context, d *schema.ResourceData
}

req := fleetapi.CreatePackagePolicyJSONRequestBody{
PolicyId: d.Get("agent_policy_id").(string),
PolicyId: utils.Pointer(d.Get("agent_policy_id").(string)),
Name: d.Get("name").(string),
}
req.Package.Name = d.Get("integration_name").(string)
Expand Down Expand Up @@ -215,7 +216,7 @@ func resourceIntegrationPolicyUpdate(ctx context.Context, d *schema.ResourceData
}

req := fleetapi.UpdatePackagePolicyJSONRequestBody{
PolicyId: d.Get("agent_policy_id").(string),
PolicyId: utils.Pointer(d.Get("agent_policy_id").(string)),
Name: d.Get("name").(string),
}
req.Package.Name = d.Get("integration_name").(string)
Expand Down
Loading

0 comments on commit b794328

Please sign in to comment.