-
Notifications
You must be signed in to change notification settings - Fork 1
/
resource_cloud_account.go
748 lines (699 loc) · 26.4 KB
/
resource_cloud_account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
package dsfhub
import (
"bytes"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"log"
)
func resourceCloudAccount() *schema.Resource {
return &schema.Resource{
Create: resourceCloudAccountCreate,
Read: resourceCloudAccountRead,
Update: resourceCloudAccountUpdate,
Delete: resourceCloudAccountDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Schema: map[string]*schema.Schema{
"admin_email": {
Type: schema.TypeString,
Description: "The email address to notify about this asset",
Required: true,
},
//"application": {
// Type: schema.TypeString,
// Description: "The Asset ID of the application asset that \"owns\" the asset.",
// Required: false,
// Optional: true,
//},
//"arn": {
// Type: schema.TypeString,
// Description: "Amazon Resource Name - format is arn:partition:service:region:account-id and used as the asset_id",
// Required: false,
// Optional: true,
// Computed: true,
// Default: nil,
//},
"asset_display_name": {
Type: schema.TypeString,
Description: "User-friendly name of the asset, defined by user.",
Required: false,
Optional: true,
Default: nil,
},
"asset_id": {
Type: schema.TypeString,
Description: "The following format is a suggestion that guarantees uniqueness and identifiability between AZURE assets using different applications/resource groups: 'directory_id/<directory_id>/subscription_id/<subscription_id>/<resource group name>/application_id/<application_id>'",
Required: true,
},
"asset_source": {
Type: schema.TypeString,
Description: "The source platform/vendor/system of the asset data. Usually the service responsible for creating that asset document",
Required: false,
Optional: true,
Default: nil,
},
"available_regions": {
Type: schema.TypeString,
Description: "A list of regions to use in discovery actions that iterate through region",
Required: false,
Optional: true,
Default: nil,
},
"aws_proxy_config": {
Type: schema.TypeSet,
Description: "AWS specific proxy configuration",
Required: false,
Optional: true,
Default: nil,
MinItems: 0,
Set: resourceAssetDataAWSProxyConfigHash,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"http": {
Type: schema.TypeString,
Description: "HTTP endpoint for aws proxy config",
Required: false,
Optional: true,
Default: nil,
},
"https": {
Type: schema.TypeString,
Description: "HTTPS endpoint for aws proxy config",
Required: false,
Optional: true,
Default: nil,
},
},
},
},
"asset_connection": {
Type: schema.TypeSet,
Description: "N/A",
Required: true,
MinItems: 0,
Set: resourceCloudAccountConnectionHash,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"access_id": {
Type: schema.TypeString,
Description: "The Access key ID of AWS secret access key used to authenticate",
Optional: true,
Default: nil,
Computed: true,
},
"access_key": {
Type: schema.TypeString,
Description: "The Secret access key used to authenticate",
Optional: true,
Default: nil,
Computed: true,
},
"amazon_secret": {
Type: schema.TypeSet,
Description: "Configuration to integrate with AWS Secrets Manager",
Required: false,
Optional: true,
Default: nil,
MinItems: 0,
MaxItems: 1,
Set: resourceConnectionDataAmazonSecretHash,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"field_mapping": {
Type: schema.TypeMap,
Description: "Field mapping for amazon secret",
Required: false,
Optional: true,
Default: nil,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"secret_asset_id": {
Type: schema.TypeString,
Description: "Amazon secret asset id",
Required: false,
Optional: true,
Default: nil,
},
"secret_name": {
Type: schema.TypeString,
Description: "Amazon secret mane",
Required: false,
Optional: true,
Default: nil,
},
},
},
},
"application_id": {
Type: schema.TypeString,
Description: "This is also referred to as the Client ID and it’s the unique identifier for the registered application being used to execute Python SDK commands against Azure’s API services. You can find this number under Azure Active Directory -> App Registrations -> Owned Applications",
Optional: true,
Default: nil,
Computed: true,
},
"auth_mechanism": {
Type: schema.TypeString,
Description: "Specifies the auth mechanism used by the connection",
Required: true,
ValidateFunc: validation.StringInSlice([]string{"auth_file", "client_secret", "default", "iam_role", "key", "machine_role", "managed_identity", "profile", "service_account"}, false),
},
"ca_certs_path": {
Type: schema.TypeString,
Description: "Certificate authority certificates path; what location should the sysetm look for certificate information from. Equivalent to --capath in a curl call",
Required: false,
Optional: true,
Default: nil,
},
"client_secret": {
Type: schema.TypeString,
Description: "This a string containing a secret used by the application to prove its identity when requesting a token. You can get a secret by going to Azure Active Directory -> App Registrations -> Owned Applications, selecting the desired application and then going to Certificates & secrets -> Client secrets -> + New client secret",
Required: false,
Optional: true,
Default: nil,
},
"credential_fields": {
Type: schema.TypeSet,
Description: "Document containing values to build a profile from. Filling this will create a profile using the given profile name",
Required: false,
Optional: true,
Default: nil,
MinItems: 0,
Set: resourceConnectionDataCredentialFieldsHash,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"credential_source": {
Type: schema.TypeString,
Description: "HashiCorp secret asset id",
Required: false,
Optional: true,
Default: nil,
},
"role_arn": {
Type: schema.TypeString,
Description: "HashiCorp secret mane",
Required: false,
Optional: true,
Default: nil,
},
},
},
},
"cyberark_secret": {
Type: schema.TypeSet,
Description: "Configuration to integrate with AWS Secrets Manager",
Required: false,
Optional: true,
Default: nil,
MinItems: 0,
MaxItems: 1,
Set: resourceConnectionDataCyberarkSecretHash,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"field_mapping": {
Type: schema.TypeMap,
Description: "Field mapping for amazon secret",
Required: false,
Optional: true,
Default: nil,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"secret_asset_id": {
Type: schema.TypeString,
Description: "Amazon secret asset id",
Required: false,
Optional: true,
Default: nil,
},
"secret_name": {
Type: schema.TypeString,
Description: "Amazon secret mane",
Required: false,
Optional: true,
Default: nil,
},
},
},
},
"directory_id": {
Type: schema.TypeString,
Description: "This is also referred to as the Tenant ID and is a GUID representing the Active Directory Tenant. It can be found in the Azure Active Directory page under the Azure portal",
Required: false,
Optional: true,
Default: nil,
},
"external_id": {
Type: schema.TypeString,
Description: "External ID to use when assuming a role",
Required: false,
Optional: true,
Default: nil,
},
"hashicorp_secret": {
Type: schema.TypeSet,
Description: "Configuration to integrate with HashiCorp Vault",
Required: false,
Optional: true,
Default: nil,
MinItems: 0,
Set: resourceConnectionDataHashicorpSecretHash,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"field_mapping": {
Type: schema.TypeMap,
Description: "Field mapping for HashiCorp secret",
Required: false,
Optional: true,
Default: nil,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"path": {
Type: schema.TypeString,
Description: "HashiCorp secret path",
Required: false,
Optional: true,
Default: nil,
},
"secret_asset_id": {
Type: schema.TypeString,
Description: "HashiCorp secret asset id",
Required: false,
Optional: true,
Default: nil,
},
"secret_name": {
Type: schema.TypeString,
Description: "HashiCorp secret mane",
Required: false,
Optional: true,
Default: nil,
},
},
},
},
"key_file": {
Type: schema.TypeString,
Description: "Location on disk on the key to be used to authenticate",
Required: false,
Optional: true,
Default: nil,
},
"reason": {
Type: schema.TypeString,
Description: "N/A",
Required: false,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"default"}, false),
},
"region": {
Type: schema.TypeString,
Description: "Default AWS region for this asset",
Required: true,
},
"role_name": {
Type: schema.TypeString,
Description: "What role is used to get credentials from.",
Required: false,
Optional: true,
Default: nil,
},
"secret_key": {
Type: schema.TypeString,
Description: "The Secret access key used to authenticate",
Required: false,
Optional: true,
Default: false,
},
"ssl": {
Type: schema.TypeBool,
Description: "If true, use SSL when connecting",
Required: false,
Optional: true,
Default: false,
},
"subscription_id": {
Type: schema.TypeString,
Description: "This is the Azure account subscription ID. You can find this number under the Subscriptions page on the Azure portal",
Required: false,
Optional: true,
Default: nil,
},
"username": {
Type: schema.TypeString,
Description: "The name of a profile in /imperva/local/credentials/.aws/credentials to use for authenticating",
Required: false,
Optional: true,
Default: nil,
},
},
},
},
"credentials_endpoint": {
Type: schema.TypeString,
Description: "A specific sts endpoint to use",
Required: false,
Optional: true,
Default: nil,
},
"criticality": {
Type: schema.TypeInt,
Description: "The asset's importance to the business. These values are measured on a scale from \"Most critical\" (1) to \"Least critical\" (4). Allowed values: 1, 2, 3, 4",
Required: false,
Optional: true,
ValidateFunc: validation.IntInSlice([]int{1, 2, 3, 4}),
Default: nil,
},
"gateway_id": {
Type: schema.TypeString,
Description: "The jsonarUid unique identifier of the agentless gateway. Example: '7a4af7cf-4292-89d9-46ec-183756ksdjd'",
Required: true,
},
"jsonar_uid": {
Type: schema.TypeString,
Description: "Unique identifier (UID) attached to the Sonar machine controlling the asset",
Required: false,
Optional: true,
Default: nil,
Computed: true,
},
"location": {
Type: schema.TypeString,
Description: "Current human-readable description of the physical location of the asset, or region.",
Required: false,
Optional: true,
Default: nil,
Computed: true,
},
"managed_by": {
Type: schema.TypeString,
Description: "Email of the person who maintains the asset; can be different from the owner specified in the owned_by field. Defaults to admin_email.",
Required: false,
Optional: true,
Default: nil,
Computed: true,
},
"owned_by": {
Type: schema.TypeString,
Description: "Email of Owner / person responsible for the asset; can be different from the person in the managed_by field. Defaults to admin_email.",
Required: false,
Optional: true,
Default: nil,
Computed: true,
},
"proxy": {
Type: schema.TypeString,
Description: "Proxy to use for AWS calls if aws_proxy_config is populated the proxy field will get populated from the http value there",
Required: false,
Optional: true,
Default: nil,
},
"region": {
Type: schema.TypeString,
Description: "For cloud systems with regions, the default region or region used with this asset",
Required: false,
Optional: true,
Default: nil,
},
"server_host_name": {
Type: schema.TypeString,
Description: "Hostname (or IP if name is unknown)",
Required: false,
Optional: true,
Default: nil,
},
"server_ip": {
Type: schema.TypeString,
Description: "IP address of the service where this asset is located. If no IP is available populate this field with other information that would identify the system e.g. hostname or AWS ARN, etc.",
Required: false,
Optional: true,
Default: nil,
},
"server_type": {
Type: schema.TypeString,
Description: "The type of server or data service to be created as a data source. The list of available data sources is documented at: https://docs.imperva.com/bundle/v4.11-sonar-user-guide/page/84552.htm",
Required: true,
},
"server_port": {
Type: schema.TypeString,
Description: "",
Required: false,
Optional: true,
Default: nil,
},
"service_endpoints": {
Type: schema.TypeSet,
Description: "Specify particular endpoints for a given service in the form of <service name>: \"endpoint\"",
Required: false,
Optional: true,
Default: nil,
MinItems: 0,
Set: resourceAssetDataServiceEndpointsHash,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"logs": {
Type: schema.TypeString,
Description: "The log endpoint for a given service",
Required: false,
Optional: true,
Default: nil,
},
},
},
},
"used_for": {
Type: schema.TypeString,
Description: "Designates how this asset is used / the environment that the asset is supporting.",
Required: false,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"Development", "Staging", "Test", "Disaster Recovery", "Demonstration", "Production", "QA", "Training"}, false),
Default: nil,
},
"version": {
Type: schema.TypeFloat,
Description: "Denotes the version of the asset",
Required: false,
Optional: true,
Default: nil,
},
},
}
}
func resourceCloudAccountCreate(d *schema.ResourceData, m interface{}) error {
client := m.(*Client)
if isOk, err := checkResourceRequiredFields(requiredCloudAccountJson, ignoreCloudAccountParamsByServerType, d); !isOk {
return err
}
cloudAccount := ResourceWrapper{}
serverType := d.Get("server_type").(string)
createResource(&cloudAccount, serverType, d)
log.Printf("[INFO] Creating CloudAccount for serverType: %s and gatewayId: %s gatewayId: \n", serverType, cloudAccount.Data.GatewayID)
createCloudAccountResponse, err := client.CreateCloudAccount(cloudAccount)
if err != nil {
log.Printf("[ERROR] adding CloudAccount for serverType: %s and gatewayId: %s | err: %s", serverType, cloudAccount.Data.GatewayID, err)
return err
}
cloudAccountId := createCloudAccountResponse.Data.AssetData.AssetID
d.SetId(cloudAccountId)
// Set the rest of the state from the resource read
return resourceCloudAccountRead(d, m)
}
func resourceCloudAccountRead(d *schema.ResourceData, m interface{}) error {
client := m.(*Client)
cloudAccountId := d.Id()
log.Printf("[INFO] Reading CloudAccount with cloudAccountId: %s\n", cloudAccountId)
cloudAccountReadResponse, err := client.ReadCloudAccount(cloudAccountId)
if err != nil {
log.Printf("[ERROR] Reading cloudAccountReadResponse with cloudAccountId: %s | err: %s\n", cloudAccountId, err)
return err
}
if cloudAccountReadResponse != nil {
log.Printf("[INFO] Reading CloudAcount with cloudAccountId: %s | err: %s\n", cloudAccountId, err)
}
log.Printf("[DEBUG] cloudAccountReadResponse: %s\n", cloudAccountReadResponse.Data.ID)
// Set returned and computed values
d.Set("admin_email", cloudAccountReadResponse.Data.AssetData.AdminEmail)
//d.Set("application", cloudAccountReadResponse.Data.AssetData.Application)
//d.Set("arn", cloudAccountReadResponse.Data.AssetData.Arn)
d.Set("asset_display_name", cloudAccountReadResponse.Data.AssetData.AssetDisplayName)
d.Set("asset_id", cloudAccountReadResponse.Data.AssetData.AssetID)
d.Set("asset_source", cloudAccountReadResponse.Data.AssetData.AssetSource)
d.Set("available_regions", cloudAccountReadResponse.Data.AssetData.AvailableRegions)
d.Set("credential_endpoint", cloudAccountReadResponse.Data.AssetData.CredentialsEndpoint)
d.Set("criticality", cloudAccountReadResponse.Data.AssetData.Criticality)
d.Set("gateway_id", cloudAccountReadResponse.Data.GatewayID)
d.Set("jsonar_uid", cloudAccountReadResponse.Data.AssetData.JsonarUID)
d.Set("location", cloudAccountReadResponse.Data.AssetData.Location)
d.Set("managed_by", cloudAccountReadResponse.Data.AssetData.ManagedBy)
d.Set("owned_by", cloudAccountReadResponse.Data.AssetData.OwnedBy)
d.Set("proxy", cloudAccountReadResponse.Data.AssetData.Proxy)
d.Set("region", cloudAccountReadResponse.Data.AssetData.Region)
d.Set("server_host_name", cloudAccountReadResponse.Data.AssetData.ServerHostName)
d.Set("server_ip", cloudAccountReadResponse.Data.AssetData.ServerIP)
d.Set("server_type", cloudAccountReadResponse.Data.ServerType)
if cloudAccountReadResponse.Data.AssetData.ServerPort != nil {
var serverPort string
if serverPortNum, ok := cloudAccountReadResponse.Data.AssetData.ServerPort.(float64); ok {
serverPort = fmt.Sprintf("%d", int(serverPortNum))
} else {
serverPort = cloudAccountReadResponse.Data.AssetData.ServerPort.(string)
}
d.Set("server_port", serverPort)
}
d.Set("used_for", cloudAccountReadResponse.Data.AssetData.UsedFor)
d.Set("version", cloudAccountReadResponse.Data.AssetData.Version)
// Handle Structs
if cloudAccountReadResponse.Data.AssetData.AwsProxyConfig != nil {
awsProxyConfig := &schema.Set{F: resourceAssetDataAWSProxyConfigHash}
awsProxyConfigMap := map[string]interface{}{}
awsProxyConfigMap["http"] = cloudAccountReadResponse.Data.AssetData.AwsProxyConfig.HTTP
awsProxyConfigMap["https"] = cloudAccountReadResponse.Data.AssetData.AwsProxyConfig.HTTPS
awsProxyConfig.Add(awsProxyConfigMap)
d.Set("aws_proxy_config", awsProxyConfig)
}
if cloudAccountReadResponse.Data.AssetData.ServiceEndpoints != nil {
serviceEndpoints := &schema.Set{F: resourceAssetDataServiceEndpointsHash}
serviceEndpointsMap := map[string]interface{}{}
serviceEndpointsMap["logs"] = cloudAccountReadResponse.Data.AssetData.ServiceEndpoints.Logs
serviceEndpoints.Add(serviceEndpointsMap)
d.Set("service_endpoints", serviceEndpoints)
}
connections := &schema.Set{F: resourceCloudAccountConnectionHash}
for _, v := range cloudAccountReadResponse.Data.AssetData.Connections {
connection := map[string]interface{}{}
connection["access_id"] = v.ConnectionData.AccessID
connection["access_key"] = v.ConnectionData.AccessKey
connection["application_id"] = v.ConnectionData.ApplicationID
connection["auth_mechanism"] = v.ConnectionData.AuthMechanism
connection["ca_certs_path"] = v.ConnectionData.CaCertsPath
connection["client_secret"] = v.ConnectionData.ClientSecret
connection["cyberark_secret"] = v.ConnectionData.CyberarkSecret
connection["directory_id"] = v.ConnectionData.DirectoryID
connection["external_id"] = v.ConnectionData.ExternalID
connection["key_file"] = v.ConnectionData.KeyFile
connection["reason"] = v.Reason
connection["region"] = v.ConnectionData.Region
connection["role_name"] = v.ConnectionData.RoleName
connection["secret_key"] = v.ConnectionData.SecretKey
connection["ssl"] = v.ConnectionData.Ssl
connection["subscription_id"] = v.ConnectionData.SubscriptionID
connection["username"] = v.ConnectionData.Username
// Handle structs
if v.ConnectionData.AmazonSecret != nil {
amazonSecret := &schema.Set{F: resourceConnectionDataAmazonSecretHash}
amazonSecretMap := map[string]interface{}{}
//amazonSecretMap["field_mapping"] = v.ConnectionData.AmazonSecret.FieldMapping
amazonSecretMap["secret_asset_id"] = v.ConnectionData.AmazonSecret.SecretAssetID
amazonSecretMap["secret_name"] = v.ConnectionData.AmazonSecret.SecretName
amazonSecret.Add(amazonSecretMap)
connection["amazon_secret"] = amazonSecret
}
if v.ConnectionData.CredentialFields != nil {
credentialFields := &schema.Set{F: resourceConnectionDataCredentialFieldsHash}
credentialFieldsMap := map[string]interface{}{}
credentialFieldsMap["credential_source"] = v.ConnectionData.CredentialFields.CredentialSource
credentialFieldsMap["role_arn"] = v.ConnectionData.CredentialFields.RoleArn
credentialFields.Add(credentialFieldsMap)
connection["credential_fields"] = credentialFields
}
if v.ConnectionData.HashicorpSecret != nil {
hashicorpSecret := &schema.Set{F: resourceConnectionDataHashicorpSecretHash}
hashicorpSecretMap := map[string]interface{}{}
//hashicorpSecretMap["field_mapping"] = v.ConnectionData.HashicorpSecret.Path
hashicorpSecretMap["path"] = v.ConnectionData.HashicorpSecret.Path
hashicorpSecretMap["secret_asset_id"] = v.ConnectionData.HashicorpSecret.SecretAssetID
hashicorpSecretMap["secret_name"] = v.ConnectionData.HashicorpSecret.SecretName
hashicorpSecret.Add(hashicorpSecretMap)
connection["hashicorp_secret"] = hashicorpSecret
}
connections.Add(connection)
}
d.Set("ca_connection", connections)
log.Printf("[INFO] Finished reading CloudAccount with cloudAccountId: %s\n", cloudAccountId)
return nil
}
func resourceCloudAccountUpdate(d *schema.ResourceData, m interface{}) error {
client := m.(*Client)
cloudAccountId := d.Id()
if isOk, err := checkResourceRequiredFields(requiredCloudAccountJson, ignoreCloudAccountParamsByServerType, d); !isOk {
return err
}
cloudAccount := ResourceWrapper{}
serverType := d.Get("server_type").(string)
createResource(&cloudAccount, serverType, d)
log.Printf("[INFO] Updating CloudAccount for serverType: %s and gatewayId: %s assetId: %s\n", cloudAccount.Data.ServerType, cloudAccount.Data.GatewayID, cloudAccount.Data.AssetData.AssetID)
_, err := client.UpdateCloudAccount(cloudAccountId, cloudAccount)
if err != nil {
log.Printf("[ERROR] Updating CloudAccount for serverType: %s and gatewayId: %s assetId: %s | err:%s\n", cloudAccount.Data.ServerType, cloudAccount.Data.GatewayID, cloudAccount.Data.AssetData.AssetID, err)
return err
}
d.SetId(cloudAccountId)
// Set the rest of the state from the resource read
return resourceCloudAccountRead(d, m)
}
func resourceCloudAccountDelete(d *schema.ResourceData, m interface{}) error {
client := m.(*Client)
cloudAccountId := d.Id()
log.Printf("[INFO] Deleting secret manager with cloudAccountId: %s", cloudAccountId)
cloudAccountDeleteResponse, err := client.DeleteCloudAccount(cloudAccountId)
if cloudAccountDeleteResponse != nil {
log.Printf("[INFO] CloudAccount has already been deleted with cloudAccountId: %s | err: %s\n", cloudAccountId, err)
}
return nil
}
func resourceCloudAccountConnectionHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
if v, ok := m["reason"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["access_id"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["access_key"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["application_id"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["ca_certs_path"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["client_secret"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["directory_id"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["external_id"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["key_file"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["region"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["role_name"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["secret_key"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["ssl"]; ok {
buf.WriteString(fmt.Sprintf("%v-", v.(bool)))
}
if v, ok := m["subscription_id"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["username"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
return PositiveHash(buf.String())
}