Skip to content

Commit 090069f

Browse files
Terraform Team Automationsagarp337
authored andcommitted
Bug Fix - tagging in management_agent
1 parent 11c806f commit 090069f

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

examples/management_agent/management_agent.tf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// Licensed under the Mozilla Public License v2.0
33

44
variable "tenancy_ocid" {}
5-
variable "user_ocid" {}
6-
variable "fingerprint" {}
7-
variable "private_key_path" {}
85
variable "region" {}
96
variable "compartment_ocid" {}
107
variable "root_compartment_ocid" {}
@@ -17,9 +14,8 @@ variable "subnet" {
1714
}
1815
provider "oci" {
1916
tenancy_ocid = var.tenancy_ocid
20-
user_ocid = var.user_ocid
21-
fingerprint = var.fingerprint
22-
private_key_path = var.private_key_path
17+
auth = "SecurityToken"
18+
config_file_profile = "terraform-federation-test"
2319
region = var.region
2420
}
2521

@@ -40,6 +36,8 @@ resource "oci_management_agent_management_agent" "test_management_agent" {
4036

4137
#Optional
4238
deploy_plugins_id = [data.oci_management_agent_management_agent_plugins.test_management_agent_plugins.management_agent_plugins.1.id]
39+
freeform_tags = {"tagKey":"tagValue"}
40+
4341
}
4442

4543

@@ -188,4 +186,8 @@ resource "oci_management_agent_management_agent" "test_compute_management_agent"
188186
freeform_tags = { "TestingTag" : "TestingValue" }
189187
managed_agent_id = data.oci_management_agent_management_agents.find_compute_agent.management_agents[0].id
190188
deploy_plugins_id = [data.oci_management_agent_management_agent_plugins.test_management_agent_plugins.management_agent_plugins.0.id]
189+
}
190+
191+
output "updated_agent" {
192+
value = data.oci_management_agent_management_agents.find_agent.management_agents[0].id
191193
}

internal/integrationtest/management_agent_management_agent_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func TestManagementAgentManagementAgentResource_basic(t *testing.T) {
185185
"managed_agent_id": acctest.Representation{RepType: acctest.Required, Create: managementAgentId},
186186
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `terraformTest`, Update: `terraformTest2`},
187187
"deploy_plugins_id": acctest.Representation{RepType: acctest.Optional, Create: []string{`${data.oci_management_agent_management_agent_plugins.test_management_agent_plugins.management_agent_plugins.0.id}`}},
188+
"freeform_tags": acctest.Representation{RepType: acctest.Required, Create: map[string]string{"TestingTag": "TestingValue"}, Update: map[string]string{"TestingTag2": "TestingValue2"}},
188189
}
189190
ManagementAgentRequiredOnlyResource := acctest.GenerateResourceFromRepresentationMap("oci_management_agent_management_agent", "test_management_agent", acctest.Required, acctest.Create, managementAgentRepresentation)
190191

@@ -205,6 +206,7 @@ func TestManagementAgentManagementAgentResource_basic(t *testing.T) {
205206
acctest.GenerateResourceFromRepresentationMap("oci_management_agent_management_agent",
206207
"test_management_agent", acctest.Required, acctest.Create, managementAgentRepresentation),
207208
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
209+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
208210

209211
func(s *terraform.State) (err error) {
210212
resId, err = acctest.FromInstanceState(s, resourceName, "id")
@@ -228,6 +230,7 @@ func TestManagementAgentManagementAgentResource_basic(t *testing.T) {
228230
resource.TestCheckResourceAttrSet(resourceName, "id"),
229231
resource.TestCheckResourceAttrSet(resourceName, "version"),
230232
resource.TestCheckResourceAttr(resourceName, "display_name", "terraformTest2"),
233+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
231234

232235
func(s *terraform.State) (err error) {
233236
resId2, err = acctest.FromInstanceState(s, resourceName, "id")
@@ -291,7 +294,7 @@ func TestManagementAgentManagementAgentResource_basic(t *testing.T) {
291294
resource.TestCheckResourceAttrSet(singularDatasourceName, "availability_status"),
292295
resource.TestCheckResourceAttrSet(singularDatasourceName, "compartment_id"),
293296
resource.TestCheckResourceAttr(singularDatasourceName, "data_source_list.#", "0"),
294-
resource.TestCheckResourceAttr(singularDatasourceName, "freeform_tags.%", "0"),
297+
resource.TestCheckResourceAttr(singularDatasourceName, "freeform_tags.%", "1"),
295298
resource.TestCheckResourceAttrSet(singularDatasourceName, "display_name"),
296299
resource.TestCheckResourceAttrSet(singularDatasourceName, "host"),
297300
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),

internal/service/management_agent/management_agent_management_agent_resource.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,14 @@ func (s *ManagementAgentManagementAgentResourceCrud) mapToMetricDimension(fieldK
993993
}
994994

995995
func (s *ManagementAgentManagementAgentResourceCrud) Create() error {
996+
997+
// During create, the user can set new value for tags and or display_name
998+
// During create, the s.D is updated with s.Get to the current values in MACS
999+
// so we keep a copy of the required values locally, and then set them during the update if necessary
1000+
freeformtags, freeformtagsok := s.D.GetOkExists("freeform_tags")
1001+
definedtags, definedtagsok := s.D.GetOkExists("defined_tags")
1002+
displayname, displaynameok := s.D.GetOkExists("display_name")
1003+
9961004
e := s.Get()
9971005
if e != nil {
9981006
return e
@@ -1002,6 +1010,18 @@ func (s *ManagementAgentManagementAgentResourceCrud) Create() error {
10021010
return e
10031011
}
10041012

1013+
if freeformtagsok {
1014+
log.Printf("[DEBUG] Updating agent freeformtags to %v", freeformtags)
1015+
s.D.Set("freeform_tags", freeformtags)
1016+
}
1017+
if definedtagsok {
1018+
log.Printf("[DEBUG] Updating agent definedtags to %v", definedtags)
1019+
s.D.Set("defined_tags", definedtags)
1020+
}
1021+
if displaynameok {
1022+
log.Printf("[DEBUG] Updating agent displayname to %v", displayname)
1023+
s.D.Set("display_name", displayname)
1024+
}
10051025
return s.Update()
10061026
}
10071027

0 commit comments

Comments
 (0)