1
1
const AzureCompute = require ( '@azure/arm-compute' ) ;
2
2
const AzureResources = require ( '@azure/arm-resources' )
3
3
const MsRest = require ( '@azure/ms-rest-nodeauth' ) ;
4
+
5
+ const FS = require ( 'fs' ) ;
6
+
4
7
const ClientID = process . env . ARM_CLIENT_ID ;
5
8
const ClientSecret = process . env . ARM_CLIENT_SECRET ;
6
9
const SubscriptionID = process . env . ARM_SUBSCRIPTION_ID ;
7
10
const TenantID = process . env . ARM_TENANT_ID ;
8
- const debug = process . env . DEBUG || false ;
9
- const FS = require ( 'fs' ) ;
11
+
12
+
13
+ const TFAzureResource = require ( './lib/tfobj' ) ;
10
14
11
15
function getCredentials ( ) {
12
16
return new Promise ( ( resolve , reject ) => {
@@ -21,49 +25,21 @@ function getCredentials() {
21
25
} )
22
26
}
23
27
24
- function toTfObject ( azObject ) {
25
- const startTF = `resource "${ azObject . armResourceType } " "${ azObject . name } " {`
26
- const endTF = `}`
27
- let tfObject = startTF + "\n" ;
28
-
29
- delete azObject . id ;
30
- delete azObject . armResourceType ;
31
- delete azObject . managedBy ;
32
-
33
- for ( var property in azObject ) {
34
- const type = azObject [ property ] . constructor ;
35
-
36
- if ( azObject . hasOwnProperty ( property ) ) {
37
- switch ( type ) {
38
- case Object :
39
- break ;
40
- default :
41
- tfObject += objectify ( property , azObject [ property ] )
42
- }
43
- }
44
- }
45
-
46
- tfObject += endTF ;
47
-
48
- if ( debug ) {
49
- console . log ( tfObject ) ;
50
- }
51
-
52
- return tfObject ;
53
- }
54
-
55
- function objectify ( property , value ) {
56
- return "\t" + `${ property } = "${ value } "` + "\n" ;
57
- }
58
-
59
28
getCredentials ( ) . then ( credentials => {
60
29
const client = new AzureResources . ResourceManagementClient ( credentials , SubscriptionID ) ;
61
30
62
31
client . resourceGroups . list ( )
63
32
. then ( ( groups ) => {
64
- groups . forEach ( ( group , index ) => {
65
- group . armResourceType = 'azurerm_resource_group' ;
66
- toTfObject ( group ) ;
33
+ groups . forEach ( group => {
34
+ let thing = new TFAzureResource ( 'azurerm_resource_group' , group ) ;
35
+
36
+ thing . saveToFile ( )
37
+ . then ( obj => { console . log ( obj ) } )
38
+ . catch ( )
67
39
} )
40
+ // groups.forEach((group, index) => {
41
+ // group.armResourceType = 'azurerm_resource_group';
42
+ // toTfObject(group);
43
+ // })
68
44
} )
69
45
} )
0 commit comments