diff --git a/.changelog/2576.txt b/.changelog/2576.txt new file mode 100644 index 0000000000..2cb42fd67a --- /dev/null +++ b/.changelog/2576.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +Added support for the `ValidatingAdmissionPolicy` resource. +``` \ No newline at end of file diff --git a/go.mod b/go.mod index dba58ebb83..f924effede 100644 --- a/go.mod +++ b/go.mod @@ -7,15 +7,18 @@ require ( github.com/getkin/kin-openapi v0.111.0 github.com/google/go-cmp v0.6.0 github.com/hashicorp/go-hclog v1.6.3 - github.com/hashicorp/go-plugin v1.6.0 + github.com/hashicorp/go-plugin v1.6.2 github.com/hashicorp/go-version v1.6.0 github.com/hashicorp/hc-install v0.6.4 github.com/hashicorp/hcl/v2 v2.20.1 github.com/hashicorp/terraform-exec v0.21.0 github.com/hashicorp/terraform-json v0.22.1 + github.com/hashicorp/terraform-plugin-codegen-kubernetes v0.1.0 github.com/hashicorp/terraform-plugin-docs v0.16.0 - github.com/hashicorp/terraform-plugin-framework v1.7.0 - github.com/hashicorp/terraform-plugin-go v0.23.0 + github.com/hashicorp/terraform-plugin-framework v1.13.0 + github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 + github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 + github.com/hashicorp/terraform-plugin-go v0.25.0 github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-mux v0.16.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 @@ -63,9 +66,9 @@ require ( github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/x448/float16 v0.8.4 // indirect golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect - golang.org/x/sync v0.7.0 // indirect + golang.org/x/sync v0.8.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect ) require ( @@ -129,16 +132,16 @@ require ( github.com/xlab/treeprint v1.2.0 // indirect github.com/zclconf/go-cty v1.14.4 go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect - golang.org/x/crypto v0.24.0 // indirect - golang.org/x/net v0.26.0 // indirect - golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/term v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/crypto v0.26.0 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/oauth2 v0.22.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/term v0.23.0 // indirect + golang.org/x/text v0.17.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/grpc v1.63.2 - google.golang.org/protobuf v1.34.2 // indirect + google.golang.org/grpc v1.67.1 + google.golang.org/protobuf v1.35.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 4219e31c73..d115da0a4c 100644 --- a/go.sum +++ b/go.sum @@ -163,8 +163,8 @@ github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVH github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/go-plugin v1.6.0 h1:wgd4KxHJTVGGqWBq4QPB1i5BZNEx9BR8+OFmHDmTk8A= -github.com/hashicorp/go-plugin v1.6.0/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI= +github.com/hashicorp/go-plugin v1.6.2 h1:zdGAEd0V1lCaU0u+MxWQhtSDQmahpkwOun8U8EiRVog= +github.com/hashicorp/go-plugin v1.6.2/go.mod h1:CkgLQ5CZqNmdL9U9JzM532t8ZiYQ35+pj3b1FD37R0Q= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -180,12 +180,18 @@ github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVW github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg= github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7orfb5Ltvec= github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A= +github.com/hashicorp/terraform-plugin-codegen-kubernetes v0.1.0 h1:cPPZitB7w5qYPbSad0IkhDaXZc7LpDhsgm4g8Kj2cOY= +github.com/hashicorp/terraform-plugin-codegen-kubernetes v0.1.0/go.mod h1:AOwjDhbkWel/4J4fnLB59l52cGmV13FjkqKxaNVJjok= github.com/hashicorp/terraform-plugin-docs v0.16.0 h1:UmxFr3AScl6Wged84jndJIfFccGyBZn52KtMNsS12dI= github.com/hashicorp/terraform-plugin-docs v0.16.0/go.mod h1:M3ZrlKBJAbPMtNOPwHicGi1c+hZUh7/g0ifT/z7TVfA= -github.com/hashicorp/terraform-plugin-framework v1.7.0 h1:wOULbVmfONnJo9iq7/q+iBOBJul5vRovaYJIu2cY/Pw= -github.com/hashicorp/terraform-plugin-framework v1.7.0/go.mod h1:jY9Id+3KbZ17OMpulgnWLSfwxNVYSoYBQFTgsx044CI= -github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co= -github.com/hashicorp/terraform-plugin-go v0.23.0/go.mod h1:1E3Cr9h2vMlahWMbsSEcNrOCxovCZhOOIXjFHbjc/lQ= +github.com/hashicorp/terraform-plugin-framework v1.13.0 h1:8OTG4+oZUfKgnfTdPTJwZ532Bh2BobF4H+yBiYJ/scw= +github.com/hashicorp/terraform-plugin-framework v1.13.0/go.mod h1:j64rwMGpgM3NYXTKuxrCnyubQb/4VKldEKlcG8cvmjU= +github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 h1:gm5b1kHgFFhaKFhm4h2TgvMUlNzFAtUqlcOWnWPm+9E= +github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1/go.mod h1:MsjL1sQ9L7wGwzJ5RjcI6FzEMdyoBnw+XK8ZnOvQOLY= +github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 h1:RXMmu7JgpFjnI1a5QjMCBb11usrW2OtAG+iOTIj5c9Y= +github.com/hashicorp/terraform-plugin-framework-validators v0.15.0/go.mod h1:Bh89/hNmqsEWug4/XWKYBwtnw3tbz5BAy1L1OgvbIaY= +github.com/hashicorp/terraform-plugin-go v0.25.0 h1:oi13cx7xXA6QciMcpcFi/rwA974rdTxjqEhXJjbAyks= +github.com/hashicorp/terraform-plugin-go v0.25.0/go.mod h1:+SYagMYadJP86Kvn+TGeV+ofr/R3g4/If0O5sO96MVw= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= github.com/hashicorp/terraform-plugin-mux v0.16.0 h1:RCzXHGDYwUwwqfYYWJKBFaS3fQsWn/ZECEiW7p2023I= @@ -373,8 +379,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 h1:EDuYyU/MkFXllv9QF9819VlI9a4tzGuCbhG0ExK9o1U= golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= @@ -397,19 +403,19 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= +golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -428,22 +434,22 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= -golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= +golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -468,13 +474,13 @@ google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= -google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -485,8 +491,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/internal/framework/provider/appsv1/validating_admission_policy.go b/internal/framework/provider/appsv1/validating_admission_policy.go new file mode 100644 index 0000000000..ea2e446926 --- /dev/null +++ b/internal/framework/provider/appsv1/validating_admission_policy.go @@ -0,0 +1,50 @@ +package appsv1 + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-codegen-kubernetes/autocrud" + "github.com/hashicorp/terraform-plugin-framework/resource" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ resource.Resource = &ValidatingAdmissionPolicy{} +var _ resource.ResourceWithImportState = &ValidatingAdmissionPolicy{} +var _ resource.ResourceWithConfigure = &ValidatingAdmissionPolicy{} + +func NewValidatingAdmissionPolicy() resource.Resource { + return &ValidatingAdmissionPolicy{ + Kind: "ValidatingAdmissionPolicy", + APIVersion: "apps/v1", + } +} + +type ValidatingAdmissionPolicy struct { + APIVersion string + Kind string + + clientGetter autocrud.KubernetesClientGetter +} + +func (r *ValidatingAdmissionPolicy) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = "kubernetes_validating_admission_policy" +} + +func (r *ValidatingAdmissionPolicy) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + clientGetter, ok := req.ProviderData.(autocrud.KubernetesClientGetter) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected KubernetesClientGetter, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + return + } + + r.clientGetter = clientGetter +} diff --git a/internal/framework/provider/appsv1/validating_admission_policy_crud.go b/internal/framework/provider/appsv1/validating_admission_policy_crud.go new file mode 100644 index 0000000000..84b9093ba7 --- /dev/null +++ b/internal/framework/provider/appsv1/validating_admission_policy_crud.go @@ -0,0 +1,151 @@ +package appsv1 + +import ( + "context" + "time" + + "github.com/hashicorp/terraform-plugin-codegen-kubernetes/autocrud" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" +) + +func (r *ValidatingAdmissionPolicy) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var validatingAdmissionPolicyModel ValidatingAdmissionPolicyModel + + diag := req.Config.Get(ctx, &validatingAdmissionPolicyModel) + resp.Diagnostics.Append(diag...) + if diag.HasError() { + return + } + + defaultTimeout, err := time.ParseDuration("20m") + if err != nil { + resp.Diagnostics.AddError("Error parsing timeout", err.Error()) + return + } + timeout, diag := validatingAdmissionPolicyModel.Timeouts.Create(ctx, defaultTimeout) + resp.Diagnostics.Append(diag...) + if diag.HasError() { + return + } + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() + + err = autocrud.Create(ctx, r.clientGetter, r.APIVersion, r.Kind, &validatingAdmissionPolicyModel) + if err != nil { + resp.Diagnostics.AddError("Error creating resource", err.Error()) + return + } + + diags := resp.State.Set(ctx, &validatingAdmissionPolicyModel) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +func (r *ValidatingAdmissionPolicy) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var validatingAdmissionPolicyModel ValidatingAdmissionPolicyModel + + diag := req.State.Get(ctx, &validatingAdmissionPolicyModel) + resp.Diagnostics.Append(diag...) + if diag.HasError() { + return + } + + defaultTimeout, err := time.ParseDuration("20m") + if err != nil { + resp.Diagnostics.AddError("Error parsing timeout", err.Error()) + return + } + timeout, diag := validatingAdmissionPolicyModel.Timeouts.Read(ctx, defaultTimeout) + resp.Diagnostics.Append(diag...) + if diag.HasError() { + return + } + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() + + err = autocrud.Read(ctx, r.clientGetter, r.Kind, r.APIVersion, req, &validatingAdmissionPolicyModel) + if err != nil { + resp.Diagnostics.AddError("Error reading resource", err.Error()) + return + } + + diags := resp.State.Set(ctx, &validatingAdmissionPolicyModel) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +func (r *ValidatingAdmissionPolicy) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var validatingAdmissionPolicyModel ValidatingAdmissionPolicyModel + + diag := req.Config.Get(ctx, &validatingAdmissionPolicyModel) + resp.Diagnostics.Append(diag...) + if diag.HasError() { + return + } + + defaultTimeout, err := time.ParseDuration("20m") + if err != nil { + resp.Diagnostics.AddError("Error parsing timeout", err.Error()) + return + } + timeout, diag := validatingAdmissionPolicyModel.Timeouts.Update(ctx, defaultTimeout) + resp.Diagnostics.Append(diag...) + if diag.HasError() { + return + } + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() + + err = autocrud.Update(ctx, r.clientGetter, r.Kind, r.APIVersion, &validatingAdmissionPolicyModel) + if err != nil { + resp.Diagnostics.AddError("Error updating resource", err.Error()) + return + } + + diags := resp.State.Set(ctx, &validatingAdmissionPolicyModel) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +func (r *ValidatingAdmissionPolicy) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + waitForDeletion := false + + var validatingAdmissionPolicyModel ValidatingAdmissionPolicyModel + + diag := req.State.Get(ctx, &validatingAdmissionPolicyModel) + resp.Diagnostics.Append(diag...) + if diag.HasError() { + return + } + + defaultTimeout, err := time.ParseDuration("20m") + if err != nil { + resp.Diagnostics.AddError("Error parsing timeout", err.Error()) + return + } + timeout, diag := validatingAdmissionPolicyModel.Timeouts.Delete(ctx, defaultTimeout) + resp.Diagnostics.Append(diag...) + if diag.HasError() { + return + } + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() + + err = autocrud.Delete(ctx, r.clientGetter, r.Kind, r.APIVersion, req, waitForDeletion) + if err != nil { + resp.Diagnostics.AddError("Error deleting resource", err.Error()) + return + } + +} + +func (r *ValidatingAdmissionPolicy) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} diff --git a/internal/framework/provider/appsv1/validating_admission_policy_model.go b/internal/framework/provider/appsv1/validating_admission_policy_model.go new file mode 100644 index 0000000000..c048c490a7 --- /dev/null +++ b/internal/framework/provider/appsv1/validating_admission_policy_model.go @@ -0,0 +1,103 @@ +package appsv1 + +import ( + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +type ValidatingAdmissionPolicyModel struct { + Timeouts timeouts.Value `tfsdk:"timeouts"` + + ID types.String `tfsdk:"id" manifest:""` + + Metadata struct { + Annotations map[string]types.String `tfsdk:"annotations" manifest:"annotations"` + GenerateName types.String `tfsdk:"generate_name" manifest:"generateName"` + Generation types.Int64 `tfsdk:"generation" manifest:"generation"` + Labels map[string]types.String `tfsdk:"labels" manifest:"labels"` + Name types.String `tfsdk:"name" manifest:"name"` + Namespace types.String `tfsdk:"namespace" manifest:"namespace"` + ResourceVersion types.String `tfsdk:"resource_version" manifest:"resourceVersion"` + UID types.String `tfsdk:"uid" manifest:"uid"` + } `tfsdk:"metadata" manifest:"metadata"` + + Spec struct { + AuditAnnotations []struct { + Key types.String `tfsdk:"key" manifest:"key"` + ValueExpressions types.String `tfsdk:"value_expressions" manifest:"valueExpressions"` + } `tfsdk:"audit_annotations" manifest:"auditAnnotations"` + FailurePolicy types.String `tfsdk:"failure_policy" manifest:"failurePolicy"` + MatchConditions []struct { + Expression types.String `tfsdk:"expression" manifest:"expression"` + Name types.String `tfsdk:"Name" manifest:"name"` + } `tfsdk:"match_conditions" manifest:"matchConditions"` + MatchConstraints struct { + ExcludeResourceRules []struct { + APIGroups []types.String `tfsdk:"api_groups" manifest:"apiGroups"` + APIVersions []types.String `tfsdk:"api_versions" manifest:"apiVersions"` + Operations []types.String `tfsdk:"operations" manifest:"operations"` + ResourceNames []types.String `tfsdk:"resource_names" manifest:"resourceNames"` + Resources []types.String `tfsdk:"resources" manifest:"resources"` + Scope types.String `tfsdk:"scope" manifest:"scope"` + } `tfsdk:"exclude_resource_rules" manifest:"excludeResourceRules"` + MatchPolicy types.String `tfsdk:"match_policy" manifest:"matchPolicy"` + NamespaceSelector struct { + APIGroups []types.String `tfsdk:"api_groups" manifest:"apiGroups"` + APIVersions []types.String `tfsdk:"api_versions" manifest:"apiVersions"` + Operations []types.String `tfsdk:"operations" manifest:"operations"` + ResourceNames []types.String `tfsdk:"resource_names" manifest:"resourceNames"` + Resources []types.String `tfsdk:"resources" manifest:"resources"` + Scope types.String `tfsdk:"scope" manifest:"scope"` + } `tfsdk:"namespace_selector" manifest:"NamespaceSelector"` + ObjectSelector struct { + LabelSelector struct { + MatchExpressions []struct { + Key types.String `tfsdk:"key" manifest:"key"` + Operator types.String `tfsdk:"operator" manifest:"operator"` + Values []types.String `tfsdk:"values" manifest:"values"` + } `tfsdk:"match_expressions" manifest:"matchExpressions"` + MatchLabels map[string]types.String `tfsdk:"match_labels" manifest:"matchLabels"` + } `tfsdk:"label_selector" manifest:"labelSelector"` + } `tfsdk:"object_selector" manifest:"objectSelector"` + ResourceRules []struct { + APIGroups []types.String `tfsdk:"api_groups" manifest:"apiGroups"` + APIVersions []types.String `tfsdk:"api_versions" manifest:"apiVersions"` + Operations []types.String `tfsdk:"operations" manifest:"operations"` + ResourceNames []types.String `tfsdk:"resource_names" manifest:"resourceNames"` + Resources []types.String `tfsdk:"resources" manifest:"resources"` + Scope types.String `tfsdk:"scope" manifest:"scope"` + } `tfsdk:"resource_rules" manifest:"resourceRules"` + } `tfsdk:"match_constraints" manifest:"matchConstraints"` + ParamKind struct { + APIVersion types.String `tfsdk:"api_version" manifest:"apiVersion"` + Kind types.String `tfsdk:"kind" manifest:"kind"` + } `tfsdk:"param_kind" manifest:"paramKind"` + Validations []struct { + Expression types.String `tfsdk:"expression" manifest:"expression"` + Message types.String `tfsdk:"message" manifest:"message"` + MessageExpression types.String `tfsdk:"message_expression" manifest:"messageExpression"` + Reason types.String `tfsdk:"reason" manifest:"reason"` + } + Variable []struct { + Expression types.String `tfsdk:"expression" manifest:"expression"` + Name types.String `tfsdk:"name" manifest:"name"` + } + Status struct { + Conditions []struct { + LastTransitionTime types.String `tfsdk:"last_transition_time" manifest:"lastTransitionTime"` + Message types.String `tfsdk:"message" manifest:"message"` + ObservedGeneration types.Int64 `tfsdk:"observed_generation" manifest:"observedGeneration"` + Reason types.String `tfsdk:"reason" manifest:"reason"` + Status types.String `tfsdk:"status" manifest:"status"` + Type types.String `tfsdk:"type" manifest:"type"` + } `tfsdk:"conditions" manifest:"conditions"` + ObservedGeneration types.Int64 `tfsdk:"observed_generation" manifest:"observedGeneration"` + TypeChecking struct { + ExpressionWarning []struct { + FieldRef types.String `tfsdk:"field_ref" manifest:"fieldRef"` + Warning types.String `tfsdk:"warning" manifest:"warning"` + } `tfsdk:"expression_warning" manifest:"expressionWarning"` + } `tfsdk:"type_checking" manifest:"typeChecking"` + } + } +} diff --git a/internal/framework/provider/appsv1/validating_admission_policy_schema.go b/internal/framework/provider/appsv1/validating_admission_policy_schema.go new file mode 100644 index 0000000000..7d2e10e1ea --- /dev/null +++ b/internal/framework/provider/appsv1/validating_admission_policy_schema.go @@ -0,0 +1,378 @@ +package appsv1 + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func (r *ValidatingAdmissionPolicy) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: `Validating Admission Policy Resource`, + Blocks: map[string]schema.Block{ + "timeouts": timeouts.BlockAll(ctx), + }, + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: `The unique ID for this terraform resource`, + Optional: true, + Computed: true, + }, + "metadata": schema.SingleNestedAttribute{ + MarkdownDescription: `Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata`, + Optional: true, + Attributes: map[string]schema.Attribute{ + "annotations": schema.MapAttribute{ + MarkdownDescription: `Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata. They are not queryable and should be preserved when modifying objects. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations`, + ElementType: types.StringType, + Optional: true, + }, + "generate_name": schema.StringAttribute{ + MarkdownDescription: `GenerateName is an optional prefix, used by the server, to generate a unique name ONLY IF the Name field has not been provided. If this field is used, the name returned to the client will be different than the name passed. This value will also be combined with a unique suffix. The provided value has the same validation rules as the Name field, and may be truncated by the length of the suffix required to make the value unique on the server. + +If this field is specified and the generated name exists, the server will return a 409. + +Applied only if Name is not specified. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#idempotency`, + Optional: true, + }, + "generation": schema.Int64Attribute{ + MarkdownDescription: `A sequence number representing a specific generation of the desired state. Populated by the system. Read-only.`, + Optional: true, + Computed: true, + }, + "labels": schema.MapAttribute{ + MarkdownDescription: `Map of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and services. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels`, + ElementType: types.StringType, + Optional: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: `Name must be unique within a namespace. Is required when creating resources, although some resources may allow a client to request the generation of an appropriate name automatically. Name is primarily intended for creation idempotence and configuration definition. Cannot be updated. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#names`, + Optional: true, + Computed: true, + }, + "namespace": schema.StringAttribute{ + MarkdownDescription: `Namespace defines the space within which each name must be unique. An empty namespace is equivalent to the "default" namespace, but "default" is the canonical representation. Not all objects are required to be scoped to a namespace - the value of this field for those objects will be empty. + +Must be a DNS_LABEL. Cannot be updated. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces`, + Optional: true, + }, + "resource_version": schema.StringAttribute{ + MarkdownDescription: `An opaque value that represents the internal version of this object that can be used by clients to determine when objects have changed. May be used for optimistic concurrency, change detection, and the watch operation on a resource or set of resources. Clients must treat these values as opaque and passed unmodified back to the server. They may only be valid for a particular resource or set of resources. + +Populated by the system. Read-only. Value must be treated as opaque by clients and . More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency`, + Optional: true, + Computed: true, + }, + "uid": schema.StringAttribute{ + MarkdownDescription: `UID is the unique in time and space value for this object. It is typically generated by the server on successful creation of a resource and is not allowed to change on PUT operations. + +Populated by the system. Read-only. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#uids`, + Optional: true, + Computed: true, + }, + }, + }, + "spec": schema.SingleNestedAttribute{ + MarkdownDescription: "Rule defining a set of permissions for the role", + Required: true, + Attributes: map[string]schema.Attribute{ + "audit_annotations": schema.ListNestedAttribute{ + MarkdownDescription: "auditAnnotations contains CEL expressions which are used to produce audit annotations for the audit event of the API request.", + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: auditAnnotationsFields(), + }, + }, + "failure_policy": schema.StringAttribute{ + MarkdownDescription: "failurePolicy defines how to handle failures for the admission policy.", + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf("Fail", "Ignore"), + }, + }, + "match_conditions": schema.ListNestedAttribute{ + MarkdownDescription: "MatchConditions is a list of conditions that must be met for a request to be validated.", + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: matchConditionsFields(), + }, + }, + "match_constraints": schema.SingleNestedAttribute{ + MarkdownDescription: "MatchConstraints specifies what resources this policy is designed to validate.", + Required: true, + Attributes: matchConstraintsFields(), + }, + "param_kind": schema.SingleNestedAttribute{ + MarkdownDescription: "ParamKind specifies the kind of resources used to parameterize this policy", + Optional: true, + Attributes: paramKindFields(), + }, + "validations": schema.ListNestedAttribute{ + MarkdownDescription: "Validations contain CEL expressions which is used to apply the validation.", + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: validationFields(), + }, + }, + "variable": schema.ListNestedAttribute{ + MarkdownDescription: "Variables contain definitions of variables that can be used in composition of other expressions.", + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: variableFields(), + }, + }, + }, + }, + "status": schema.SingleNestedAttribute{ + MarkdownDescription: `The status of the ValidatingAdmissionPolicy, including warnings that are useful to determine if the policy behaves in the expected way.`, + Optional: true, + Attributes: map[string]schema.Attribute{ + "conditions": schema.ListNestedAttribute{ + MarkdownDescription: `The conditions represent the latest available observations of a policy's current state.`, + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "last_transition_time": schema.StringAttribute{ + MarkdownDescription: `Last time the condition transitioned from one status to another.`, + Optional: true, + }, + "message": schema.StringAttribute{ + MarkdownDescription: `A human readable message indicating details about the transition.`, + Optional: true, + }, + "observed_generation": schema.Int64Attribute{ + MarkdownDescription: `The generation observed by the deployment controller.`, + Optional: true, + }, + "reason": schema.StringAttribute{ + MarkdownDescription: `The reason for the condition's last transition.`, + Optional: true, + }, + "status": schema.StringAttribute{ + MarkdownDescription: `Status of the condition, one of True, False, Unknown.`, + Optional: true, + }, + "type": schema.StringAttribute{ + MarkdownDescription: `Type of deployment condition.`, + Optional: true, + }, + }, + }, + }, + "observed_generation": schema.Int64Attribute{ + MarkdownDescription: `The generation observed by the deployment controller.`, + Optional: true, + }, + "type_checking": schema.SingleNestedAttribute{ + MarkdownDescription: `The results of type checking for each expression. Presence of this field indicates the completion of the type checking.`, + Optional: true, + Attributes: map[string]schema.Attribute{ + "expression_warning": schema.ListNestedAttribute{ + MarkdownDescription: `The type checking warnings for each expression.`, + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "field_ref": schema.StringAttribute{ + Description: "The path to the field that refers the expression. For example, the reference to the expression of the first item of validations is \"spec.validations[0].expression\"", + Optional: true, + }, + "warning": schema.StringAttribute{ + MarkdownDescription: `The content of type checking information in a human-readable form. Each line of the warning contains the type that the expression is checked against, followed by the type check error from the compiler.`, + Optional: true, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func auditAnnotationsFields() map[string]schema.Attribute { + return map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Description: "key specifies the audit annotation key.", + Required: true, + }, + "value_expressions": schema.StringAttribute{ + Description: "valueExpression represents the expression which is evaluated by CEL to produce an audit annotation value.", + Required: true, + }, + } +} + +func matchConditionsFields() map[string]schema.Attribute { + return map[string]schema.Attribute{ + "expression": schema.StringAttribute{ + Description: "Expression represents the expression which will be evaluated by CEL.", + Required: true, + }, + "name": schema.StringAttribute{ + Description: "Name is an identifier for this match condition, used for strategic merging of MatchConditions, as well as providing an identifier for logging purposes.", + Required: true, + }, + } +} + +func matchConstraintsFields() map[string]schema.Attribute { + return map[string]schema.Attribute{ + "exclude_resource_rules": schema.ListNestedAttribute{ + Description: "ExcludeResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy should not care about.", + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: namedRuleWithOperationsFields(), + }, + }, + "match_policy": schema.StringAttribute{ + Optional: true, + Description: "matchPolicy defines how the MatchResources list is used to match incoming requests. Allowed values are Exact or Equivalent.", + Validators: []validator.String{ + stringvalidator.OneOf("Exact", "Equivalent"), + }, + }, + "namespace_selector": schema.SingleNestedAttribute{ + Description: "NamespaceSelector decides whether to run the admission control policy on an object based on whether the namespace for that object matches the selector.", + Optional: true, + Attributes: namedRuleWithOperationsFields(), + }, + "object_selector": schema.SingleNestedAttribute{ + Description: "ObjectSelector decides whether to run the validation based on if the object has matching labels.", + Optional: true, + Attributes: labelSelectorFields(), + }, + "resource_rules": schema.ListNestedAttribute{ + Description: "ResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy matches.", + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: namedRuleWithOperationsFields(), + }, + }, + } +} + +func paramKindFields() map[string]schema.Attribute { + return map[string]schema.Attribute{ + "api_version": schema.StringAttribute{ + Description: "APIVersion is the API group version the resources belong to. In format of \"group/version\"", + Required: true, + }, + "kind": schema.StringAttribute{ + Description: "Kind is the API kind the resources belong to.", + Required: true, + }, + } +} + +func validationFields() map[string]schema.Attribute { + return map[string]schema.Attribute{ + "expression": schema.StringAttribute{ + Description: "Expression represents the expression which will be evaluated by CEL.", + Required: true, + }, + "message": schema.StringAttribute{ + Description: "Message represents the message displayed when validation fails.", + Required: true, + }, + "message_expression": schema.StringAttribute{ + Description: "Message Expression declares a CEL expression that evaluates to the validation failure message that is returned when this rule fails.", + Optional: true, + }, + "reason": schema.StringAttribute{ + Description: "Reason represents a machine-readable description of why this validation failed.", + Optional: true, + }, + } +} + +func variableFields() map[string]schema.Attribute { + return map[string]schema.Attribute{ + "expression": schema.StringAttribute{ + Description: "Expression is the expression that will be evaluated as the value of the variable.", + Optional: true, + }, + "name": schema.StringAttribute{ + Description: "Name is the name of the variable.", + Optional: true, + }, + } +} + +func namedRuleWithOperationsFields() map[string]schema.Attribute { + return map[string]schema.Attribute{ + "api_groups": schema.ListAttribute{ + Description: "APIGroups is the API groups the resources belong to. '\\*' is all groups. If '\\*' is present, the length of the slice must be one.", + Required: true, + ElementType: types.StringType, + }, + "api_versions": schema.ListAttribute{ + Description: "APIVersions is the API versions the resources belong to. '\\*' is all versions. If '\\*' is present, the length of the slice must be one. Required.", + Required: true, + ElementType: types.StringType, + }, + "operations": schema.ListAttribute{ + Description: "Operations is the operations the admission hook cares about - CREATE, UPDATE, DELETE, CONNECT or * for all of those operations and any future admission operations that are added.", + Required: true, + ElementType: types.StringType, + }, + "resource_names": schema.ListAttribute{ + Description: "ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed.", + Optional: true, + ElementType: types.StringType, + }, + "resources": schema.ListAttribute{ + Description: "Resources is a list of resources this rule applies to.", + Required: true, + ElementType: types.StringType, + }, + "scope": schema.StringAttribute{ + Description: "scope specifies the scope of this rule.", + Optional: true, + }, + } +} + +func labelSelectorFields() map[string]schema.Attribute { + return map[string]schema.Attribute{ + "label_selector": schema.SingleNestedAttribute{ + MarkdownDescription: `A label query over a set of resources, in this case pods.`, + Optional: true, + Attributes: map[string]schema.Attribute{ + "match_expressions": schema.ListNestedAttribute{ + MarkdownDescription: `matchExpressions is a list of label selector requirements. The requirements are ANDed.`, + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + MarkdownDescription: `key is the label key that the selector applies to.`, + Optional: true, + }, + "operator": schema.StringAttribute{ + MarkdownDescription: `operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist.`, + Optional: true, + }, + "values": schema.ListAttribute{ + MarkdownDescription: `values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch.`, + ElementType: types.StringType, + Optional: true, + }, + }, + }, + }, + "match_labels": schema.MapAttribute{ + MarkdownDescription: `matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed.`, + ElementType: types.StringType, + Optional: true, + }, + }, + }, + } + +} diff --git a/internal/framework/provider/provider.go b/internal/framework/provider/provider.go index f953b38875..07ca11bdea 100644 --- a/internal/framework/provider/provider.go +++ b/internal/framework/provider/provider.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/provider/schema" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" + appsv1 "github.com/hashicorp/terraform-provider-kubernetes/internal/framework/provider/appsv1" pfunctions "github.com/hashicorp/terraform-provider-kubernetes/internal/framework/provider/functions" ) @@ -185,7 +186,9 @@ func (p *KubernetesProvider) Schema(ctx context.Context, req provider.SchemaRequ } func (p *KubernetesProvider) Resources(ctx context.Context) []func() resource.Resource { - return []func() resource.Resource{} + return []func() resource.Resource{ + appsv1.NewValidatingAdmissionPolicy, + } } func (p *KubernetesProvider) DataSources(ctx context.Context) []func() datasource.DataSource {