44 "fmt"
55
66 "github.com/hashicorp/hcl/v2"
7+ "github.com/hashicorp/hcl/v2/hclsyntax"
78 "github.com/hashicorp/hcl/v2/hclwrite"
89)
910
@@ -16,17 +17,21 @@ func ClusterToAdvancedCluster(config []byte) ([]byte, error) {
1617 if err != nil {
1718 return nil , err
1819 }
19- body := parser .Body ()
20- for _ , resource := range body .Blocks () {
20+ for _ , resource := range parser .Body ().Blocks () {
2121 isResource := resource .Type () == "resource"
2222 labels := resource .Labels ()
2323 resourceName := labels [0 ]
2424 if ! isResource || resourceName != "mongodbatlas_cluster" {
2525 continue
2626 }
27+ resourceBody := resource .Body ()
28+
2729 // TODO: Do the full transformation
2830 labels [0 ] = "mongodbatlas_advanced_cluster"
2931 resource .SetLabels (labels )
32+ resourceBody .AppendNewline ()
33+ appendComment (resourceBody , "Generated by atlas-cli-plugin-terraform." )
34+ appendComment (resourceBody , "Please confirm that all references to this resource are updated." )
3035 }
3136 return parser .Bytes (), nil
3237}
@@ -38,3 +43,13 @@ func getParser(config []byte) (*hclwrite.File, error) {
3843 }
3944 return parser , nil
4045}
46+
47+ func appendComment (body * hclwrite.Body , comment string ) {
48+ tokens := hclwrite.Tokens {
49+ & hclwrite.Token {
50+ Type : hclsyntax .TokenComment ,
51+ Bytes : []byte ("# " + comment + "\n " ),
52+ },
53+ }
54+ body .AppendUnstructuredTokens (tokens )
55+ }
0 commit comments