@@ -57,38 +57,6 @@ func (rt ResourceType) IsPotentialCircularDependencyTo(referringResourceID strin
5757 return rt == ResourceTypes .JSONDashboard && referredToResourceType == ResourceTypes .JSONDashboardBase && referringResourceID != referredToResourceID
5858}
5959
60- func (rt ResourceType ) VoidResource (resource * Resource , contents []byte ) ([]byte , bool ) {
61- if ! rt .CanGetVoidedIfNotReferenced () {
62- return contents , false
63- }
64- dashboardBaseReference := fmt .Sprintf (`${dynatrace_json_dashboard_base.%s.id}` , resource .UniqueName )
65- dashboardReference := fmt .Sprintf (`${dynatrace_json_dashboard.%s.id}` , resource .UniqueName )
66- var results string
67- lastLineWasSpace := false
68- for _ , line := range strings .Split (string (contents ), "\n " ) {
69- if strings .Contains (line , "link_id" ) && strings .Contains (line , dashboardBaseReference ) {
70- continue
71- } else if strings .Contains (line , "dashboard_id" ) && strings .Contains (line , dashboardBaseReference ) {
72- line = strings .Replace (line , dashboardBaseReference , dashboardReference , 1 )
73- }
74- curLineIsSpace := len (strings .TrimSpace (line )) == 0
75- if curLineIsSpace {
76- if lastLineWasSpace {
77- continue
78- }
79- }
80- lastLineWasSpace = curLineIsSpace
81- results = results + "\n " + line
82- }
83- // Here we assume (see ResourceType.Less) that the resource block `dynatrace_json_dashboard_base`
84- // is located at the very end of the file. The resource block is expected to be empty.
85- // Therefore we can expect that the } before the last one signals the end of the
86- // resource blocks that are allowed to remain. Everything past that will get cut off
87- results = results [:strings .LastIndex (results , "}" )]
88- results = results [:strings .LastIndex (results , "}" )+ 1 ]
89- return []byte (results ), true
90- }
91-
9260func (rt ResourceType ) CanGetVoidedIfNotReferenced () bool {
9361 return rt == ResourceTypes .JSONDashboardBase
9462}
0 commit comments