Skip to content

Commit 9d0f274

Browse files
authored
Merge pull request #257 from rawmind0/auditlog
Fix audit_log.configuration.policy argument to `rke_config.services.kube_api` argument
2 parents 66868d2 + affd025 commit 9d0f274

140 files changed

Lines changed: 42636 additions & 33 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
FEATURES:
44

5-
5+
* **New Data Source:** `rancher2_pod_security_policy_template`
6+
* **New Resource:** `rancher2_pod_security_policy_template`
67

78
ENHANCEMENTS:
89

10+
* Updated `rancher/norman` go modules and vendor files
911
* Added `plugin` optional value `none` to `rke_config` argument on `rancher2_cluster` resource
1012
* Updated multiline arguments to trim spaces by default and avoid false diff
1113
* Updated `rancher/types` go modules and vendor files
@@ -14,6 +16,10 @@ ENHANCEMENTS:
1416

1517
BUG FIXES:
1618

19+
* Fix `audit_log.configuration.policy` argument to `rke_config.services.kube_api` argument on `rancher2_cluster` resource
20+
* Added `plugin` optional value `none` to `rke_config` argument on `rancher2_cluster` resource
21+
* Updated multiline arguments to trim spaces by default and avoid false diff
22+
* Updated `private_key_file` definition for openstack driver on `rancher2_node_template` docs
1723
* Updated `private_key_file` definition for openstack driver on `rancher2_node_template` docs
1824
* Fixed `rke_config.cloud_provider.aws_cloud_provider.global` argument as computed to avoid false diff
1925

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ module github.com/terraform-providers/terraform-provider-rancher2
33
go 1.12
44

55
require (
6+
github.com/ghodss/yaml v1.0.0
67
github.com/google/btree v1.0.0 // indirect
78
github.com/hashicorp/go-version v1.2.0
89
github.com/hashicorp/terraform-plugin-sdk v1.7.0
910
github.com/rancher/norman v0.0.0-20200206042542-ef3920abad1c
1011
github.com/rancher/types v0.0.0-20191220141556-ad31d6815bbd
1112
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586
13+
gopkg.in/yaml.v2 v2.2.5
14+
k8s.io/apiserver v0.0.0
1215
)
1316

1417
replace (

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
931931
gopkg.in/check.v1 v1.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
932932
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
933933
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
934+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
934935
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
935936
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
936937
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
@@ -940,6 +941,7 @@ gopkg.in/fsnotify/fsnotify.v1 v1.4.7/go.mod h1:Fyux9zXlo4rWoMSIzpn9fDAYjalPqJ/K1
940941
gopkg.in/gcfg.v1 v1.2.0/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
941942
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
942943
gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
944+
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
943945
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
944946
gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
945947
gopkg.in/mcuadros/go-syslog.v2 v2.2.1/go.mod h1:l5LPIyOOyIdQquNg+oU6Z3524YwrcqEm0aKH+5zpt2U=
@@ -973,6 +975,7 @@ howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCU
973975
k8s.io/api v0.0.0-20181213150558-05914d821849/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
974976
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
975977
k8s.io/api v0.0.0-20190620084959-7cf5895f2711/go.mod h1:TBhBqb1AWbBQbW3XRusr7n7E4v2+5ZY8r8sAMnyFC5A=
978+
k8s.io/api v0.0.0-20190918155943-95b840bb6a1f h1:8FRUST8oUkEI45WYKyD8ed7Ad0Kg5v11zHyPkEVb2xo=
976979
k8s.io/api v0.0.0-20190918155943-95b840bb6a1f/go.mod h1:uWuOHnjmNrtQomJrvEBg0c0HRNyQ+8KTEERVsK0PW48=
977980
k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8/go.mod h1:IxkesAMoaCRoLrPJdZNZUQp9NfZnzqaVzLhb2VEQzXE=
978981
k8s.io/apiextensions-apiserver v0.0.0-20190620085554-14e95df34f1f/go.mod h1:++XMkbLSSAutLgulnUnXW4kNbSkyQzlPL8PaW4hjJT4=
@@ -984,6 +987,7 @@ k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719/go.mod h1:I4A+glKBHiTgiEj
984987
k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655 h1:CS1tBQz3HOXiseWZu6ZicKX361CZLT97UFnnPx0aqBw=
985988
k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655/go.mod h1:nL6pwRT8NgfF8TT68DBI8uEePRt89cSvoXUVqbkWHq4=
986989
k8s.io/apiserver v0.0.0-20190620085212-47dc9a115b18/go.mod h1:Hc9PbFVOsMigd7B7OiY/6bIRkR8y31eIKsr1D+JtKg4=
990+
k8s.io/apiserver v0.0.0-20190918160949-bfa5e2e684ad h1:IMoNR9pilTBaCS5WpwWnAdmoVYVeXowOD3bLrwxIAtQ=
987991
k8s.io/apiserver v0.0.0-20190918160949-bfa5e2e684ad/go.mod h1:XPCXEwhjaFN29a8NldXA901ElnKeKLrLtREO9ZhFyhg=
988992
k8s.io/cli-runtime v0.0.0-20190918162238-f783a3654da8/go.mod h1:WRliO+M6Osz7/zdOF0RI42IsJgSYHUwbLgqAWJPneSs=
989993
k8s.io/client-go v12.0.0+incompatible/go.mod h1:E95RaSlHr79aHaX0aGSwcPNfygDiPKOVXdmivCIZT0k=

rancher2/resource_rancher2_cluster_test.go

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,20 @@ resource "rancher2_cluster" "foo" {
2626
creation = "6h"
2727
retention = "24h"
2828
}
29-
}
29+
kube_api {
30+
audit_log {
31+
enabled = true
32+
configuration {
33+
max_age = 5
34+
max_backup = 5
35+
max_size = 100
36+
path = "-"
37+
format = "json"
38+
policy = "apiVersion: audit.k8s.io/v1\nkind: Policy\nmetadata:\n creationTimestamp: null\nomitStages:\n- RequestReceived\nrules:\n- level: RequestResponse\n resources:\n - resources:\n - pods\n"
39+
}
40+
}
41+
}
42+
}
3043
}
3144
}
3245
`
@@ -44,7 +57,20 @@ resource "rancher2_cluster" "foo" {
4457
creation = "12h"
4558
retention = "72h"
4659
}
47-
}
60+
kube_api {
61+
audit_log {
62+
enabled = true
63+
configuration {
64+
max_age = 7
65+
max_backup = 5
66+
max_size = 100
67+
path = "-"
68+
format = "json"
69+
policy = "apiVersion: audit.k8s.io/v1\nkind: Policy\nmetadata:\n creationTimestamp: null\nomitStages:\n- RequestReceived\nrules:\n- level: RequestResponse\n resources:\n - resources:\n - pods\n"
70+
}
71+
}
72+
}
73+
}
4874
}
4975
}
5076
`
@@ -62,7 +88,20 @@ resource "rancher2_cluster" "foo" {
6288
creation = "6h"
6389
retention = "24h"
6490
}
65-
}
91+
kube_api {
92+
audit_log {
93+
enabled = true
94+
configuration {
95+
max_age = 5
96+
max_backup = 5
97+
max_size = 100
98+
path = "-"
99+
format = "json"
100+
policy = "apiVersion: audit.k8s.io/v1\nkind: Policy\nmetadata:\n creationTimestamp: null\nomitStages:\n- RequestReceived\nrules:\n- level: RequestResponse\n resources:\n - resources:\n - pods\n"
101+
}
102+
}
103+
}
104+
}
66105
}
67106
}
68107
`
@@ -105,6 +144,7 @@ func TestAccRancher2Cluster_basic_RKE(t *testing.T) {
105144
resource.TestCheckResourceAttr(testAccRancher2ClusterType+".foo", "description", "Terraform custom cluster acceptance test"),
106145
resource.TestCheckResourceAttr(testAccRancher2ClusterType+".foo", "rke_config.0.services.0.etcd.0.creation", "6h"),
107146
resource.TestCheckResourceAttr(testAccRancher2ClusterType+".foo", "rke_config.0.services.0.etcd.0.retention", "24h"),
147+
resource.TestCheckResourceAttr(testAccRancher2ClusterType+".foo", "rke_config.0.services.0.kube_api.0.audit_log.0.configuration.0.max_age", "5"),
108148
),
109149
},
110150
resource.TestStep{
@@ -115,6 +155,7 @@ func TestAccRancher2Cluster_basic_RKE(t *testing.T) {
115155
resource.TestCheckResourceAttr(testAccRancher2ClusterType+".foo", "description", "Terraform custom cluster acceptance test - updated"),
116156
resource.TestCheckResourceAttr(testAccRancher2ClusterType+".foo", "rke_config.0.services.0.etcd.0.creation", "12h"),
117157
resource.TestCheckResourceAttr(testAccRancher2ClusterType+".foo", "rke_config.0.services.0.etcd.0.retention", "72h"),
158+
resource.TestCheckResourceAttr(testAccRancher2ClusterType+".foo", "rke_config.0.services.0.kube_api.0.audit_log.0.configuration.0.max_age", "7"),
118159
),
119160
},
120161
resource.TestStep{
@@ -125,6 +166,7 @@ func TestAccRancher2Cluster_basic_RKE(t *testing.T) {
125166
resource.TestCheckResourceAttr(testAccRancher2ClusterType+".foo", "description", "Terraform custom cluster acceptance test"),
126167
resource.TestCheckResourceAttr(testAccRancher2ClusterType+".foo", "rke_config.0.services.0.etcd.0.creation", "6h"),
127168
resource.TestCheckResourceAttr(testAccRancher2ClusterType+".foo", "rke_config.0.services.0.etcd.0.retention", "24h"),
169+
resource.TestCheckResourceAttr(testAccRancher2ClusterType+".foo", "rke_config.0.services.0.kube_api.0.audit_log.0.configuration.0.max_age", "5"),
128170
),
129171
},
130172
},

rancher2/schema_cluster_rke_config_services_kube_api.go

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package rancher2
22

33
import (
4+
"fmt"
5+
"reflect"
6+
47
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
auditv1 "k8s.io/apiserver/pkg/apis/audit/v1"
59
)
610

711
const (
8-
servicesKubeAPIAuditLogPolicyOmitStages = "omitStages"
9-
servicesKubeAPIAuditLogPolicyRules = "rules"
12+
clusterRKEConfigServicesKubeAPIAuditLogConfigPolicyApiversionTag = "apiVersion"
13+
clusterRKEConfigServicesKubeAPIAuditLogConfigPolicyKindDefault = "Policy"
14+
clusterRKEConfigServicesKubeAPIAuditLogConfigPolicyKindTag = "kind"
1015
)
1116

1217
var (
13-
servicesKubeAPIAuditLogPolicy = []string{servicesKubeAPIAuditLogPolicyOmitStages, servicesKubeAPIAuditLogPolicyRules}
18+
clusterRKEConfigServicesKubeAPIAuditLogConfigPolicyRequired = []string{
19+
clusterRKEConfigServicesKubeAPIAuditLogConfigPolicyApiversionTag,
20+
clusterRKEConfigServicesKubeAPIAuditLogConfigPolicyKindTag}
1421
)
1522

1623
//Schemas
@@ -45,6 +52,45 @@ func clusterRKEConfigServicesKubeAPIAuditLogConfigFields() map[string]*schema.Sc
4552
"policy": {
4653
Type: schema.TypeString,
4754
Optional: true,
55+
Computed: true,
56+
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
57+
v, ok := val.(string)
58+
if !ok || len(v) == 0 {
59+
return
60+
}
61+
m, err := ghodssyamlToMapInterface(v)
62+
if err != nil {
63+
errs = append(errs, fmt.Errorf("%q must be in yaml format, error: %v", key, err))
64+
return
65+
}
66+
for _, k := range clusterRKEConfigServicesKubeAPIAuditLogConfigPolicyRequired {
67+
check, ok := m[k].(string)
68+
if !ok || len(check) == 0 {
69+
errs = append(errs, fmt.Errorf("%s is required on yaml", k))
70+
}
71+
if k == clusterRKEConfigServicesKubeAPIAuditLogConfigPolicyKindTag {
72+
if check != clusterRKEConfigServicesKubeAPIAuditLogConfigPolicyKindDefault {
73+
errs = append(errs, fmt.Errorf("%s value %s should be: %s", k, check, clusterRKEConfigServicesKubeAPIAuditLogConfigPolicyKindDefault))
74+
}
75+
}
76+
77+
}
78+
return
79+
},
80+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
81+
if old == "" || new == "" {
82+
return false
83+
}
84+
oldPolicy := &auditv1.Policy{}
85+
newPolicy := &auditv1.Policy{}
86+
oldMap, _ := ghodssyamlToMapInterface(old)
87+
newMap, _ := ghodssyamlToMapInterface(new)
88+
oldStr, _ := mapInterfaceToJSON(oldMap)
89+
newStr, _ := mapInterfaceToJSON(newMap)
90+
jsonToInterface(oldStr, oldPolicy)
91+
jsonToInterface(newStr, newPolicy)
92+
return reflect.DeepEqual(oldPolicy, newPolicy)
93+
},
4894
},
4995
}
5096
return s
@@ -56,6 +102,7 @@ func clusterRKEConfigServicesKubeAPIAuditLogFields() map[string]*schema.Schema {
56102
Type: schema.TypeList,
57103
MaxItems: 1,
58104
Optional: true,
105+
Computed: true,
59106
Elem: &schema.Resource{
60107
Schema: clusterRKEConfigServicesKubeAPIAuditLogConfigFields(),
61108
},

rancher2/structure_cluster_rke_config_services_kube_api.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,11 @@ func flattenClusterRKEConfigServicesKubeAPIAuditLogConfig(in *managementClient.A
1919
obj["path"] = in.Path
2020

2121
if len(in.Policy) > 0 {
22-
policy := map[string]interface{}{}
23-
24-
for _, field := range servicesKubeAPIAuditLogPolicy {
25-
if in.Policy[field] != nil {
26-
policy[field] = in.Policy[field]
27-
}
28-
}
29-
policyMap, err := mapInterfaceToJson(policy)
22+
policyStr, err := mapInterfaceToYAML(in.Policy)
3023
if err != nil {
3124
return nil, err
3225
}
33-
obj["policy"] = policyMap
26+
obj["policy"] = policyStr
3427
}
3528

3629
return []interface{}{obj}, nil
@@ -170,19 +163,12 @@ func expandClusterRKEConfigServicesKubeAPIAuditLogConfig(p []interface{}) (*mana
170163
}
171164

172165
if v, ok := in["policy"].(string); ok && len(v) > 0 {
173-
policyMap, err := jsonToMapInterface(v)
166+
policyMap, err := ghodssyamlToMapInterface(v)
174167
if err != nil {
175168
return nil, err
176169
}
177-
policy := map[string]interface{}{}
178-
179-
for _, field := range servicesKubeAPIAuditLogPolicy {
180-
if policyMap[field] != nil {
181-
policy[field] = policyMap[field]
182-
}
183-
}
184170

185-
obj.Policy = policy
171+
obj.Policy = policyMap
186172
}
187173

188174
return obj, nil

rancher2/structure_cluster_rke_config_services_kube_api_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func init() {
2828
MaxSize: 100,
2929
Path: "path",
3030
Policy: map[string]interface{}{
31-
"omitStages": "conf1",
32-
"rules": "conf2",
31+
"apiVersion": "audit.k8s.io/v1",
32+
"kind": "Policy",
3333
},
3434
}
3535
testClusterRKEConfigServicesKubeAPIAuditLogConfigInterface = []interface{}{
@@ -39,7 +39,7 @@ func init() {
3939
"max_backup": 10,
4040
"max_size": 100,
4141
"path": "path",
42-
"policy": `{"omitStages":"conf1","rules":"conf2"}`,
42+
"policy": "apiVersion: audit.k8s.io/v1\nkind: Policy\n",
4343
},
4444
}
4545
testClusterRKEConfigServicesKubeAPIAuditLogConf = &managementClient.AuditLog{

0 commit comments

Comments
 (0)