-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor resource mapping file (#234)
- Loading branch information
Showing
10 changed files
with
258 additions
and
142 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
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 |
---|---|---|
@@ -1,39 +1,13 @@ | ||
package resmap | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/Azure/aztfy/internal/tfaddr" | ||
) | ||
|
||
type ResourceMapping map[string]tfaddr.TFAddr | ||
|
||
func (res ResourceMapping) MarshalJSON() ([]byte, error) { | ||
m := map[string]string{} | ||
for id, addr := range res { | ||
m[id] = addr.String() | ||
} | ||
return json.Marshal(m) | ||
type ResourceMapEntity struct { | ||
// TF resource ID | ||
ResourceId string `json:"resource_id"` | ||
// TF resource type | ||
ResourceType string `json:"resource_type"` | ||
// TF resource name | ||
ResourceName string `json:"resource_name"` | ||
} | ||
|
||
func (res *ResourceMapping) UnmarshalJSON(b []byte) error { | ||
out := ResourceMapping{} | ||
var m map[string]string | ||
if err := json.Unmarshal(b, &m); err != nil { | ||
return err | ||
} | ||
for id, addr := range m { | ||
var tfAddr tfaddr.TFAddr | ||
if addr != "" { | ||
pTFAddr, err := tfaddr.ParseTFResourceAddr(addr) | ||
if err != nil { | ||
return fmt.Errorf("parsing TF address %q: %v", addr, err) | ||
} | ||
tfAddr = *pTFAddr | ||
} | ||
out[id] = tfAddr | ||
} | ||
*res = out | ||
return nil | ||
} | ||
// ResourceMapping is the resource mapping file, the key is the Azure resource Id in uppercase. | ||
type ResourceMapping map[string]ResourceMapEntity |
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
Oops, something went wrong.