@@ -17,20 +17,20 @@ import (
17
17
)
18
18
19
19
const (
20
- defaultSKSClusterCNI = "calico"
21
- defaultSKSClusterServiceLevel = "pro"
22
- defaultSKSClusterAuditInitBackoff = "10s"
20
+ defaultSKSClusterCNI = "calico"
21
+ defaultSKSClusterServiceLevel = "pro"
22
+ defaultSKSClusterAuditInitBackoff = "10s"
23
23
24
24
sksClusterAddonExoscaleCCM = "exoscale-cloud-controller"
25
25
sksClusterAddonExoscaleCSI = "exoscale-container-storage-interface"
26
26
sksClusterAddonMS = "metrics-server"
27
27
28
28
resSKSClusterAttrAddons = "addons"
29
29
resSKSClusterAttrAggregationLayerCA = "aggregation_ca"
30
- resSKSClusterAttrAuditBearerToken = "audit_bearer_token"
31
- resSKSClusterAttrAuditEnabled = "audit_enabled"
32
- resSKSClusterAttrAuditEndpoint = "audit_endpoint"
33
- resSKSClusterAttrAuditInitBackoff = "audit_initial_backoff"
30
+ resSKSClusterAttrAuditBearerToken = "audit_bearer_token"
31
+ resSKSClusterAttrAuditEnabled = "audit_enabled"
32
+ resSKSClusterAttrAuditEndpoint = "audit_endpoint"
33
+ resSKSClusterAttrAuditInitBackoff = "audit_initial_backoff"
34
34
resSKSClusterAttrAutoUpgrade = "auto_upgrade"
35
35
resSKSClusterAttrCNI = "cni"
36
36
resSKSClusterAttrControlPlaneCA = "control_plane_ca"
@@ -82,31 +82,27 @@ func resourceSKSCluster() *schema.Resource {
82
82
Description : "The CA certificate (in PEM format) for TLS communications between the control plane and the aggregation layer (e.g. `metrics-server`)." ,
83
83
},
84
84
"audit" : {
85
- Type : schema .TypeList ,
86
- MaxItems : 1 ,
87
- Optional : true ,
88
- Computed : true ,
85
+ Type : schema .TypeList ,
86
+ MaxItems : 1 ,
87
+ Optional : true ,
89
88
Description : "Parameters for Kubernetes Audit configuration (may only be enabled at creation time)" ,
90
89
Elem : & schema.Resource {
91
- Schema : map [string ]* schema.Schema {
92
- resSKSClusterAttrAuditEnabled : {
93
- Type : schema .TypeBool ,
94
- Required : false ,
90
+ Schema : map [string ]* schema.Schema {
91
+ resSKSClusterAttrAuditEnabled : {
92
+ Type : schema .TypeBool ,
95
93
Description : "Whether to run the APIServer with the configured Kubernetes Audit" ,
96
94
},
97
95
resSKSClusterAttrAuditEndpoint : {
98
- Type : schema .TypeString ,
99
- Required : true ,
96
+ Type : schema .TypeString ,
97
+ Required : true ,
100
98
Description : "The Endpoint URL for the Webserver responsible of processing Audit events" ,
101
99
},
102
100
resSKSClusterAttrAuditInitBackoff : {
103
- Type : schema .TypeString ,
104
- Required : false ,
101
+ Type : schema .TypeString ,
105
102
Description : "The Initial Backoff to wait before sending data to the remote server (default '10s')" ,
106
103
},
107
104
resSKSClusterAttrAuditBearerToken : {
108
- Type : schema .TypeString ,
109
- Required : false ,
105
+ Type : schema .TypeString ,
110
106
Description : "The optional bearer token to include in the request header" ,
111
107
},
112
108
},
@@ -393,16 +389,19 @@ func resourceSKSClusterCreate(ctx context.Context, d *schema.ResourceData, meta
393
389
}
394
390
createReq .Version = version
395
391
396
- if v , ok := d .GetOk (resSKSClusterAttrAudit (resSKSClusterAttrAuditEndpoint )); ok {
397
- createReq .Audit = & v3.SKSAuditCreate {
398
- Endpoint : v .(v3.SKSAuditEndpoint ),
399
- }
392
+ auditEnabled := d .Get (resSKSClusterAttrAuditEnabled ).(bool )
393
+ if auditEnabled {
394
+ if v , ok := d .GetOk (resSKSClusterAttrAudit (resSKSClusterAttrAuditEndpoint )); ok {
395
+ createReq .Audit = & v3.SKSAuditCreate {
396
+ Endpoint : v .(v3.SKSAuditEndpoint ),
397
+ }
400
398
401
- if v , ok := d .GetOk (resSKSClusterAttrAudit (resSKSClusterAttrAuditBearerToken )); ok {
402
- createReq .Audit .BearerToken = v .(v3.SKSAuditBearerToken )
403
- }
404
- if v , ok := d .GetOk (resSKSClusterAttrAudit (resSKSClusterAttrAuditInitBackoff )); ok {
405
- createReq .Audit .InitialBackoff = v .(v3.SKSAuditInitialBackoff )
399
+ if v , ok := d .GetOk (resSKSClusterAttrAudit (resSKSClusterAttrAuditBearerToken )); ok {
400
+ createReq .Audit .BearerToken = v .(v3.SKSAuditBearerToken )
401
+ }
402
+ if v , ok := d .GetOk (resSKSClusterAttrAudit (resSKSClusterAttrAuditInitBackoff )); ok {
403
+ createReq .Audit .InitialBackoff = v .(v3.SKSAuditInitialBackoff )
404
+ }
406
405
}
407
406
}
408
407
@@ -625,8 +624,27 @@ func resourceSKSClusterUpdate(ctx context.Context, d *schema.ResourceData, meta
625
624
}
626
625
}
627
626
628
- if d .HasChange (resSKSClusterAttrAuditEndpoint ) {
629
- // TODO
627
+ if d .HasChange (resSKSClusterAttrAuditEndpoint ) || d .HasChange (resSKSClusterAttrAuditEnabled ) ||
628
+ d .HasChange (resSKSClusterAttrAuditBearerToken ) || d .HasChange (resSKSClusterAttrAuditInitBackoff ) {
629
+ enableAudit := d .Get (resSKSClusterAttrAuditEnabled ).(bool )
630
+ updateReq .Audit = & v3.SKSAuditUpdate {
631
+ Enabled : & enableAudit ,
632
+ Endpoint : v3 .SKSAuditEndpoint (d .Get (resSKSClusterAttrAuditEndpoint ).(string )),
633
+ }
634
+
635
+ if enableAudit && updateReq .Audit .Endpoint == "" {
636
+ return diag .Errorf ("cannot enable audit without setting an endpoint" )
637
+ }
638
+
639
+ if v , ok := d .GetOk (resSKSClusterAttrAuditBearerToken ); ok {
640
+ updateReq .Audit .BearerToken = v .(v3.SKSAuditBearerToken )
641
+ }
642
+
643
+ if v , ok := d .GetOk (resSKSClusterAttrAuditInitBackoff ); ok {
644
+ updateReq .Audit .InitialBackoff = v .(v3.SKSAuditInitialBackoff )
645
+ }
646
+
647
+ updated = true
630
648
}
631
649
632
650
if updated {
0 commit comments