From 81dc6d8f85e6649b5e97977f23de3423b8e14d65 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 9 Nov 2023 00:27:09 +0000 Subject: [PATCH 01/43] deps: bump golang.org/x/crypto from 0.14.0 to 0.15.0 Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.15.0. - [Commits](https://github.com/golang/crypto/compare/v0.14.0...v0.15.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 6 +++--- go.sum | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 28a966c5..02bff1bd 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/jeremmfr/go-netconf v0.4.14 github.com/jeremmfr/go-utils v0.10.0 github.com/jeremmfr/junosdecode v1.1.1 - golang.org/x/crypto v0.14.0 + golang.org/x/crypto v0.15.0 ) require ( @@ -56,8 +56,8 @@ require ( golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/sys v0.14.0 // indirect + golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect google.golang.org/grpc v1.57.1 // indirect diff --git a/go.sum b/go.sum index 314f7103..4743386c 100644 --- a/go.sum +++ b/go.sum @@ -140,8 +140,9 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= +golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= 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= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -178,16 +179,17 @@ golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.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.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8= 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= @@ -196,8 +198,9 @@ golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= From 93ffd0abc918bf38a2f3c0f346d397d10e6f8d7e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Nov 2023 00:19:39 +0000 Subject: [PATCH 02/43] deps: bump github.com/hashicorp/terraform-plugin-go Bumps [github.com/hashicorp/terraform-plugin-go](https://github.com/hashicorp/terraform-plugin-go) from 0.19.0 to 0.19.1. - [Release notes](https://github.com/hashicorp/terraform-plugin-go/releases) - [Changelog](https://github.com/hashicorp/terraform-plugin-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/terraform-plugin-go/compare/v0.19.0...v0.19.1) --- updated-dependencies: - dependency-name: github.com/hashicorp/terraform-plugin-go dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 12 ++++++------ go.sum | 26 ++++++++++++-------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 28a966c5..15070564 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/terraform-plugin-framework v1.4.2 github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 - github.com/hashicorp/terraform-plugin-go v0.19.0 + github.com/hashicorp/terraform-plugin-go v0.19.1 github.com/hashicorp/terraform-plugin-mux v0.12.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0 github.com/hashicorp/terraform-plugin-testing v1.5.1 @@ -29,7 +29,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-hclog v1.5.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/hashicorp/go-plugin v1.5.1 // indirect + github.com/hashicorp/go-plugin v1.5.2 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/go-version v1.6.0 // indirect github.com/hashicorp/hc-install v0.6.0 // indirect @@ -38,7 +38,7 @@ require ( github.com/hashicorp/terraform-exec v0.19.0 // indirect github.com/hashicorp/terraform-json v0.17.1 // indirect github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect - github.com/hashicorp/terraform-registry-address v0.2.2 // indirect + github.com/hashicorp/terraform-registry-address v0.2.3 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect github.com/mattn/go-colorable v0.1.12 // indirect @@ -50,7 +50,7 @@ require ( github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/oklog/run v1.0.0 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect - github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect + github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/zclconf/go-cty v1.14.0 // indirect golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect @@ -59,8 +59,8 @@ require ( golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect - google.golang.org/grpc v1.57.1 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect + google.golang.org/grpc v1.59.0 // indirect google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/go.sum b/go.sum index 314f7103..d0752d91 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+ github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= 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.5.1 h1:oGm7cWBaYIp3lJpx1RUEfLWophprE2EV/KUeqBYo+6k= -github.com/hashicorp/go-plugin v1.5.1/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= +github.com/hashicorp/go-plugin v1.5.2 h1:aWv8eimFqWlsEiMrYZdPYl+FdHaBJSN4AWwGWfT1G2Y= +github.com/hashicorp/go-plugin v1.5.2/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= 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= @@ -67,16 +67,16 @@ github.com/hashicorp/terraform-plugin-framework v1.4.2 h1:P7a7VP1GZbjc4rv921Xy5O github.com/hashicorp/terraform-plugin-framework v1.4.2/go.mod h1:GWl3InPFZi2wVQmdVnINPKys09s9mLmTZr95/ngLnbY= github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc= github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg= -github.com/hashicorp/terraform-plugin-go v0.19.0 h1:BuZx/6Cp+lkmiG0cOBk6Zps0Cb2tmqQpDM3iAtnhDQU= -github.com/hashicorp/terraform-plugin-go v0.19.0/go.mod h1:EhRSkEPNoylLQntYsk5KrDHTZJh9HQoumZXbOGOXmec= +github.com/hashicorp/terraform-plugin-go v0.19.1 h1:lf/jTGTeELcz5IIbn/94mJdmnTjRYm6S6ct/JqCSr50= +github.com/hashicorp/terraform-plugin-go v0.19.1/go.mod h1:5NMIS+DXkfacX6o5HCpswda5yjkSYfKzn1Nfl9l+qRs= 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.12.0 h1:TJlmeslQ11WlQtIFAfth0vXx+gSNgvMEng2Rn9z3WZY= github.com/hashicorp/terraform-plugin-mux v0.12.0/go.mod h1:8MR0AgmV+Q03DIjyrAKxXyYlq2EUnYBQP8gxAAA0zeM= github.com/hashicorp/terraform-plugin-testing v1.5.1 h1:T4aQh9JAhmWo4+t1A7x+rnxAJHCDIYW9kXyo4sVO92c= github.com/hashicorp/terraform-plugin-testing v1.5.1/go.mod h1:dg8clO6K59rZ8w9EshBmDp1CxTIPu3yA4iaDpX1h5u0= -github.com/hashicorp/terraform-registry-address v0.2.2 h1:lPQBg403El8PPicg/qONZJDC6YlgCVbWDtNmmZKtBno= -github.com/hashicorp/terraform-registry-address v0.2.2/go.mod h1:LtwNbCihUoUZ3RYriyS2wF/lGPB6gF9ICLRtuDk7hSo= +github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= +github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM= github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= @@ -122,14 +122,13 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJCpM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= -github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= -github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= +github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8= +github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= @@ -208,10 +207,10 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 h1:0nDDozoAU19Qb2HwhXadU8OcsiO/09cnTqhUtq2MEOM= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= -google.golang.org/grpc v1.57.1 h1:upNTNqv0ES+2ZOOqACwVtS3Il8M12/+Hz41RCPzAjQg= -google.golang.org/grpc v1.57.1/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= +google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= +google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= 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.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= @@ -220,6 +219,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 27e555fd46dbe810067903e5c44434dab3b87d6a Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Tue, 21 Nov 2023 08:42:03 +0100 Subject: [PATCH 03/43] add junos_forwardingoptions_storm_control_profile resource Partial fix #574 --- .changes/issue-574.md | 4 + ...forwardingoptions_storm_control_profile.md | 63 +++ internal/providerfwk/provider.go | 1 + ...forwardingoptions_storm_control_profile.go | 529 ++++++++++++++++++ ...rdingoptions_storm_control_profile_test.go | 37 ++ .../1/main.tf | 11 + .../3/main.tf | 7 + .../4/main.tf | 6 + .../5/main.tf | 4 + 9 files changed, 662 insertions(+) create mode 100644 .changes/issue-574.md create mode 100644 docs/resources/forwardingoptions_storm_control_profile.md create mode 100644 internal/providerfwk/resource_forwardingoptions_storm_control_profile.go create mode 100644 internal/providerfwk/resource_forwardingoptions_storm_control_profile_test.go create mode 100644 internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/1/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/3/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/4/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/5/main.tf diff --git a/.changes/issue-574.md b/.changes/issue-574.md new file mode 100644 index 00000000..7995d5b9 --- /dev/null +++ b/.changes/issue-574.md @@ -0,0 +1,4 @@ + +FEATURES: + +* add **junos_forwardingoptions_storm_control_profile** resource (Partial fix [#574](https://github.com/jeremmfr/terraform-provider-junos/issues/574)) diff --git a/docs/resources/forwardingoptions_storm_control_profile.md b/docs/resources/forwardingoptions_storm_control_profile.md new file mode 100644 index 00000000..01381fd6 --- /dev/null +++ b/docs/resources/forwardingoptions_storm_control_profile.md @@ -0,0 +1,63 @@ +--- +page_title: "Junos: junos_forwardingoptions_storm_control_profile" +--- + +# junos_forwardingoptions_storm_control_profile + +Provides a forwarding-options storm-control-profile resource. + +## Example Usage + +```hcl +# Add a forwarding-options storm-control-profile +resource "junos_forwardingoptions_storm_control_profile" "demo" { + name = "demo" + action_shutdown = true + all { + bandwidth_percentage = 80 + } +} +``` + +## Argument Reference + +The following arguments are supported: + +- **name** (Required, String, Forces new resource) + Storm control profile name. +- **all** (Required, Block) + For all BUM traffic. + - **bandwidth_level** (Optional, Number) + Link bandwidth (100..100000000 kbps). + - **bandwidth_percentage** (Optional, Number) + Percentage of link bandwidth (1..100). + - **burst_size** (Optional, Number) + Burst size (1500..100000000 bytes). + - **no_broadcast** (Optional, Boolean) + Disable broadcast storm control. + - **no_multicast** (Optional, Boolean) + Disable multicast storm control. + - **no_registered_multicast** (Optional, Boolean) + Disable registered multicast storm control. + - **no_unknown_unicast** (Optional, Boolean) + Disable unknown unicast storm control. + - **no_unregistered_multicast** (Optional, Boolean) + Disable unregistered multicast storm control. +- **action_shutdown** (Optional, Boolean) + Disable port for excessive storm control errors. + +## Attributes Reference + +The following attributes are exported: + +- **id** (String) + An identifier for the resource with format ``. + +## Import + +Junos forwarding-options storm-control-profile can be imported using an id made up of +``, e.g. + +```shell +$ terraform import junos_forwardingoptions_storm_control_profile.demo demo +``` diff --git a/internal/providerfwk/provider.go b/internal/providerfwk/provider.go index 4e94dae8..094c8e94 100644 --- a/internal/providerfwk/provider.go +++ b/internal/providerfwk/provider.go @@ -211,6 +211,7 @@ func (p *junosProvider) Resources(_ context.Context) []func() resource.Resource newFirewallPolicerResource, newForwardingoptionsSamplingResource, newForwardingoptionsSamplingInstanceResource, + newForwardingoptionsStormControlProfileResource, newGenerateRouteResource, newInterfaceLogicalResource, newInterfacePhysicalDisableResource, diff --git a/internal/providerfwk/resource_forwardingoptions_storm_control_profile.go b/internal/providerfwk/resource_forwardingoptions_storm_control_profile.go new file mode 100644 index 00000000..695e3fcc --- /dev/null +++ b/internal/providerfwk/resource_forwardingoptions_storm_control_profile.go @@ -0,0 +1,529 @@ +package providerfwk + +import ( + "context" + "strings" + + "github.com/jeremmfr/terraform-provider-junos/internal/junos" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdata" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdiag" + "github.com/jeremmfr/terraform-provider-junos/internal/tfplanmodifier" + "github.com/jeremmfr/terraform-provider-junos/internal/tfvalidator" + "github.com/jeremmfr/terraform-provider-junos/internal/utils" + + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + balt "github.com/jeremmfr/go-utils/basicalter" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ resource.Resource = &forwardingoptionsStormControlProfile{} + _ resource.ResourceWithConfigure = &forwardingoptionsStormControlProfile{} + _ resource.ResourceWithValidateConfig = &forwardingoptionsStormControlProfile{} + _ resource.ResourceWithImportState = &forwardingoptionsStormControlProfile{} +) + +type forwardingoptionsStormControlProfile struct { + client *junos.Client +} + +func newForwardingoptionsStormControlProfileResource() resource.Resource { + return &forwardingoptionsStormControlProfile{} +} + +func (rsc *forwardingoptionsStormControlProfile) typeName() string { + return providerName + "_forwardingoptions_storm_control_profile" +} + +func (rsc *forwardingoptionsStormControlProfile) junosName() string { + return "forwarding-options storm-control-profile" +} + +func (rsc *forwardingoptionsStormControlProfile) junosClient() *junos.Client { + return rsc.client +} + +func (rsc *forwardingoptionsStormControlProfile) Metadata( + _ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse, +) { + resp.TypeName = rsc.typeName() +} + +func (rsc *forwardingoptionsStormControlProfile) Configure( + ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse, +) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + client, ok := req.ProviderData.(*junos.Client) + if !ok { + unexpectedResourceConfigureType(ctx, req, resp) + + return + } + rsc.client = client +} + +func (rsc *forwardingoptionsStormControlProfile) Schema( + _ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse, +) { + resp.Schema = schema.Schema{ + Description: defaultResourceSchemaDescription(rsc), + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "An identifier for the resource with format ``.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "name": schema.StringAttribute{ + Required: true, + Description: "Storm control profile name.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 127), + tfvalidator.StringDoubleQuoteExclusion(), + }, + }, + "action_shutdown": schema.BoolAttribute{ + Optional: true, + Description: "Disable port for excessive storm control errors.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + }, + Blocks: map[string]schema.Block{ + "all": schema.SingleNestedBlock{ + Description: "For all BUM traffic.", + Attributes: map[string]schema.Attribute{ + "bandwidth_level": schema.Int64Attribute{ + Optional: true, + Description: "Link bandwidth (kbps)", + Validators: []validator.Int64{ + int64validator.Between(100, 100000000), + }, + }, + "bandwidth_percentage": schema.Int64Attribute{ + Optional: true, + Description: "Percentage of link bandwidth.", + Validators: []validator.Int64{ + int64validator.Between(1, 100), + }, + }, + "burst_size": schema.Int64Attribute{ + Optional: true, + Description: "Burst size (bytes).", + Validators: []validator.Int64{ + int64validator.Between(1500, 100000000), + }, + }, + "no_broadcast": schema.BoolAttribute{ + Optional: true, + Description: "Disable broadcast storm control.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "no_multicast": schema.BoolAttribute{ + Optional: true, + Description: "Disable multicast storm control.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "no_registered_multicast": schema.BoolAttribute{ + Optional: true, + Description: "Disable registered multicast storm control.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "no_unknown_unicast": schema.BoolAttribute{ + Optional: true, + Description: "Disable unknown unicast storm control.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "no_unregistered_multicast": schema.BoolAttribute{ + Optional: true, + Description: "Disable unregistered multicast storm control.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + }, + PlanModifiers: []planmodifier.Object{ + tfplanmodifier.BlockRemoveNull(), + }, + }, + }, + } +} + +type forwardingoptionsStormControlProfileData struct { + ActionShutdown types.Bool `tfsdk:"action_shutdown"` + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + All *forwardingoptionsStormControlProfileBlockAll `tfsdk:"all"` +} + +type forwardingoptionsStormControlProfileBlockAll struct { + NoBroadcast types.Bool `tfsdk:"no_broadcast"` + NoMulticast types.Bool `tfsdk:"no_multicast"` + NoRegisteredMulticast types.Bool `tfsdk:"no_registered_multicast"` + NoUnknownUnicast types.Bool `tfsdk:"no_unknown_unicast"` + NoUnregisteredMulticast types.Bool `tfsdk:"no_unregistered_multicast"` + BandwidthLevel types.Int64 `tfsdk:"bandwidth_level"` + BandwidthPercentage types.Int64 `tfsdk:"bandwidth_percentage"` + BurstSize types.Int64 `tfsdk:"burst_size"` +} + +func (rsc *forwardingoptionsStormControlProfile) ValidateConfig( + ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse, +) { + var config forwardingoptionsStormControlProfileData + resp.Diagnostics.Append(req.Config.Get(ctx, &config)...) + if resp.Diagnostics.HasError() { + return + } + + if config.All == nil { + resp.Diagnostics.AddAttributeError( + path.Root("all"), + tfdiag.MissingConfigErrSummary, + "all block must be specified", + ) + } else { + if !config.All.BandwidthLevel.IsNull() && + !config.All.BandwidthPercentage.IsNull() { + resp.Diagnostics.AddAttributeError( + path.Root("all").AtName("bandwidth_level"), + tfdiag.ConflictConfigErrSummary, + "bandwidth_level and bandwidth_percentage cannot be configured together"+ + " in all block", + ) + } + if !config.All.NoMulticast.IsNull() { + if !config.All.NoRegisteredMulticast.IsNull() { + resp.Diagnostics.AddAttributeError( + path.Root("all").AtName("no_multicast"), + tfdiag.ConflictConfigErrSummary, + "no_multicast and no_registered_multicast cannot be configured together"+ + " in all block", + ) + } + if !config.All.NoUnregisteredMulticast.IsNull() { + resp.Diagnostics.AddAttributeError( + path.Root("all").AtName("no_multicast"), + tfdiag.ConflictConfigErrSummary, + "no_multicast and no_unregistered_multicast cannot be configured together"+ + " in all block", + ) + } + } else if !config.All.NoRegisteredMulticast.IsNull() && + !config.All.NoUnregisteredMulticast.IsNull() { + resp.Diagnostics.AddAttributeError( + path.Root("all").AtName("no_registered_multicast"), + tfdiag.ConflictConfigErrSummary, + "no_registered_multicast and no_unregistered_multicast cannot be configured together"+ + " in all block", + ) + } + } +} + +func (rsc *forwardingoptionsStormControlProfile) Create( + ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse, +) { + var plan forwardingoptionsStormControlProfileData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + if plan.Name.ValueString() == "" { + resp.Diagnostics.AddAttributeError( + path.Root("name"), + "Empty Name", + defaultResourceCouldNotCreateWithEmptyMessage(rsc, "name"), + ) + + return + } + + defaultResourceCreate( + ctx, + rsc, + func(fnCtx context.Context, junSess *junos.Session) bool { + profileExists, err := checkForwardingoptionsStormControlProfileExists( + fnCtx, + plan.Name.ValueString(), + junSess, + ) + if err != nil { + resp.Diagnostics.AddError(tfdiag.PreCheckErrSummary, err.Error()) + + return false + } + if profileExists { + resp.Diagnostics.AddError( + tfdiag.DuplicateConfigErrSummary, + defaultResourceAlreadyExistsMessage(rsc, plan.Name), + ) + + return false + } + + return true + }, + func(fnCtx context.Context, junSess *junos.Session) bool { + profileExists, err := checkForwardingoptionsStormControlProfileExists( + fnCtx, + plan.Name.ValueString(), + junSess, + ) + if err != nil { + resp.Diagnostics.AddError(tfdiag.PostCheckErrSummary, err.Error()) + + return false + } + if !profileExists { + resp.Diagnostics.AddError( + tfdiag.NotFoundErrSummary, + defaultResourceDoesNotExistsAfterCommitMessage(rsc, plan.Name), + ) + + return false + } + + return true + }, + &plan, + resp, + ) +} + +func (rsc *forwardingoptionsStormControlProfile) Read( + ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse, +) { + var state, data forwardingoptionsStormControlProfileData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + var _ resourceDataReadFrom1String = &data + defaultResourceRead( + ctx, + rsc, + []string{ + state.Name.ValueString(), + }, + &data, + nil, + resp, + ) +} + +func (rsc *forwardingoptionsStormControlProfile) Update( + ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse, +) { + var plan, state forwardingoptionsStormControlProfileData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceUpdate( + ctx, + rsc, + &state, + &plan, + resp, + ) +} + +func (rsc *forwardingoptionsStormControlProfile) Delete( + ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse, +) { + var state forwardingoptionsStormControlProfileData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceDelete( + ctx, + rsc, + &state, + resp, + ) +} + +func (rsc *forwardingoptionsStormControlProfile) ImportState( + ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse, +) { + var data forwardingoptionsStormControlProfileData + + var _ resourceDataReadFrom1String = &data + defaultResourceImportState( + ctx, + rsc, + &data, + req, + resp, + defaultResourceImportDontFindIDStrMessage(rsc, req.ID, "name"), + ) +} + +func checkForwardingoptionsStormControlProfileExists( + _ context.Context, name string, junSess *junos.Session, +) ( + _ bool, err error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "forwarding-options storm-control-profiles \"" + name + "\"" + junos.PipeDisplaySet) + if err != nil { + return false, err + } + if showConfig == junos.EmptyW { + return false, nil + } + + return true, nil +} + +func (rscData *forwardingoptionsStormControlProfileData) fillID() { + rscData.ID = types.StringValue(rscData.Name.ValueString()) +} + +func (rscData *forwardingoptionsStormControlProfileData) nullID() bool { + return rscData.ID.IsNull() +} + +func (rscData *forwardingoptionsStormControlProfileData) set( + _ context.Context, junSess *junos.Session, +) ( + path.Path, error, +) { + configSet := make([]string, 0) + setPrefix := "set forwarding-options storm-control-profiles \"" + rscData.Name.ValueString() + "\" " + + if rscData.ActionShutdown.ValueBool() { + configSet = append(configSet, setPrefix+"action-shutdown") + } + if rscData.All != nil { + configSet = append(configSet, setPrefix+"all") + + if !rscData.All.BandwidthLevel.IsNull() { + configSet = append(configSet, setPrefix+"all bandwidth-level "+ + utils.ConvI64toa(rscData.All.BandwidthLevel.ValueInt64())) + } + if !rscData.All.BandwidthPercentage.IsNull() { + configSet = append(configSet, setPrefix+"all bandwidth-percentage "+ + utils.ConvI64toa(rscData.All.BandwidthPercentage.ValueInt64())) + } + if !rscData.All.BurstSize.IsNull() { + configSet = append(configSet, setPrefix+"all burst-size "+ + utils.ConvI64toa(rscData.All.BurstSize.ValueInt64())) + } + if rscData.All.NoBroadcast.ValueBool() { + configSet = append(configSet, setPrefix+"all no-broadcast") + } + if rscData.All.NoMulticast.ValueBool() { + configSet = append(configSet, setPrefix+"all no-multicast") + } + if rscData.All.NoRegisteredMulticast.ValueBool() { + configSet = append(configSet, setPrefix+"all no-registered-multicast") + } + if rscData.All.NoUnknownUnicast.ValueBool() { + configSet = append(configSet, setPrefix+"all no-unknown-unicast") + } + if rscData.All.NoUnregisteredMulticast.ValueBool() { + configSet = append(configSet, setPrefix+"all no-unregistered-multicast") + } + } + + return path.Empty(), junSess.ConfigSet(configSet) +} + +func (rscData *forwardingoptionsStormControlProfileData) read( + _ context.Context, name string, junSess *junos.Session, +) ( + err error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "forwarding-options storm-control-profiles \"" + name + "\"" + junos.PipeDisplaySetRelative) + if err != nil { + return err + } + if showConfig != junos.EmptyW { + rscData.Name = types.StringValue(name) + rscData.fillID() + for _, item := range strings.Split(showConfig, "\n") { + if strings.Contains(item, junos.XMLStartTagConfigOut) { + continue + } + if strings.Contains(item, junos.XMLEndTagConfigOut) { + break + } + itemTrim := strings.TrimPrefix(item, junos.SetLS) + switch { + case itemTrim == "action-shutdown": + rscData.ActionShutdown = types.BoolValue(true) + case balt.CutPrefixInString(&itemTrim, "all"): + if rscData.All == nil { + rscData.All = &forwardingoptionsStormControlProfileBlockAll{} + } + var err error + switch { + case balt.CutPrefixInString(&itemTrim, " bandwidth-level "): + rscData.All.BandwidthLevel, err = tfdata.ConvAtoi64Value(itemTrim) + case balt.CutPrefixInString(&itemTrim, " bandwidth-percentage "): + rscData.All.BandwidthPercentage, err = tfdata.ConvAtoi64Value(itemTrim) + case balt.CutPrefixInString(&itemTrim, " burst-size "): + rscData.All.BurstSize, err = tfdata.ConvAtoi64Value(itemTrim) + case itemTrim == " no-broadcast": + rscData.All.NoBroadcast = types.BoolValue(true) + case itemTrim == " no-multicast": + rscData.All.NoMulticast = types.BoolValue(true) + case itemTrim == " no-registered-multicast": + rscData.All.NoRegisteredMulticast = types.BoolValue(true) + case itemTrim == " no-unknown-unicast": + rscData.All.NoUnknownUnicast = types.BoolValue(true) + case itemTrim == " no-unregistered-multicast": + rscData.All.NoUnregisteredMulticast = types.BoolValue(true) + } + if err != nil { + return err + } + } + } + } + + return nil +} + +func (rscData *forwardingoptionsStormControlProfileData) del( + _ context.Context, junSess *junos.Session, +) error { + configSet := []string{ + "delete forwarding-options storm-control-profiles \"" + rscData.Name.ValueString() + "\"", + } + + return junSess.ConfigSet(configSet) +} diff --git a/internal/providerfwk/resource_forwardingoptions_storm_control_profile_test.go b/internal/providerfwk/resource_forwardingoptions_storm_control_profile_test.go new file mode 100644 index 00000000..122e97db --- /dev/null +++ b/internal/providerfwk/resource_forwardingoptions_storm_control_profile_test.go @@ -0,0 +1,37 @@ +package providerfwk_test + +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccResourceForwardingoptionsStormControlProfile_basic(t *testing.T) { + if os.Getenv("TESTACC_ROUTER") != "" || os.Getenv("TESTACC_SWITCH") != "" { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestStepDirectory(), + }, + { + ResourceName: "junos_forwardingoptions_storm_control_profile.testacc_stormControlProfile", + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.TestStepDirectory(), + }, + { + ConfigDirectory: config.TestStepDirectory(), + }, + { + ConfigDirectory: config.TestStepDirectory(), + }, + }, + }) + } +} diff --git a/internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/1/main.tf b/internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/1/main.tf new file mode 100644 index 00000000..a459b28b --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/1/main.tf @@ -0,0 +1,11 @@ +resource "junos_forwardingoptions_storm_control_profile" "testacc_stormControlProfile" { + name = "testacc_stormControlProfile @1" + action_shutdown = true + all { + bandwidth_level = 10240 + burst_size = 10240 + no_broadcast = true + no_multicast = true + no_unknown_unicast = true + } +} diff --git a/internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/3/main.tf b/internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/3/main.tf new file mode 100644 index 00000000..97f4440b --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/3/main.tf @@ -0,0 +1,7 @@ +resource "junos_forwardingoptions_storm_control_profile" "testacc_stormControlProfile" { + name = "testacc_stormControlProfile @1" + all { + bandwidth_percentage = 50 + no_registered_multicast = true + } +} diff --git a/internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/4/main.tf b/internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/4/main.tf new file mode 100644 index 00000000..69d99cb7 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/4/main.tf @@ -0,0 +1,6 @@ +resource "junos_forwardingoptions_storm_control_profile" "testacc_stormControlProfile" { + name = "testacc_stormControlProfile @1" + all { + no_unregistered_multicast = true + } +} diff --git a/internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/5/main.tf b/internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/5/main.tf new file mode 100644 index 00000000..66194e33 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceForwardingoptionsStormControlProfile_basic/5/main.tf @@ -0,0 +1,4 @@ +resource "junos_forwardingoptions_storm_control_profile" "testacc_stormControlProfile" { + name = "testacc_stormControlProfile @1" + all {} +} From 8275a4e94a2372bf553d3306dbce2682fa43834f Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Tue, 21 Nov 2023 08:43:25 +0100 Subject: [PATCH 04/43] r/interface_physical: add storm_control argument Partial fix #574 --- .changes/issue-574.md | 4 ++++ docs/resources/interface_physical.md | 2 ++ .../providerfwk/resource_interface_physical.go | 16 ++++++++++++++++ .../1/main.tf | 16 +++++++++++----- .../2/main.tf | 5 +++++ 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/.changes/issue-574.md b/.changes/issue-574.md index 7995d5b9..3a3eabd0 100644 --- a/.changes/issue-574.md +++ b/.changes/issue-574.md @@ -2,3 +2,7 @@ FEATURES: * add **junos_forwardingoptions_storm_control_profile** resource (Partial fix [#574](https://github.com/jeremmfr/terraform-provider-junos/issues/574)) + +ENHANCEMENTS: + +* **resource/junos_interface_physical**: add `storm_control` argument (Partial fix [#574](https://github.com/jeremmfr/terraform-provider-junos/issues/574)) diff --git a/docs/resources/interface_physical.md b/docs/resources/interface_physical.md index 93e37897..a59e6aec 100644 --- a/docs/resources/interface_physical.md +++ b/docs/resources/interface_physical.md @@ -110,6 +110,8 @@ The following arguments are supported: - **speed** (Optional, String) Link speed. Must be a valid speed (10m | 100m | 1g ...) +- **storm_control** (Optional, String) + Storm control profile name to bind. - **trunk** (Optional, Boolean) Interface mode is trunk. - **trunk_non_els** (Optional, Boolean) diff --git a/internal/providerfwk/resource_interface_physical.go b/internal/providerfwk/resource_interface_physical.go index 0776a5fc..560ad032 100644 --- a/internal/providerfwk/resource_interface_physical.go +++ b/internal/providerfwk/resource_interface_physical.go @@ -194,6 +194,14 @@ func (rsc *interfacePhysical) Schema( "must be a valid speed (10m | 100m | 1g ...)"), }, }, + "storm_control": schema.StringAttribute{ + Optional: true, + Description: "Storm control profile name to bind.", + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 127), + tfvalidator.StringDoubleQuoteExclusion(), + }, + }, "trunk": schema.BoolAttribute{ Optional: true, Description: "Interface mode is trunk.", @@ -641,6 +649,7 @@ type interfacePhysicalData struct { LinkMode types.String `tfsdk:"link_mode"` Mtu types.Int64 `tfsdk:"mtu"` Speed types.String `tfsdk:"speed"` + StormControl types.String `tfsdk:"storm_control"` VlanMembers []types.String `tfsdk:"vlan_members"` VlanNative types.Int64 `tfsdk:"vlan_native"` VlanNativeNonELS types.String `tfsdk:"vlan_native_non_els"` @@ -669,6 +678,7 @@ type interfacePhysicalConfig struct { LinkMode types.String `tfsdk:"link_mode"` Mtu types.Int64 `tfsdk:"mtu"` Speed types.String `tfsdk:"speed"` + StormControl types.String `tfsdk:"storm_control"` VlanMembers types.List `tfsdk:"vlan_members"` VlanNative types.Int64 `tfsdk:"vlan_native"` VlanNativeNonELS types.String `tfsdk:"vlan_native_non_els"` @@ -1737,6 +1747,9 @@ func (rscData *interfacePhysicalData) set( if v := rscData.Speed.ValueString(); v != "" { configSet = append(configSet, setPrefix+"speed "+v) } + if v := rscData.StormControl.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"unit 0 family ethernet-switching storm-control \""+v+"\"") + } if rscData.Trunk.ValueBool() { configSet = append(configSet, setPrefix+"unit 0 family ethernet-switching interface-mode trunk") } @@ -2028,6 +2041,8 @@ func (rscData *interfacePhysicalData) read( rscData.NoGratuitousArpRequest = types.BoolValue(true) case balt.CutPrefixInString(&itemTrim, "speed "): rscData.Speed = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "unit 0 family ethernet-switching storm-control "): + rscData.StormControl = types.StringValue(strings.Trim(itemTrim, "\"")) case itemTrim == "unit 0 family ethernet-switching interface-mode trunk": rscData.Trunk = types.BoolValue(true) case itemTrim == "unit 0 family ethernet-switching port-mode trunk": @@ -2228,6 +2243,7 @@ func (rscData *interfacePhysicalData) delOpts( delPrefix + "unit 0 family ethernet-switching interface-mode", delPrefix + "unit 0 family ethernet-switching native-vlan-id", delPrefix + "unit 0 family ethernet-switching port-mode", + delPrefix + "unit 0 family ethernet-switching storm-control", delPrefix + "unit 0 family ethernet-switching vlan members", delPrefix + "vlan-tagging", } diff --git a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/1/main.tf b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/1/main.tf index b4e5e667..2d2c6f28 100644 --- a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/1/main.tf +++ b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/1/main.tf @@ -1,7 +1,13 @@ resource "junos_interface_physical" "testacc_interface" { - name = var.interface - description = "testacc_interface" - trunk = true - vlan_native = 100 - vlan_members = ["100-110"] + name = var.interface + description = "testacc_interface" + storm_control = junos_forwardingoptions_storm_control_profile.testacc_interface.name + trunk = true + vlan_native = 100 + vlan_members = ["100-110"] +} + +resource "junos_forwardingoptions_storm_control_profile" "testacc_interface" { + name = "testacc interface" + all {} } diff --git a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/2/main.tf b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/2/main.tf index 4d8df0b3..21e1068b 100644 --- a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/2/main.tf +++ b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_switch/2/main.tf @@ -3,3 +3,8 @@ resource "junos_interface_physical" "testacc_interface" { description = "testacc_interfaceU" vlan_members = ["100"] } + +resource "junos_forwardingoptions_storm_control_profile" "testacc_interface" { + name = "testacc interface" + all {} +} From 4360f6360dff05febd04a0abc54a8310979296fe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 Nov 2023 01:00:42 +0000 Subject: [PATCH 05/43] deps: bump github.com/jeremmfr/go-utils from 0.10.0 to 0.11.0 Bumps [github.com/jeremmfr/go-utils](https://github.com/jeremmfr/go-utils) from 0.10.0 to 0.11.0. - [Release notes](https://github.com/jeremmfr/go-utils/releases) - [Changelog](https://github.com/jeremmfr/go-utils/blob/main/CHANGELOG.md) - [Commits](https://github.com/jeremmfr/go-utils/compare/v0.10.0...v0.11.0) --- updated-dependencies: - dependency-name: github.com/jeremmfr/go-utils dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index afe47dcc..bb1458c0 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0 github.com/hashicorp/terraform-plugin-testing v1.5.1 github.com/jeremmfr/go-netconf v0.4.14 - github.com/jeremmfr/go-utils v0.10.0 + github.com/jeremmfr/go-utils v0.11.0 github.com/jeremmfr/junosdecode v1.1.1 golang.org/x/crypto v0.15.0 ) diff --git a/go.sum b/go.sum index ce8eaa0a..63f815d1 100644 --- a/go.sum +++ b/go.sum @@ -84,8 +84,8 @@ github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKe github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jeremmfr/go-netconf v0.4.14 h1:kENaS5/8WootwGEIPUPke31sqsMbc7MpSJBbzY81t/A= github.com/jeremmfr/go-netconf v0.4.14/go.mod h1:Le5V8n/aoOifpdJK4BmxWW0CRhJWIaUkwpcQT75Y2NE= -github.com/jeremmfr/go-utils v0.10.0 h1:gEgZzLkzzHqRS0slHv3NCEeVemBYWWF7C4M3W1EatlY= -github.com/jeremmfr/go-utils v0.10.0/go.mod h1:Lkn95iSzCRviFhn2/0XmqzWGmxI+kkoqKAZqip7VUmM= +github.com/jeremmfr/go-utils v0.11.0 h1:+0Y1pXp2UJKh6Rw0QxPxe0zLv70GzyThAIEMkqKV67M= +github.com/jeremmfr/go-utils v0.11.0/go.mod h1:Lkn95iSzCRviFhn2/0XmqzWGmxI+kkoqKAZqip7VUmM= github.com/jeremmfr/junosdecode v1.1.1 h1:wOFfJIwLXP9s0eQzzAhuX7a7N1mc+AWgDLYAmR7VoWg= github.com/jeremmfr/junosdecode v1.1.1/go.mod h1:nTY0XbZC2ePbZdV0wuUboSMtGrJxtpwWVYfHjrS2Oqw= github.com/jeremmfr/terraform-plugin-sdk/v2 v2.29.1-0.20230913082525-7f46c82c0820 h1:NfBGagrPGV0InEMFvcqwIuYgeBzU//NwvEPSiTGSxZM= From 77b22d095b2ff36327525e1f23a1d16180ec46cb Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Fri, 24 Nov 2023 13:37:51 +0100 Subject: [PATCH 06/43] add junos_iccp resource Partial fix #573 --- .changes/issue-573.md | 4 + docs/resources/iccp.md | 47 +++ internal/providerfwk/provider.go | 1 + internal/providerfwk/resource_iccp.go | 294 ++++++++++++++++++ internal/providerfwk/resource_iccp_test.go | 31 ++ .../TestAccResourceIccp_basic/1/main.tf | 5 + .../TestAccResourceIccp_basic/3/main.tf | 3 + 7 files changed, 385 insertions(+) create mode 100644 .changes/issue-573.md create mode 100644 docs/resources/iccp.md create mode 100644 internal/providerfwk/resource_iccp.go create mode 100644 internal/providerfwk/resource_iccp_test.go create mode 100644 internal/providerfwk/testdata/TestAccResourceIccp_basic/1/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceIccp_basic/3/main.tf diff --git a/.changes/issue-573.md b/.changes/issue-573.md new file mode 100644 index 00000000..cf6a1645 --- /dev/null +++ b/.changes/issue-573.md @@ -0,0 +1,4 @@ + +FEATURES: + +* add `junos_iccp` resource (Partial fix [#573](https://github.com/jeremmfr/terraform-provider-junos/issues/573)) diff --git a/docs/resources/iccp.md b/docs/resources/iccp.md new file mode 100644 index 00000000..be1e26d0 --- /dev/null +++ b/docs/resources/iccp.md @@ -0,0 +1,47 @@ +--- +page_title: "Junos: junos_iccp" +--- + +# junos_iccp + +-> **Note:** This resource should only be created **once**. +It's used to configure static (not object) options in `protocols iccp` block. + +Configure static configuration in `protocols iccp` block. + +## Example Usage + +```hcl +# Configure protocol ICCP +resource "junos_iccp" "iccp" { + local_ip_addr = "192.0.2.1" + authentication_key = "a_key" + session_establishment_hold_time = 300 +} +``` + +## Argument Reference + +The following arguments are supported: + +- **local_ip_addr** (Required, String) + Local IP address to use by default for all peers. +- **authentication_key** (Optional, String, Sensitive) + MD5 authentication key for all peers. +- **session_establishment_hold_time** (Optional, Number) + Time within which connection must succeed with peers (45..600 seconds). + +## Attributes Reference + +The following attributes are exported: + +- **id** (String) + An identifier for the resource with value `iccp`. + +## Import + +Junos protocols ICCP can be imported using any id, e.g. + +```shell +$ terraform import junos_iccp.iccp random +``` diff --git a/internal/providerfwk/provider.go b/internal/providerfwk/provider.go index 4e94dae8..c0f3dd1b 100644 --- a/internal/providerfwk/provider.go +++ b/internal/providerfwk/provider.go @@ -212,6 +212,7 @@ func (p *junosProvider) Resources(_ context.Context) []func() resource.Resource newForwardingoptionsSamplingResource, newForwardingoptionsSamplingInstanceResource, newGenerateRouteResource, + newIccpResource, newInterfaceLogicalResource, newInterfacePhysicalDisableResource, newInterfacePhysicalResource, diff --git a/internal/providerfwk/resource_iccp.go b/internal/providerfwk/resource_iccp.go new file mode 100644 index 00000000..8e458292 --- /dev/null +++ b/internal/providerfwk/resource_iccp.go @@ -0,0 +1,294 @@ +package providerfwk + +import ( + "context" + "strings" + + "github.com/jeremmfr/terraform-provider-junos/internal/junos" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdata" + "github.com/jeremmfr/terraform-provider-junos/internal/tfvalidator" + "github.com/jeremmfr/terraform-provider-junos/internal/utils" + + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + balt "github.com/jeremmfr/go-utils/basicalter" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ resource.Resource = &iccp{} + _ resource.ResourceWithConfigure = &iccp{} + _ resource.ResourceWithImportState = &iccp{} +) + +type iccp struct { + client *junos.Client +} + +func newIccpResource() resource.Resource { + return &iccp{} +} + +func (rsc *iccp) typeName() string { + return providerName + "_iccp" +} + +func (rsc *iccp) junosName() string { + return "protocols iccp" +} + +func (rsc *iccp) junosClient() *junos.Client { + return rsc.client +} + +func (rsc *iccp) Metadata( + _ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse, +) { + resp.TypeName = rsc.typeName() +} + +func (rsc *iccp) Configure( + ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse, +) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + client, ok := req.ProviderData.(*junos.Client) + if !ok { + unexpectedResourceConfigureType(ctx, req, resp) + + return + } + rsc.client = client +} + +func (rsc *iccp) Schema( + _ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse, +) { + resp.Schema = schema.Schema{ + Description: "Configure static configuration in `" + rsc.junosName() + "` block", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "An identifier for the resource with value " + + "`iccp`.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "local_ip_addr": schema.StringAttribute{ + Required: true, + Description: "Local IP address to use by default for all peers.", + Validators: []validator.String{ + tfvalidator.StringIPAddress().IPv4Only(), + }, + }, + "authentication_key": schema.StringAttribute{ + Optional: true, + Sensitive: true, + Description: "MD5 authentication key for all peers.", + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 126), + tfvalidator.StringDoubleQuoteExclusion(), + }, + }, + "session_establishment_hold_time": schema.Int64Attribute{ + Optional: true, + Description: "Time within which connection must succeed with peers (seconds).", + Validators: []validator.Int64{ + int64validator.Between(45, 600), + }, + }, + }, + } +} + +type iccpData struct { + ID types.String `tfsdk:"id"` + LocalIPAddr types.String `tfsdk:"local_ip_addr"` + AuthenticationKey types.String `tfsdk:"authentication_key"` + SessionEstablishmentHoldTime types.Int64 `tfsdk:"session_establishment_hold_time"` +} + +func (rsc *iccp) Create( + ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse, +) { + var plan iccpData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceCreate( + ctx, + rsc, + nil, + nil, + &plan, + resp, + ) +} + +func (rsc *iccp) Read( + ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse, +) { + var state, data iccpData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + var _ resourceDataReadFrom0String = &data + defaultResourceRead( + ctx, + rsc, + nil, + &data, + nil, + resp, + ) +} + +func (rsc *iccp) Update( + ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse, +) { + var plan, state iccpData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceUpdate( + ctx, + rsc, + &state, + &plan, + resp, + ) +} + +func (rsc *iccp) Delete( + ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse, +) { + var state iccpData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceDelete( + ctx, + rsc, + &state, + resp, + ) +} + +func (rsc *iccp) ImportState( + ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse, +) { + var data iccpData + + var _ resourceDataReadFrom0String = &data + defaultResourceImportState( + ctx, + rsc, + &data, + req, + resp, + "", + ) +} + +func (rscData *iccpData) fillID() { + rscData.ID = types.StringValue("iccp") +} + +func (rscData *iccpData) nullID() bool { + return rscData.ID.IsNull() +} + +func (rscData *iccpData) set( + _ context.Context, junSess *junos.Session, +) ( + path.Path, error, +) { + setPrefix := junos.SetLS + "protocols iccp " + configSet := []string{ + setPrefix + "local-ip-addr " + rscData.LocalIPAddr.ValueString(), + } + + if v := rscData.AuthenticationKey.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"authentication-key \""+v+"\"") + } + if !rscData.SessionEstablishmentHoldTime.IsNull() { + configSet = append(configSet, setPrefix+"session-establishment-hold-time "+ + utils.ConvI64toa(rscData.SessionEstablishmentHoldTime.ValueInt64())) + } + + return path.Empty(), junSess.ConfigSet(configSet) +} + +func (rscData *iccpData) read( + _ context.Context, junSess *junos.Session, +) ( + err error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "protocols iccp" + junos.PipeDisplaySetRelative) + if err != nil { + return err + } + + if showConfig != junos.EmptyW { + rscData.fillID() + for _, item := range strings.Split(showConfig, "\n") { + if strings.Contains(item, junos.XMLStartTagConfigOut) { + continue + } + if strings.Contains(item, junos.XMLEndTagConfigOut) { + break + } + itemTrim := strings.TrimPrefix(item, junos.SetLS) + switch { + case balt.CutPrefixInString(&itemTrim, "local-ip-addr "): + rscData.LocalIPAddr = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "authentication-key "): + rscData.AuthenticationKey, err = tfdata.JunosDecode(strings.Trim(itemTrim, "\""), "authentication-key") + if err != nil { + return err + } + case balt.CutPrefixInString(&itemTrim, "session-establishment-hold-time "): + rscData.SessionEstablishmentHoldTime, err = tfdata.ConvAtoi64Value(itemTrim) + if err != nil { + return err + } + } + } + } + + return nil +} + +func (rscData *iccpData) del( + _ context.Context, junSess *junos.Session, +) error { + delLine := junos.DeleteLS + "protocols iccp " + + configSet := []string{ + delLine + "local-ip-addr", + delLine + "authentication-key", + delLine + "session-establishment-hold-time", + } + + return junSess.ConfigSet(configSet) +} diff --git a/internal/providerfwk/resource_iccp_test.go b/internal/providerfwk/resource_iccp_test.go new file mode 100644 index 00000000..a816b60f --- /dev/null +++ b/internal/providerfwk/resource_iccp_test.go @@ -0,0 +1,31 @@ +package providerfwk_test + +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccResourceIccp_basic(t *testing.T) { + if os.Getenv("TESTACC_ROUTER") != "" { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestStepDirectory(), + }, + { + ResourceName: "junos_iccp.testacc_iccp", + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.TestStepDirectory(), + }, + }, + }) + } +} diff --git a/internal/providerfwk/testdata/TestAccResourceIccp_basic/1/main.tf b/internal/providerfwk/testdata/TestAccResourceIccp_basic/1/main.tf new file mode 100644 index 00000000..8f865cc5 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceIccp_basic/1/main.tf @@ -0,0 +1,5 @@ +resource "junos_iccp" "testacc_iccp" { + local_ip_addr = "192.0.2.1" + authentication_key = "a@Key" + session_establishment_hold_time = 300 +} diff --git a/internal/providerfwk/testdata/TestAccResourceIccp_basic/3/main.tf b/internal/providerfwk/testdata/TestAccResourceIccp_basic/3/main.tf new file mode 100644 index 00000000..2583b81a --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceIccp_basic/3/main.tf @@ -0,0 +1,3 @@ +resource "junos_iccp" "testacc_iccp" { + local_ip_addr = "192.0.2.1" +} From f4c33cd63ffac93a65ed5c5d8f6970d0bec3fa1f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Nov 2023 00:32:50 +0000 Subject: [PATCH 07/43] deps: bump golang.org/x/crypto from 0.15.0 to 0.16.0 Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.15.0 to 0.16.0. - [Commits](https://github.com/golang/crypto/compare/v0.15.0...v0.16.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 4 ++-- go.sum | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index bb1458c0..71b47cd6 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/jeremmfr/go-netconf v0.4.14 github.com/jeremmfr/go-utils v0.11.0 github.com/jeremmfr/junosdecode v1.1.1 - golang.org/x/crypto v0.15.0 + golang.org/x/crypto v0.16.0 ) require ( @@ -56,7 +56,7 @@ require ( golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.14.0 // indirect + golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect diff --git a/go.sum b/go.sum index 63f815d1..3b7c1a4e 100644 --- a/go.sum +++ b/go.sum @@ -140,8 +140,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= -golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= +golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= +golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= 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= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -179,8 +179,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.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.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= @@ -188,7 +188,7 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= -golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8= +golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= 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= From fb6e6e03494b33f93084956771216c2e8dbc8822 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Wed, 29 Nov 2023 11:58:49 +0100 Subject: [PATCH 08/43] github: update feature request template add example of junos configuration --- .github/ISSUE_TEMPLATE/feature_request.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 40253ccd..828130b2 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -18,6 +18,13 @@ Please list the new or affected resources and data sources. * junos_XXXXX +### Example Junos Configuration + + ### Potential Terraform Configuration +ENHANCEMENTS: + +* **resource/junos_interface_physical**: add `mc_ae` block argument in `parent_ether_opts` block (Partial fix [#572](https://github.com/jeremmfr/terraform-provider-junos/issues/572)) diff --git a/docs/resources/interface_physical.md b/docs/resources/interface_physical.md index a59e6aec..082d9332 100644 --- a/docs/resources/interface_physical.md +++ b/docs/resources/interface_physical.md @@ -176,6 +176,9 @@ The following arguments are supported: Don't enable loopback. - **link_speed** (Optional, String) Link speed of individual interface that joins the AE. +- **mc_ae** (Optional, Block) + Multi-chassis aggregation (MC-AE) network device configuration. + See [below for nested schema](#mc_ae-arguments-in-parent_ether_opts). - **minimum_bandwidth** (Optional, String) Minimum bandwidth configured for aggregated bundle. Need to be `N (k|g|m)?bps` format. @@ -221,6 +224,38 @@ The following arguments are supported: - **version** (Optional, String) BFD protocol version number. +--- + +### mc_ae arguments in parent_ether_opts + +- **chassis_id** (Required, Number) + Chassis id of MC-AE network device (0..1). +- **mc_ae_id** (Required, Number) + MC-AE group id (1..65535). +- **mode** (Required, String) + Mode of the MC-AE. + Need to be `active-active` or `active-standby`. +- **status_control** (Required, String) + Status of the MC-AE chassis. + Need to be `active` or `standby`. +- **enhanced_convergence** (Optional, Boolean) + Optimized convergence time for MC-AE. +- **events_iccp_peer_down** (Optional, Block) + Define behavior in the event of ICCP peer down. + - **force_icl_down** (Optional, Boolean) + Bring down ICL logical interface. + - **prefer_status_control_active** (Optional, Boolean) + Keep this node up (recommended only on status-control active). +- **init_delay_time** (Optional, Number) + Init delay timer for mcae sm for min traffic loss (1..6000 seconds). +- **redundancy_group** (Optional, Number) + Redundancy group id (1..4294967294). +- **revert_time** (Optional, Number) + Wait interval before performing switchover (1..10 minute). +- **switchover_mode** (Optional, String) + Switchover mode. + Need to be `revertive` or `non-revertive`. + ## Attributes Reference The following attributes are exported: diff --git a/internal/providerfwk/resource_interface_physical.go b/internal/providerfwk/resource_interface_physical.go index 988a9903..6a2eca2b 100644 --- a/internal/providerfwk/resource_interface_physical.go +++ b/internal/providerfwk/resource_interface_physical.go @@ -558,6 +558,105 @@ func (rsc *interfacePhysical) Schema( tfplanmodifier.BlockRemoveNull(), }, }, + "mc_ae": schema.SingleNestedBlock{ + Description: "Multi-chassis aggregation (MC-AE) network device configuration.", + Attributes: map[string]schema.Attribute{ + "chassis_id": schema.Int64Attribute{ + Required: false, // true when SingleNestedBlock is specified + Optional: true, + Description: "Chassis id of MC-AE network device.", + Validators: []validator.Int64{ + int64validator.Between(0, 1), + }, + }, + "mc_ae_id": schema.Int64Attribute{ + Required: false, // true when SingleNestedBlock is specified + Optional: true, + Description: "MC-AE group id.", + Validators: []validator.Int64{ + int64validator.Between(1, 65535), + }, + }, + "mode": schema.StringAttribute{ + Required: false, // true when SingleNestedBlock is specified + Optional: true, + Description: "Mode of the MC-AE.", + Validators: []validator.String{ + stringvalidator.OneOf("active-active", "active-standby"), + }, + }, + "status_control": schema.StringAttribute{ + Required: false, // true when SingleNestedBlock is specified + Optional: true, + Description: "Status of the MC-AE chassis.", + Validators: []validator.String{ + stringvalidator.OneOf("active", "standby"), + }, + }, + "enhanced_convergence": schema.BoolAttribute{ + Optional: true, + Description: "Optimized convergence time for mcae.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "init_delay_time": schema.Int64Attribute{ + Optional: true, + Description: "Init delay timer for mcae sm for min traffic loss (seconds).", + Validators: []validator.Int64{ + int64validator.Between(1, 6000), + }, + }, + "redundancy_group": schema.Int64Attribute{ + Optional: true, + Description: "Redundancy group id.", + Validators: []validator.Int64{ + int64validator.Between(1, 4294967294), + }, + }, + "revert_time": schema.Int64Attribute{ + Optional: true, + Description: "Wait interval before performing switchover (minute).", + Validators: []validator.Int64{ + int64validator.Between(1, 10), + }, + }, + "switchover_mode": schema.StringAttribute{ + Optional: true, + Description: "Switchover mode.", + Validators: []validator.String{ + stringvalidator.OneOf("revertive", "non-revertive"), + }, + }, + }, + Blocks: map[string]schema.Block{ + "events_iccp_peer_down": schema.SingleNestedBlock{ + Description: "Define behavior in the event of ICCP peer down.", + Attributes: map[string]schema.Attribute{ + "force_icl_down": schema.BoolAttribute{ + Optional: true, + Description: "Bring down ICL logical interface.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "prefer_status_control_active": schema.BoolAttribute{ + Optional: true, + Description: "Keep this node up.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + }, + PlanModifiers: []planmodifier.Object{ + tfplanmodifier.BlockRemoveNull(), + }, + }, + }, + PlanModifiers: []planmodifier.Object{ + tfplanmodifier.BlockRemoveNull(), + }, + }, }, PlanModifiers: []planmodifier.Object{ tfplanmodifier.BlockRemoveNull(), @@ -743,6 +842,7 @@ type interfacePhysicalBlockParentEtherOpts struct { SourceAddressFilter []types.String `tfsdk:"source_address_filter"` BFDLivenessDetection *interfacePhysicalBlockParentEtherOptsBlockBFDLivenessDetection `tfsdk:"bfd_liveness_detection"` Lacp *interfacePhysicalBlockParentEtherOptsBlockLacp `tfsdk:"lacp"` + MCAE *interfacePhysicalBlockParentEtherOptsBlockMCAE `tfsdk:"mc_ae"` } type interfacePhysicalBlockParentEtherOptsConfig struct { @@ -758,6 +858,7 @@ type interfacePhysicalBlockParentEtherOptsConfig struct { SourceAddressFilter types.List `tfsdk:"source_address_filter"` BFDLivenessDetection *interfacePhysicalBlockParentEtherOptsBlockBFDLivenessDetection `tfsdk:"bfd_liveness_detection"` Lacp *interfacePhysicalBlockParentEtherOptsBlockLacp `tfsdk:"lacp"` + MCAE *interfacePhysicalBlockParentEtherOptsBlockMCAE `tfsdk:"mc_ae"` } func (block *interfacePhysicalBlockParentEtherOptsConfig) isEmpty() bool { @@ -786,6 +887,8 @@ func (block *interfacePhysicalBlockParentEtherOptsConfig) isEmpty() bool { return false case block.Lacp != nil: return false + case block.MCAE != nil: + return false default: return true } @@ -817,6 +920,25 @@ type interfacePhysicalBlockParentEtherOptsBlockLacp struct { SystemPriority types.Int64 `tfsdk:"system_priority"` } +//nolint:lll +type interfacePhysicalBlockParentEtherOptsBlockMCAE struct { + EnhancedConvergence types.Bool `tfsdk:"enhanced_convergence"` + ChassisID types.Int64 `tfsdk:"chassis_id"` + MCAEID types.Int64 `tfsdk:"mc_ae_id"` + Mode types.String `tfsdk:"mode"` + StatusControl types.String `tfsdk:"status_control"` + InitDelayTime types.Int64 `tfsdk:"init_delay_time"` + RedundancyGroup types.Int64 `tfsdk:"redundancy_group"` + RevertTime types.Int64 `tfsdk:"revert_time"` + SwitchoverMode types.String `tfsdk:"switchover_mode"` + EventsIccpPeerDown *interfacePhysicalBlockParentEtherOptsBlockMCAEBlockEventsIccpPeerDown `tfsdk:"events_iccp_peer_down"` +} + +type interfacePhysicalBlockParentEtherOptsBlockMCAEBlockEventsIccpPeerDown struct { + ForceIclDown types.Bool `tfsdk:"force_icl_down"` + PreferStatusControlActive types.Bool `tfsdk:"prefer_status_control_active"` +} + func (rsc *interfacePhysical) ValidateConfig( ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse, ) { @@ -989,6 +1111,58 @@ func (rsc *interfacePhysical) ValidateConfig( ) } } + if config.ParentEtherOpts.MCAE != nil { + if !config.Name.IsUnknown() { + if v := config.Name.ValueString(); !strings.HasPrefix(v, "ae") { + resp.Diagnostics.AddAttributeError( + path.Root("parent_ether_opts").AtName("mc_ae").AtName("*"), + tfdiag.ConflictConfigErrSummary, + fmt.Sprintf("mc_ae in parent_ether_opts block not compatible with this interface %q "+ + "(need to be ae* interface)", v), + ) + } + } + if config.ParentEtherOpts.MCAE.ChassisID.IsNull() { + resp.Diagnostics.AddAttributeError( + path.Root("parent_ether_opts").AtName("mc_ae").AtName("chassis_id"), + tfdiag.MissingConfigErrSummary, + "chassis_id must be specified in mc_ae block in parent_ether_opts block", + ) + } + if config.ParentEtherOpts.MCAE.MCAEID.IsNull() { + resp.Diagnostics.AddAttributeError( + path.Root("parent_ether_opts").AtName("mc_ae_id").AtName("chassis_id"), + tfdiag.MissingConfigErrSummary, + "mc_ae_id must be specified in mc_ae block in parent_ether_opts block", + ) + } + if config.ParentEtherOpts.MCAE.Mode.IsNull() { + resp.Diagnostics.AddAttributeError( + path.Root("parent_ether_opts").AtName("mode").AtName("chassis_id"), + tfdiag.MissingConfigErrSummary, + "mode must be specified in mc_ae block in parent_ether_opts block", + ) + } + if config.ParentEtherOpts.MCAE.StatusControl.IsNull() { + resp.Diagnostics.AddAttributeError( + path.Root("parent_ether_opts").AtName("status_control").AtName("chassis_id"), + tfdiag.MissingConfigErrSummary, + "status_control must be specified in mc_ae block in parent_ether_opts block", + ) + } + } + if !config.ParentEtherOpts.RedundancyGroup.IsNull() { + if !config.Name.IsUnknown() { + if v := config.Name.ValueString(); !strings.HasPrefix(v, "reth") { + resp.Diagnostics.AddAttributeError( + path.Root("parent_ether_opts").AtName("redundancy_group"), + tfdiag.ConflictConfigErrSummary, + fmt.Sprintf("redundancy_group in parent_ether_opts block not compatible with this interface %q "+ + "(need to be reth* interface)", v), + ) + } + } + } if config.ParentEtherOpts.isEmpty() { resp.Diagnostics.AddAttributeError( @@ -1904,6 +2078,49 @@ func (block *interfacePhysicalBlockParentEtherOpts) configSet( if v := block.LinkSpeed.ValueString(); v != "" { configSet = append(configSet, setPrefix+"link-speed "+v) } + if block.MCAE != nil { + if !strings.HasPrefix(interfaceName, "ae") { + return configSet, + path.Root("parent_ether_opts").AtName("mc_ae").AtName("*"), + fmt.Errorf("mc_ae in parent_ether_opts block not compatible with this interface %q "+ + "(need to be ae* interface)", interfaceName) + } + configSet = append(configSet, setPrefix+"mc-ae chassis-id "+ + utils.ConvI64toa(block.MCAE.ChassisID.ValueInt64())) + configSet = append(configSet, setPrefix+"mc-ae mc-ae-id "+ + utils.ConvI64toa(block.MCAE.MCAEID.ValueInt64())) + configSet = append(configSet, setPrefix+"mc-ae mode "+block.MCAE.Mode.ValueString()) + configSet = append(configSet, setPrefix+"mc-ae status-control "+block.MCAE.StatusControl.ValueString()) + + if block.MCAE.EnhancedConvergence.ValueBool() { + configSet = append(configSet, setPrefix+"mc-ae enhanced-convergence") + } + if block.MCAE.EventsIccpPeerDown != nil { + configSet = append(configSet, setPrefix+"mc-ae events iccp-peer-down") + + if block.MCAE.EventsIccpPeerDown.ForceIclDown.ValueBool() { + configSet = append(configSet, setPrefix+"mc-ae events iccp-peer-down force-icl-down") + } + if block.MCAE.EventsIccpPeerDown.PreferStatusControlActive.ValueBool() { + configSet = append(configSet, setPrefix+"mc-ae events iccp-peer-down prefer-status-control-active") + } + } + if !block.MCAE.InitDelayTime.IsNull() { + configSet = append(configSet, setPrefix+"mc-ae init-delay-time "+ + utils.ConvI64toa(block.MCAE.InitDelayTime.ValueInt64())) + } + if !block.MCAE.RedundancyGroup.IsNull() { + configSet = append(configSet, setPrefix+"mc-ae redundancy-group "+ + utils.ConvI64toa(block.MCAE.RedundancyGroup.ValueInt64())) + } + if !block.MCAE.RevertTime.IsNull() { + configSet = append(configSet, setPrefix+"mc-ae revert-time "+ + utils.ConvI64toa(block.MCAE.RevertTime.ValueInt64())) + } + if v := block.MCAE.SwitchoverMode.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"mc-ae switchover-mode "+v) + } + } if v := block.MinimumBandwidth.ValueString(); v != "" { vS := strings.Split(v, " ") configSet = append(configSet, setPrefix+"minimum-bandwidth bw-value "+vS[0]) @@ -1916,6 +2133,12 @@ func (block *interfacePhysicalBlockParentEtherOpts) configSet( utils.ConvI64toa(block.MinimumLinks.ValueInt64())) } if !block.RedundancyGroup.IsNull() { + if !strings.HasPrefix(interfaceName, "reth") { + return configSet, + path.Root("parent_ether_opts").AtName("redundancy_group"), + fmt.Errorf("redundancy_group in parent_ether_opts block not compatible with this interface %q "+ + "(need to be reth* interface)", interfaceName) + } configSet = append(configSet, setPrefix+"redundancy-group "+ utils.ConvI64toa(block.RedundancyGroup.ValueInt64())) } @@ -2119,43 +2342,22 @@ func (block *interfacePhysicalBlockParentEtherOpts) read(itemTrim string) (err e block.BFDLivenessDetection.AuthenticationLooseCheck = types.BoolValue(true) case balt.CutPrefixInString(&itemTrim, "detection-time threshold "): block.BFDLivenessDetection.DetectionTimeThreshold, err = tfdata.ConvAtoi64Value(itemTrim) - if err != nil { - return err - } case balt.CutPrefixInString(&itemTrim, "holddown-interval "): block.BFDLivenessDetection.HolddownInterval, err = tfdata.ConvAtoi64Value(itemTrim) - if err != nil { - return err - } case balt.CutPrefixInString(&itemTrim, "minimum-interval "): block.BFDLivenessDetection.MinimumInterval, err = tfdata.ConvAtoi64Value(itemTrim) - if err != nil { - return err - } case balt.CutPrefixInString(&itemTrim, "minimum-receive-interval "): block.BFDLivenessDetection.MinimumReceiveInterval, err = tfdata.ConvAtoi64Value(itemTrim) - if err != nil { - return err - } case balt.CutPrefixInString(&itemTrim, "multiplier "): block.BFDLivenessDetection.Multiplier, err = tfdata.ConvAtoi64Value(itemTrim) - if err != nil { - return err - } case balt.CutPrefixInString(&itemTrim, "neighbor "): block.BFDLivenessDetection.Neighbor = types.StringValue(itemTrim) case itemTrim == "no-adaptation": block.BFDLivenessDetection.NoAdaptation = types.BoolValue(true) case balt.CutPrefixInString(&itemTrim, "transmit-interval minimum-interval "): block.BFDLivenessDetection.TransmitIntervalMinimumInterval, err = tfdata.ConvAtoi64Value(itemTrim) - if err != nil { - return err - } case balt.CutPrefixInString(&itemTrim, "transmit-interval threshold "): block.BFDLivenessDetection.TransmitIntervalThreshold, err = tfdata.ConvAtoi64Value(itemTrim) - if err != nil { - return err - } case balt.CutPrefixInString(&itemTrim, "version "): block.BFDLivenessDetection.Version = types.StringValue(itemTrim) } @@ -2172,9 +2374,6 @@ func (block *interfacePhysicalBlockParentEtherOpts) read(itemTrim string) (err e block.Lacp.Mode = types.StringValue(itemTrim) case balt.CutPrefixInString(&itemTrim, "admin-key "): block.Lacp.AdminKey, err = tfdata.ConvAtoi64Value(itemTrim) - if err != nil { - return err - } case balt.CutPrefixInString(&itemTrim, "periodic "): block.Lacp.Periodic = types.StringValue(itemTrim) case balt.CutPrefixInString(&itemTrim, "sync-reset "): @@ -2183,9 +2382,6 @@ func (block *interfacePhysicalBlockParentEtherOpts) read(itemTrim string) (err e block.Lacp.SystemID = types.StringValue(itemTrim) case balt.CutPrefixInString(&itemTrim, "system-priority "): block.Lacp.SystemPriority, err = tfdata.ConvAtoi64Value(itemTrim) - if err != nil { - return err - } } case itemTrim == "loopback": block.Loopback = types.BoolValue(true) @@ -2193,20 +2389,48 @@ func (block *interfacePhysicalBlockParentEtherOpts) read(itemTrim string) (err e block.NoLoopback = types.BoolValue(true) case balt.CutPrefixInString(&itemTrim, "link-speed "): block.LinkSpeed = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "mc-ae "): + if block.MCAE == nil { + block.MCAE = &interfacePhysicalBlockParentEtherOptsBlockMCAE{} + } + switch { + case balt.CutPrefixInString(&itemTrim, "chassis-id "): + block.MCAE.ChassisID, err = tfdata.ConvAtoi64Value(itemTrim) + case balt.CutPrefixInString(&itemTrim, "mc-ae-id "): + block.MCAE.MCAEID, err = tfdata.ConvAtoi64Value(itemTrim) + case balt.CutPrefixInString(&itemTrim, "mode "): + block.MCAE.Mode = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "status-control "): + block.MCAE.StatusControl = types.StringValue(itemTrim) + case itemTrim == "enhanced-convergence": + block.MCAE.EnhancedConvergence = types.BoolValue(true) + case balt.CutPrefixInString(&itemTrim, "events iccp-peer-down"): + if block.MCAE.EventsIccpPeerDown == nil { + block.MCAE.EventsIccpPeerDown = &interfacePhysicalBlockParentEtherOptsBlockMCAEBlockEventsIccpPeerDown{} + } + switch { + case itemTrim == " force-icl-down": + block.MCAE.EventsIccpPeerDown.ForceIclDown = types.BoolValue(true) + case itemTrim == " prefer-status-control-active": + block.MCAE.EventsIccpPeerDown.PreferStatusControlActive = types.BoolValue(true) + } + case balt.CutPrefixInString(&itemTrim, "init-delay-time "): + block.MCAE.InitDelayTime, err = tfdata.ConvAtoi64Value(itemTrim) + case balt.CutPrefixInString(&itemTrim, "redundancy-group "): + block.MCAE.RedundancyGroup, err = tfdata.ConvAtoi64Value(itemTrim) + case balt.CutPrefixInString(&itemTrim, "revert-time "): + block.MCAE.RevertTime, err = tfdata.ConvAtoi64Value(itemTrim) + case balt.CutPrefixInString(&itemTrim, "switchover-mode "): + block.MCAE.SwitchoverMode = types.StringValue(itemTrim) + } case balt.CutPrefixInString(&itemTrim, "minimum-bandwidth bw-value "): block.MinimumBandwidth = types.StringValue(itemTrim + block.MinimumBandwidth.ValueString()) case balt.CutPrefixInString(&itemTrim, "minimum-bandwidth bw-unit "): block.MinimumBandwidth = types.StringValue(block.MinimumBandwidth.ValueString() + " " + itemTrim) case balt.CutPrefixInString(&itemTrim, "minimum-links "): block.MinimumLinks, err = tfdata.ConvAtoi64Value(itemTrim) - if err != nil { - return err - } case balt.CutPrefixInString(&itemTrim, "redundancy-group "): block.RedundancyGroup, err = tfdata.ConvAtoi64Value(itemTrim) - if err != nil { - return err - } case balt.CutPrefixInString(&itemTrim, "source-address-filter "): block.SourceAddressFilter = append(block.SourceAddressFilter, types.StringValue(itemTrim), @@ -2215,6 +2439,10 @@ func (block *interfacePhysicalBlockParentEtherOpts) read(itemTrim string) (err e block.SourceFiltering = types.BoolValue(true) } + if err != nil { + return err + } + return nil } diff --git a/internal/providerfwk/resource_interface_physical_test.go b/internal/providerfwk/resource_interface_physical_test.go index c42f96dc..c3887808 100644 --- a/internal/providerfwk/resource_interface_physical_test.go +++ b/internal/providerfwk/resource_interface_physical_test.go @@ -155,6 +155,20 @@ func TestAccResourceInterfacePhysical_router(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + ConfigDirectory: config.TestStepDirectory(), + ConfigVariables: map[string]config.Variable{ + "interface": config.StringVariable(testaccInterface), + "interfaceAE": config.StringVariable(testaccInterfaceAE), + }, + }, + { + ConfigDirectory: config.TestStepDirectory(), + ConfigVariables: map[string]config.Variable{ + "interface": config.StringVariable(testaccInterface), + "interfaceAE": config.StringVariable(testaccInterfaceAE), + }, + }, }, }) } diff --git a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/2/main.tf b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/2/main.tf index c5290443..e83304cd 100644 --- a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/2/main.tf +++ b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/2/main.tf @@ -12,5 +12,18 @@ resource "junos_interface_physical" "testacc_interfaceAE" { identifier = "00:11:11:11:11:11:11:11:11:11" mode = "all-active" } + parent_ether_opts { + lacp { + mode = "active" + admin_key = 1 + system_id = "ab:cd:ef:fe:dc:ba" + } + mc_ae { + chassis_id = 0 + mc_ae_id = 200 + mode = "active-active" + status_control = "active" + } + } vlan_tagging = true } diff --git a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/4/main.tf b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/4/main.tf new file mode 100644 index 00000000..82159c12 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/4/main.tf @@ -0,0 +1,53 @@ +resource "junos_interface_physical" "testacc_interface" { + name = var.interface + description = "testacc_interface" + gigether_opts { + ae_8023ad = var.interfaceAE + } +} +resource "junos_interface_physical" "testacc_interfaceAE" { + depends_on = [junos_iccp_peer.testacc_interfaceAE] + + name = var.interfaceAE + description = "testacc_interfaceAE" + esi { + identifier = "00:11:11:11:11:11:11:11:11:11" + mode = "all-active" + } + parent_ether_opts { + lacp { + mode = "active" + admin_key = 1 + system_id = "ab:cd:ef:fe:dc:ba" + } + mc_ae { + chassis_id = 0 + mc_ae_id = 200 + mode = "active-active" + status_control = "standby" + enhanced_convergence = true + events_iccp_peer_down { + force_icl_down = true + prefer_status_control_active = true + } + init_delay_time = 60 + redundancy_group = 300 + } + } + vlan_tagging = true +} + +resource "junos_iccp" "testacc_interfaceAE" { + local_ip_addr = "192.0.2.1" +} + +resource "junos_iccp_peer" "testacc_interfaceAE" { + depends_on = [junos_iccp.testacc_interfaceAE] + + ip_address = "192.0.2.2" + redundancy_group_id_list = [300] + + liveness_detection { + minimum_interval = 600 + } +} diff --git a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/4/variables.tf b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/4/variables.tf new file mode 100644 index 00000000..5a4fabc4 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/4/variables.tf @@ -0,0 +1,7 @@ +variable "interface" { + type = string +} + +variable "interfaceAE" { + type = string +} diff --git a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/5/main.tf b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/5/main.tf new file mode 100644 index 00000000..da0a2d71 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/5/main.tf @@ -0,0 +1,49 @@ +resource "junos_interface_physical" "testacc_interface" { + name = var.interface + description = "testacc_interface" + gigether_opts { + ae_8023ad = var.interfaceAE + } +} +resource "junos_interface_physical" "testacc_interfaceAE" { + depends_on = [junos_iccp_peer.testacc_interfaceAE] + + name = var.interfaceAE + description = "testacc_interfaceAE" + esi { + identifier = "00:11:11:11:11:11:11:11:11:11" + mode = "all-active" + } + parent_ether_opts { + lacp { + mode = "passive" + admin_key = 1 + system_id = "ab:cd:ef:fe:dc:ba" + } + mc_ae { + chassis_id = 0 + mc_ae_id = 200 + mode = "active-standby" + status_control = "active" + events_iccp_peer_down {} + revert_time = 5 + switchover_mode = "revertive" + } + } + vlan_tagging = true +} + +resource "junos_iccp" "testacc_interfaceAE" { + local_ip_addr = "192.0.2.1" +} + +resource "junos_iccp_peer" "testacc_interfaceAE" { + depends_on = [junos_iccp.testacc_interfaceAE] + + ip_address = "192.0.2.2" + redundancy_group_id_list = [300] + + liveness_detection { + minimum_interval = 600 + } +} diff --git a/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/5/variables.tf b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/5/variables.tf new file mode 100644 index 00000000..5a4fabc4 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceInterfacePhysical_router/5/variables.tf @@ -0,0 +1,7 @@ +variable "interface" { + type = string +} + +variable "interfaceAE" { + type = string +} From f6d3a6dbc90da1f4f94140dafeafddd6a97708f5 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Tue, 5 Dec 2023 09:19:52 +0100 Subject: [PATCH 12/43] r/interface_physical: rename struct field 'lacp' to uppercase --- .../resource_interface_physical.go | 66 +++++++++---------- .../upgradestate_interface_physical.go | 22 +++---- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/internal/providerfwk/resource_interface_physical.go b/internal/providerfwk/resource_interface_physical.go index 6a2eca2b..9661d29a 100644 --- a/internal/providerfwk/resource_interface_physical.go +++ b/internal/providerfwk/resource_interface_physical.go @@ -788,7 +788,7 @@ type interfacePhysicalConfig struct { } type interfacePhysicalBlockESI struct { - AutoDeriveLacp types.Bool `tfsdk:"auto_derive_lacp"` + AutoDeriveLACP types.Bool `tfsdk:"auto_derive_lacp"` Mode types.String `tfsdk:"mode"` DFElectionType types.String `tfsdk:"df_election_type"` Identifier types.String `tfsdk:"identifier"` @@ -841,7 +841,7 @@ type interfacePhysicalBlockParentEtherOpts struct { RedundancyGroup types.Int64 `tfsdk:"redundancy_group"` SourceAddressFilter []types.String `tfsdk:"source_address_filter"` BFDLivenessDetection *interfacePhysicalBlockParentEtherOptsBlockBFDLivenessDetection `tfsdk:"bfd_liveness_detection"` - Lacp *interfacePhysicalBlockParentEtherOptsBlockLacp `tfsdk:"lacp"` + LACP *interfacePhysicalBlockParentEtherOptsBlockLACP `tfsdk:"lacp"` MCAE *interfacePhysicalBlockParentEtherOptsBlockMCAE `tfsdk:"mc_ae"` } @@ -857,7 +857,7 @@ type interfacePhysicalBlockParentEtherOptsConfig struct { RedundancyGroup types.Int64 `tfsdk:"redundancy_group"` SourceAddressFilter types.List `tfsdk:"source_address_filter"` BFDLivenessDetection *interfacePhysicalBlockParentEtherOptsBlockBFDLivenessDetection `tfsdk:"bfd_liveness_detection"` - Lacp *interfacePhysicalBlockParentEtherOptsBlockLacp `tfsdk:"lacp"` + LACP *interfacePhysicalBlockParentEtherOptsBlockLACP `tfsdk:"lacp"` MCAE *interfacePhysicalBlockParentEtherOptsBlockMCAE `tfsdk:"mc_ae"` } @@ -885,7 +885,7 @@ func (block *interfacePhysicalBlockParentEtherOptsConfig) isEmpty() bool { return false case block.BFDLivenessDetection != nil: return false - case block.Lacp != nil: + case block.LACP != nil: return false case block.MCAE != nil: return false @@ -911,7 +911,7 @@ type interfacePhysicalBlockParentEtherOptsBlockBFDLivenessDetection struct { Version types.String `tfsdk:"version"` } -type interfacePhysicalBlockParentEtherOptsBlockLacp struct { +type interfacePhysicalBlockParentEtherOptsBlockLACP struct { Mode types.String `tfsdk:"mode"` AdminKey types.Int64 `tfsdk:"admin_key"` Periodic types.String `tfsdk:"periodic"` @@ -956,7 +956,7 @@ func (rsc *interfacePhysical) ValidateConfig( "mode must be specified in esi block", ) } - if !config.ESI.AutoDeriveLacp.IsNull() && !config.ESI.Identifier.IsNull() { + if !config.ESI.AutoDeriveLACP.IsNull() && !config.ESI.Identifier.IsNull() { resp.Diagnostics.AddAttributeError( path.Root("esi").AtName("auto_derive_lacp"), tfdiag.ConflictConfigErrSummary, @@ -1102,8 +1102,8 @@ func (rsc *interfacePhysical) ValidateConfig( ) } } - if config.ParentEtherOpts.Lacp != nil { - if config.ParentEtherOpts.Lacp.Mode.IsNull() { + if config.ParentEtherOpts.LACP != nil { + if config.ParentEtherOpts.LACP.Mode.IsNull() { resp.Diagnostics.AddAttributeError( path.Root("parent_ether_opts").AtName("lacp").AtName("mode"), tfdiag.MissingConfigErrSummary, @@ -1953,7 +1953,7 @@ func (block *interfacePhysicalBlockESI) configSet(setPrefix string) []string { setPrefix + "esi " + block.Mode.ValueString(), } - if block.AutoDeriveLacp.ValueBool() { + if block.AutoDeriveLACP.ValueBool() { configSet = append(configSet, setPrefix+"esi auto-derive lacp") } if v := block.DFElectionType.ValueString(); v != "" { @@ -2048,25 +2048,25 @@ func (block *interfacePhysicalBlockParentEtherOpts) configSet( if block.NoFlowControl.ValueBool() { configSet = append(configSet, setPrefix+"no-flow-control") } - if block.Lacp != nil { - setPrefixLacp := setPrefix + "lacp " - configSet = append(configSet, setPrefixLacp+block.Lacp.Mode.ValueString()) - if !block.Lacp.AdminKey.IsNull() { - configSet = append(configSet, setPrefixLacp+"admin-key "+ - utils.ConvI64toa(block.Lacp.AdminKey.ValueInt64())) + if block.LACP != nil { + setPrefixLACP := setPrefix + "lacp " + configSet = append(configSet, setPrefixLACP+block.LACP.Mode.ValueString()) + if !block.LACP.AdminKey.IsNull() { + configSet = append(configSet, setPrefixLACP+"admin-key "+ + utils.ConvI64toa(block.LACP.AdminKey.ValueInt64())) } - if v := block.Lacp.Periodic.ValueString(); v != "" { - configSet = append(configSet, setPrefixLacp+"periodic "+v) + if v := block.LACP.Periodic.ValueString(); v != "" { + configSet = append(configSet, setPrefixLACP+"periodic "+v) } - if v := block.Lacp.SyncReset.ValueString(); v != "" { - configSet = append(configSet, setPrefixLacp+"sync-reset "+v) + if v := block.LACP.SyncReset.ValueString(); v != "" { + configSet = append(configSet, setPrefixLACP+"sync-reset "+v) } - if v := block.Lacp.SystemID.ValueString(); v != "" { - configSet = append(configSet, setPrefixLacp+"system-id "+v) + if v := block.LACP.SystemID.ValueString(); v != "" { + configSet = append(configSet, setPrefixLACP+"system-id "+v) } - if !block.Lacp.SystemPriority.IsNull() { - configSet = append(configSet, setPrefixLacp+"system-priority "+ - utils.ConvI64toa(block.Lacp.SystemPriority.ValueInt64())) + if !block.LACP.SystemPriority.IsNull() { + configSet = append(configSet, setPrefixLACP+"system-priority "+ + utils.ConvI64toa(block.LACP.SystemPriority.ValueInt64())) } } if block.Loopback.ValueBool() { @@ -2298,7 +2298,7 @@ func (block *interfacePhysicalBlockESI) read(itemTrim string) error { case balt.CutPrefixInString(&itemTrim, "source-bmac "): block.SourceBMAC = types.StringValue(itemTrim) case itemTrim == "auto-derive lacp": - block.AutoDeriveLacp = types.BoolValue(true) + block.AutoDeriveLACP = types.BoolValue(true) } return nil @@ -2366,22 +2366,22 @@ func (block *interfacePhysicalBlockParentEtherOpts) read(itemTrim string) (err e case itemTrim == "no-flow-control": block.NoFlowControl = types.BoolValue(true) case balt.CutPrefixInString(&itemTrim, "lacp "): - if block.Lacp == nil { - block.Lacp = &interfacePhysicalBlockParentEtherOptsBlockLacp{} + if block.LACP == nil { + block.LACP = &interfacePhysicalBlockParentEtherOptsBlockLACP{} } switch { case itemTrim == "active", itemTrim == "passive": - block.Lacp.Mode = types.StringValue(itemTrim) + block.LACP.Mode = types.StringValue(itemTrim) case balt.CutPrefixInString(&itemTrim, "admin-key "): - block.Lacp.AdminKey, err = tfdata.ConvAtoi64Value(itemTrim) + block.LACP.AdminKey, err = tfdata.ConvAtoi64Value(itemTrim) case balt.CutPrefixInString(&itemTrim, "periodic "): - block.Lacp.Periodic = types.StringValue(itemTrim) + block.LACP.Periodic = types.StringValue(itemTrim) case balt.CutPrefixInString(&itemTrim, "sync-reset "): - block.Lacp.SyncReset = types.StringValue(itemTrim) + block.LACP.SyncReset = types.StringValue(itemTrim) case balt.CutPrefixInString(&itemTrim, "system-id "): - block.Lacp.SystemID = types.StringValue(itemTrim) + block.LACP.SystemID = types.StringValue(itemTrim) case balt.CutPrefixInString(&itemTrim, "system-priority "): - block.Lacp.SystemPriority, err = tfdata.ConvAtoi64Value(itemTrim) + block.LACP.SystemPriority, err = tfdata.ConvAtoi64Value(itemTrim) } case itemTrim == "loopback": block.Loopback = types.BoolValue(true) diff --git a/internal/providerfwk/upgradestate_interface_physical.go b/internal/providerfwk/upgradestate_interface_physical.go index 70e5eabb..c9060870 100644 --- a/internal/providerfwk/upgradestate_interface_physical.go +++ b/internal/providerfwk/upgradestate_interface_physical.go @@ -260,7 +260,7 @@ func upgradeInterfacePhysicalV0toV1( VlanMembers []types.String `tfsdk:"vlan_members"` VlanNative types.Int64 `tfsdk:"vlan_native"` ESI []struct { - AutoDeriveLacp types.Bool `tfsdk:"auto_derive_lacp"` + AutoDeriveLACP types.Bool `tfsdk:"auto_derive_lacp"` Mode types.String `tfsdk:"mode"` DFElectionType types.String `tfsdk:"df_election_type"` Identifier types.String `tfsdk:"identifier"` @@ -313,7 +313,7 @@ func upgradeInterfacePhysicalV0toV1( TransmitIntervalThreshold types.Int64 `tfsdk:"transmit_interval_threshold"` Version types.String `tfsdk:"version"` } `tfsdk:"bfd_liveness_detection"` - Lacp []struct { + LACP []struct { Mode types.String `tfsdk:"mode"` AdminKey types.Int64 `tfsdk:"admin_key"` Periodic types.String `tfsdk:"periodic"` @@ -346,7 +346,7 @@ func upgradeInterfacePhysicalV0toV1( dataV1.VlanTagging = dataV0.VlanTagging if len(dataV0.ESI) > 0 { dataV1.ESI = &interfacePhysicalBlockESI{ - AutoDeriveLacp: dataV0.ESI[0].AutoDeriveLacp, + AutoDeriveLACP: dataV0.ESI[0].AutoDeriveLACP, Mode: dataV0.ESI[0].Mode, DFElectionType: dataV0.ESI[0].DFElectionType, Identifier: dataV0.ESI[0].Identifier, @@ -408,14 +408,14 @@ func upgradeInterfacePhysicalV0toV1( Version: dataV0.ParentEtherOpts[0].BFDLivenessDetection[0].Version, } } - if len(dataV0.ParentEtherOpts[0].Lacp) > 0 { - dataV1.ParentEtherOpts.Lacp = &interfacePhysicalBlockParentEtherOptsBlockLacp{ - Mode: dataV0.ParentEtherOpts[0].Lacp[0].Mode, - AdminKey: dataV0.ParentEtherOpts[0].Lacp[0].AdminKey, - Periodic: dataV0.ParentEtherOpts[0].Lacp[0].Periodic, - SyncReset: dataV0.ParentEtherOpts[0].Lacp[0].SyncReset, - SystemID: dataV0.ParentEtherOpts[0].Lacp[0].SystemID, - SystemPriority: dataV0.ParentEtherOpts[0].Lacp[0].SystemPriority, + if len(dataV0.ParentEtherOpts[0].LACP) > 0 { + dataV1.ParentEtherOpts.LACP = &interfacePhysicalBlockParentEtherOptsBlockLACP{ + Mode: dataV0.ParentEtherOpts[0].LACP[0].Mode, + AdminKey: dataV0.ParentEtherOpts[0].LACP[0].AdminKey, + Periodic: dataV0.ParentEtherOpts[0].LACP[0].Periodic, + SyncReset: dataV0.ParentEtherOpts[0].LACP[0].SyncReset, + SystemID: dataV0.ParentEtherOpts[0].LACP[0].SystemID, + SystemPriority: dataV0.ParentEtherOpts[0].LACP[0].SystemPriority, } } } From 54a25454be41c173fde74a74356e891b5a896be0 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Tue, 5 Dec 2023 13:57:38 +0100 Subject: [PATCH 13/43] d/interface_physical: add mc_ae block attribute in parent_ether_opts block attribute --- .changes/issue-572.md | 1 + docs/data-sources/interface_physical.md | 34 ++++++++++- .../data_source_interface_physical.go | 21 ++++++- .../data_source_interface_physical_test.go | 38 +++++++++++++ .../1/main.tf | 53 +++++++++++++++++ .../1/variables.tf | 7 +++ .../2/main.tf | 57 +++++++++++++++++++ .../2/variables.tf | 7 +++ 8 files changed, 214 insertions(+), 4 deletions(-) create mode 100644 internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/1/main.tf create mode 100644 internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/1/variables.tf create mode 100644 internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/2/main.tf create mode 100644 internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/2/variables.tf diff --git a/.changes/issue-572.md b/.changes/issue-572.md index 61e51c82..5eca7d89 100644 --- a/.changes/issue-572.md +++ b/.changes/issue-572.md @@ -2,3 +2,4 @@ ENHANCEMENTS: * **resource/junos_interface_physical**: add `mc_ae` block argument in `parent_ether_opts` block (Partial fix [#572](https://github.com/jeremmfr/terraform-provider-junos/issues/572)) +* **data-source/junos_interface_physical**: add `mc_ae` block attribute in `parent_ether_opts` block diff --git a/docs/data-sources/interface_physical.md b/docs/data-sources/interface_physical.md index 0cb2d59e..bfb808e9 100644 --- a/docs/data-sources/interface_physical.md +++ b/docs/data-sources/interface_physical.md @@ -140,7 +140,7 @@ The following attributes are exported: - **bfd_liveness_detection** (Block) The `bfd-liveness-detection` in `aggregated-ether-options` configuration. - See [below for nested schema](#bfd_liveness_detection-attributes-in-parent_ether_opts) block. + See [below for nested schema](#bfd_liveness_detection-attributes-in-parent_ether_opts). - **flow_control** (Boolean) Enable flow control. - **no_flow_control** (Boolean) @@ -165,6 +165,9 @@ The following attributes are exported: Don't enable loopback. - **link_speed** (String) Link speed of individual interface that joins the AE. +- **mc_ae** (Block) + Multi-chassis aggregation (MC-AE) network device configuration. + See [below for nested schema](#mc_ae-arguments-in-parent_ether_opts). - **minimum_bandwidth** (String) Minimum bandwidth configured for aggregated bundle. - **minimum_links** (Number) @@ -208,3 +211,32 @@ The following attributes are exported: High transmit interval triggering a trap. - **version** (String) BFD protocol version number. + +--- + +### mc_ae arguments in parent_ether_opts + +- **chassis_id** (Number) + Chassis id of MC-AE network device. +- **mc_ae_id** (Number) + MC-AE group id. +- **mode** (String) + Mode of the MC-AE. +- **status_control** (String) + Status of the MC-AE chassis. +- **enhanced_convergence** (Boolean) + Optimized convergence time for MC-AE. +- **events_iccp_peer_down** (Block) + Define behavior in the event of ICCP peer down. + - **force_icl_down** (Boolean) + Bring down ICL logical interface. + - **prefer_status_control_active** (Boolean) + Keep this node up (recommended only on status-control active). +- **init_delay_time** (Number) + Init delay timer for mcae sm for min traffic loss (seconds). +- **redundancy_group** (Number) + Redundancy group id. +- **revert_time** (Number) + Wait interval before performing switchover (minute). +- **switchover_mode** (String) + Switchover mode. diff --git a/internal/providerfwk/data_source_interface_physical.go b/internal/providerfwk/data_source_interface_physical.go index c738f8fb..414108f6 100644 --- a/internal/providerfwk/data_source_interface_physical.go +++ b/internal/providerfwk/data_source_interface_physical.go @@ -210,9 +210,24 @@ func (dsc *interfacePhysicalDataSource) Schema( "system_id": types.StringType, "system_priority": types.Int64Type, }), - "loopback": types.BoolType, - "no_loopback": types.BoolType, - "link_speed": types.Int64Type, + "loopback": types.BoolType, + "no_loopback": types.BoolType, + "link_speed": types.Int64Type, + "mc_ae": types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ + "chassis_id": types.Int64Type, + "mc_ae_id": types.Int64Type, + "mode": types.StringType, + "status_control": types.StringType, + "enhanced_convergence": types.BoolType, + "init_delay_time": types.Int64Type, + "redundancy_group": types.Int64Type, + "revert_time": types.Int64Type, + "switchover_mode": types.StringType, + "events_iccp_peer_down": types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ + "force_icl_down": types.BoolType, + "prefer_status_control_active": types.BoolType, + }), + }), "minimum_bandwidth": types.Int64Type, "minimum_links": types.Int64Type, "redundancy_group": types.Int64Type, diff --git a/internal/providerfwk/data_source_interface_physical_test.go b/internal/providerfwk/data_source_interface_physical_test.go index e5fd2e5a..8e6cd275 100644 --- a/internal/providerfwk/data_source_interface_physical_test.go +++ b/internal/providerfwk/data_source_interface_physical_test.go @@ -44,3 +44,41 @@ func TestAccDataSourceInterfacePhysical_basic(t *testing.T) { }) } } + +func TestAccDataSourceInterfacePhysical_router(t *testing.T) { + testaccInterface := junos.DefaultInterfaceTestAcc + testaccInterfaceAE := "ae0" + if iface := os.Getenv("TESTACC_INTERFACE"); iface != "" { + testaccInterface = iface + } + if iface := os.Getenv("TESTACC_INTERFACE_AE"); iface != "" { + testaccInterfaceAE = iface + } + if os.Getenv("TESTACC_ROUTER") != "" { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestStepDirectory(), + ConfigVariables: map[string]config.Variable{ + "interface": config.StringVariable(testaccInterface), + "interfaceAE": config.StringVariable(testaccInterfaceAE), + }, + }, + { + ConfigDirectory: config.TestStepDirectory(), + ConfigVariables: map[string]config.Variable{ + "interface": config.StringVariable(testaccInterface), + "interfaceAE": config.StringVariable(testaccInterfaceAE), + }, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.junos_interface_physical.testacc_interfaceAE", + "id", testaccInterfaceAE), + ), + }, + }, + PreventPostDestroyRefresh: true, + }) + } +} diff --git a/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/1/main.tf b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/1/main.tf new file mode 100644 index 00000000..82159c12 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/1/main.tf @@ -0,0 +1,53 @@ +resource "junos_interface_physical" "testacc_interface" { + name = var.interface + description = "testacc_interface" + gigether_opts { + ae_8023ad = var.interfaceAE + } +} +resource "junos_interface_physical" "testacc_interfaceAE" { + depends_on = [junos_iccp_peer.testacc_interfaceAE] + + name = var.interfaceAE + description = "testacc_interfaceAE" + esi { + identifier = "00:11:11:11:11:11:11:11:11:11" + mode = "all-active" + } + parent_ether_opts { + lacp { + mode = "active" + admin_key = 1 + system_id = "ab:cd:ef:fe:dc:ba" + } + mc_ae { + chassis_id = 0 + mc_ae_id = 200 + mode = "active-active" + status_control = "standby" + enhanced_convergence = true + events_iccp_peer_down { + force_icl_down = true + prefer_status_control_active = true + } + init_delay_time = 60 + redundancy_group = 300 + } + } + vlan_tagging = true +} + +resource "junos_iccp" "testacc_interfaceAE" { + local_ip_addr = "192.0.2.1" +} + +resource "junos_iccp_peer" "testacc_interfaceAE" { + depends_on = [junos_iccp.testacc_interfaceAE] + + ip_address = "192.0.2.2" + redundancy_group_id_list = [300] + + liveness_detection { + minimum_interval = 600 + } +} diff --git a/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/1/variables.tf b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/1/variables.tf new file mode 100644 index 00000000..5a4fabc4 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/1/variables.tf @@ -0,0 +1,7 @@ +variable "interface" { + type = string +} + +variable "interfaceAE" { + type = string +} diff --git a/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/2/main.tf b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/2/main.tf new file mode 100644 index 00000000..39a1c9fa --- /dev/null +++ b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/2/main.tf @@ -0,0 +1,57 @@ +data "junos_interface_physical" "testacc_interfaceAE" { + config_interface = var.interfaceAE +} + +resource "junos_interface_physical" "testacc_interface" { + name = var.interface + description = "testacc_interface" + gigether_opts { + ae_8023ad = var.interfaceAE + } +} +resource "junos_interface_physical" "testacc_interfaceAE" { + depends_on = [junos_iccp_peer.testacc_interfaceAE] + + name = var.interfaceAE + description = "testacc_interfaceAE" + esi { + identifier = "00:11:11:11:11:11:11:11:11:11" + mode = "all-active" + } + parent_ether_opts { + lacp { + mode = "active" + admin_key = 1 + system_id = "ab:cd:ef:fe:dc:ba" + } + mc_ae { + chassis_id = 0 + mc_ae_id = 200 + mode = "active-active" + status_control = "standby" + enhanced_convergence = true + events_iccp_peer_down { + force_icl_down = true + prefer_status_control_active = true + } + init_delay_time = 60 + redundancy_group = 300 + } + } + vlan_tagging = true +} + +resource "junos_iccp" "testacc_interfaceAE" { + local_ip_addr = "192.0.2.1" +} + +resource "junos_iccp_peer" "testacc_interfaceAE" { + depends_on = [junos_iccp.testacc_interfaceAE] + + ip_address = "192.0.2.2" + redundancy_group_id_list = [300] + + liveness_detection { + minimum_interval = 600 + } +} diff --git a/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/2/variables.tf b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/2/variables.tf new file mode 100644 index 00000000..5a4fabc4 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_router/2/variables.tf @@ -0,0 +1,7 @@ +variable "interface" { + type = string +} + +variable "interfaceAE" { + type = string +} From 59ca9e18197c159b88ba8587a819486eacd09b8a Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Tue, 5 Dec 2023 14:16:53 +0100 Subject: [PATCH 14/43] d/interface_physical: fix reading link_speed and minimum_bandwidth attributes in parent_ether_opts block --- .changes/issue-572.md | 4 ++++ internal/providerfwk/data_source_interface_physical.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.changes/issue-572.md b/.changes/issue-572.md index 5eca7d89..14639bd3 100644 --- a/.changes/issue-572.md +++ b/.changes/issue-572.md @@ -3,3 +3,7 @@ ENHANCEMENTS: * **resource/junos_interface_physical**: add `mc_ae` block argument in `parent_ether_opts` block (Partial fix [#572](https://github.com/jeremmfr/terraform-provider-junos/issues/572)) * **data-source/junos_interface_physical**: add `mc_ae` block attribute in `parent_ether_opts` block + +BUG FIXES: + +* **data-source/junos_interface_physical**: fix reading `link_speed` and `minimum_bandwidth` attributes in `parent_ether_opts` block diff --git a/internal/providerfwk/data_source_interface_physical.go b/internal/providerfwk/data_source_interface_physical.go index 414108f6..31adb845 100644 --- a/internal/providerfwk/data_source_interface_physical.go +++ b/internal/providerfwk/data_source_interface_physical.go @@ -212,7 +212,7 @@ func (dsc *interfacePhysicalDataSource) Schema( }), "loopback": types.BoolType, "no_loopback": types.BoolType, - "link_speed": types.Int64Type, + "link_speed": types.StringType, "mc_ae": types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ "chassis_id": types.Int64Type, "mc_ae_id": types.Int64Type, @@ -228,7 +228,7 @@ func (dsc *interfacePhysicalDataSource) Schema( "prefer_status_control_active": types.BoolType, }), }), - "minimum_bandwidth": types.Int64Type, + "minimum_bandwidth": types.StringType, "minimum_links": types.Int64Type, "redundancy_group": types.Int64Type, "source_address_filter": types.ListType{}.WithElementType(types.StringType), From 9fd8209b08498e2cf885751e0d5bbfa3250b297d Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Tue, 5 Dec 2023 14:04:53 +0100 Subject: [PATCH 15/43] d/interface_physical: add storm_control attribute --- .changes/issue-574.md | 1 + docs/data-sources/interface_physical.md | 2 ++ .../data_source_interface_physical.go | 14 +++++--- .../data_source_interface_physical_test.go | 33 +++++++++++++++++++ .../1/main.tf | 13 ++++++++ .../1/variables.tf | 3 ++ .../2/main.tf | 16 +++++++++ .../2/variables.tf | 3 ++ 8 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/1/main.tf create mode 100644 internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/1/variables.tf create mode 100644 internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/2/main.tf create mode 100644 internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/2/variables.tf diff --git a/.changes/issue-574.md b/.changes/issue-574.md index 3a3eabd0..19e037d8 100644 --- a/.changes/issue-574.md +++ b/.changes/issue-574.md @@ -6,3 +6,4 @@ FEATURES: ENHANCEMENTS: * **resource/junos_interface_physical**: add `storm_control` argument (Partial fix [#574](https://github.com/jeremmfr/terraform-provider-junos/issues/574)) +* **data-source/junos_interface_physical**: add `storm_control` attribute like resource diff --git a/docs/data-sources/interface_physical.md b/docs/data-sources/interface_physical.md index bfb808e9..474cc622 100644 --- a/docs/data-sources/interface_physical.md +++ b/docs/data-sources/interface_physical.md @@ -103,6 +103,8 @@ The following attributes are exported: See [below for nested schema](#parent_ether_opts-attributes). - **speed** (String) Link speed. +- **storm_control** (String) + Storm control profile name to bind. - **trunk** (Boolean) Interface mode is trunk. - **trunk_non_els** (Boolean) diff --git a/internal/providerfwk/data_source_interface_physical.go b/internal/providerfwk/data_source_interface_physical.go index 31adb845..c62f9b1d 100644 --- a/internal/providerfwk/data_source_interface_physical.go +++ b/internal/providerfwk/data_source_interface_physical.go @@ -176,10 +176,6 @@ func (dsc *interfacePhysicalDataSource) Schema( Computed: true, Description: "Ignore gratuitous ARP request.", }, - "speed": schema.StringAttribute{ - Computed: true, - Description: "Link speed.", - }, "parent_ether_opts": schema.ObjectAttribute{ Computed: true, Description: "The `aggregated-ether-options` or `redundant-ether-options` configuration.", @@ -235,6 +231,14 @@ func (dsc *interfacePhysicalDataSource) Schema( "source_filtering": types.BoolType, }, }, + "speed": schema.StringAttribute{ + Computed: true, + Description: "Link speed.", + }, + "storm_control": schema.StringAttribute{ + Computed: true, + Description: "Storm control profile name to bind.", + }, "trunk": schema.BoolAttribute{ Computed: true, Description: "Interface mode is trunk.", @@ -284,6 +288,7 @@ type interfacePhysicalDataSourceData struct { LinkMode types.String `tfsdk:"link_mode"` Mtu types.Int64 `tfsdk:"mtu"` Speed types.String `tfsdk:"speed"` + StormControl types.String `tfsdk:"storm_control"` VlanMembers []types.String `tfsdk:"vlan_members"` VlanNative types.Int64 `tfsdk:"vlan_native"` VlanNativeNonELS types.String `tfsdk:"vlan_native_non_els"` @@ -435,6 +440,7 @@ func (dscData *interfacePhysicalDataSourceData) copyFromResourceData(rscData int dscData.NoGratuitousArpRequest = rscData.NoGratuitousArpRequest dscData.ParentEtherOpts = rscData.ParentEtherOpts dscData.Speed = rscData.Speed + dscData.StormControl = rscData.StormControl dscData.Trunk = rscData.Trunk dscData.TrunkNonELS = rscData.TrunkNonELS dscData.VlanMembers = rscData.VlanMembers diff --git a/internal/providerfwk/data_source_interface_physical_test.go b/internal/providerfwk/data_source_interface_physical_test.go index 8e6cd275..32ecd34e 100644 --- a/internal/providerfwk/data_source_interface_physical_test.go +++ b/internal/providerfwk/data_source_interface_physical_test.go @@ -82,3 +82,36 @@ func TestAccDataSourceInterfacePhysical_router(t *testing.T) { }) } } + +func TestAccDataSourceInterfacePhysical_switch(t *testing.T) { + testaccInterface := junos.DefaultInterfaceSwitchTestAcc + if iface := os.Getenv("TESTACC_INTERFACE"); iface != "" { + testaccInterface = iface + } + if os.Getenv("TESTACC_SWITCH") != "" { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestStepDirectory(), + ConfigVariables: map[string]config.Variable{ + "interface": config.StringVariable(testaccInterface), + }, + }, + { + ConfigDirectory: config.TestStepDirectory(), + ConfigVariables: map[string]config.Variable{ + "interface": config.StringVariable(testaccInterface), + }, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.junos_interface_physical.testacc_interface", + "id", testaccInterface), + resource.TestCheckResourceAttr("data.junos_interface_physical.testacc_interface", + "storm_control", "testacc interface"), + ), + }, + }, + }) + } +} diff --git a/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/1/main.tf b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/1/main.tf new file mode 100644 index 00000000..2d2c6f28 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/1/main.tf @@ -0,0 +1,13 @@ +resource "junos_interface_physical" "testacc_interface" { + name = var.interface + description = "testacc_interface" + storm_control = junos_forwardingoptions_storm_control_profile.testacc_interface.name + trunk = true + vlan_native = 100 + vlan_members = ["100-110"] +} + +resource "junos_forwardingoptions_storm_control_profile" "testacc_interface" { + name = "testacc interface" + all {} +} diff --git a/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/1/variables.tf b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/1/variables.tf new file mode 100644 index 00000000..d5ed041c --- /dev/null +++ b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/1/variables.tf @@ -0,0 +1,3 @@ +variable "interface" { + type = string +} diff --git a/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/2/main.tf b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/2/main.tf new file mode 100644 index 00000000..3cd50929 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/2/main.tf @@ -0,0 +1,16 @@ +data "junos_interface_physical" "testacc_interface" { + config_interface = var.interface +} +resource "junos_interface_physical" "testacc_interface" { + name = var.interface + description = "testacc_interface" + storm_control = junos_forwardingoptions_storm_control_profile.testacc_interface.name + trunk = true + vlan_native = 100 + vlan_members = ["100-110"] +} + +resource "junos_forwardingoptions_storm_control_profile" "testacc_interface" { + name = "testacc interface" + all {} +} diff --git a/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/2/variables.tf b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/2/variables.tf new file mode 100644 index 00000000..d5ed041c --- /dev/null +++ b/internal/providerfwk/testdata/TestAccDataSourceInterfacePhysical_switch/2/variables.tf @@ -0,0 +1,3 @@ +variable "interface" { + type = string +} From b36b9d6e38eac25634916706b0e4f279f17eed62 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Tue, 5 Dec 2023 20:38:06 +0100 Subject: [PATCH 16/43] d/interface_physical: reorder Schema keys to be same to Attributes and Blocks in resource --- .../data_source_interface_physical.go | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/internal/providerfwk/data_source_interface_physical.go b/internal/providerfwk/data_source_interface_physical.go index c62f9b1d..142186de 100644 --- a/internal/providerfwk/data_source_interface_physical.go +++ b/internal/providerfwk/data_source_interface_physical.go @@ -125,6 +125,51 @@ func (dsc *interfacePhysicalDataSource) Schema( Computed: true, Description: "Link operational mode.", }, + "mtu": schema.Int64Attribute{ + Computed: true, + Description: "Maximum transmission unit.", + }, + "no_gratuitous_arp_reply": schema.BoolAttribute{ + Computed: true, + Description: "Don't enable gratuitous ARP reply.", + }, + "no_gratuitous_arp_request": schema.BoolAttribute{ + Computed: true, + Description: "Ignore gratuitous ARP request.", + }, + "speed": schema.StringAttribute{ + Computed: true, + Description: "Link speed.", + }, + "storm_control": schema.StringAttribute{ + Computed: true, + Description: "Storm control profile name to bind.", + }, + "trunk": schema.BoolAttribute{ + Computed: true, + Description: "Interface mode is trunk.", + }, + "trunk_non_els": schema.BoolAttribute{ + Computed: true, + Description: "Port mode is trunk.", + }, + "vlan_members": schema.ListAttribute{ + ElementType: types.StringType, + Computed: true, + Description: "List of vlan membership for this interface.", + }, + "vlan_native": schema.Int64Attribute{ + Computed: true, + Description: "Vlan for untagged frames.", + }, + "vlan_native_non_els": schema.StringAttribute{ + Computed: true, + Description: "Vlan for untagged frames (non-ELS).", + }, + "vlan_tagging": schema.BoolAttribute{ + Computed: true, + Description: "802.1q VLAN tagging support.", + }, "esi": schema.ObjectAttribute{ Computed: true, Description: "ESI Config parameters.", @@ -164,22 +209,20 @@ func (dsc *interfacePhysicalDataSource) Schema( "redundant_parent": types.StringType, }, }, - "mtu": schema.Int64Attribute{ - Computed: true, - Description: "Maximum transmission unit.", - }, - "no_gratuitous_arp_reply": schema.BoolAttribute{ - Computed: true, - Description: "Don't enable gratuitous ARP reply.", - }, - "no_gratuitous_arp_request": schema.BoolAttribute{ - Computed: true, - Description: "Ignore gratuitous ARP request.", - }, "parent_ether_opts": schema.ObjectAttribute{ Computed: true, Description: "The `aggregated-ether-options` or `redundant-ether-options` configuration.", AttributeTypes: map[string]attr.Type{ + "flow_control": types.BoolType, + "no_flow_control": types.BoolType, + "loopback": types.BoolType, + "no_loopback": types.BoolType, + "link_speed": types.StringType, + "minimum_bandwidth": types.StringType, + "minimum_links": types.Int64Type, + "redundancy_group": types.Int64Type, + "source_address_filter": types.ListType{}.WithElementType(types.StringType), + "source_filtering": types.BoolType, "bfd_liveness_detection": types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ "local_address": types.StringType, "authentication_algorithm": types.StringType, @@ -196,8 +239,6 @@ func (dsc *interfacePhysicalDataSource) Schema( "transmit_interval_threshold": types.Int64Type, "version": types.StringType, }), - "flow_control": types.BoolType, - "no_flow_control": types.BoolType, "lacp": types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ "mode": types.StringType, "admin_key": types.Int64Type, @@ -206,9 +247,6 @@ func (dsc *interfacePhysicalDataSource) Schema( "system_id": types.StringType, "system_priority": types.Int64Type, }), - "loopback": types.BoolType, - "no_loopback": types.BoolType, - "link_speed": types.StringType, "mc_ae": types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ "chassis_id": types.Int64Type, "mc_ae_id": types.Int64Type, @@ -224,46 +262,8 @@ func (dsc *interfacePhysicalDataSource) Schema( "prefer_status_control_active": types.BoolType, }), }), - "minimum_bandwidth": types.StringType, - "minimum_links": types.Int64Type, - "redundancy_group": types.Int64Type, - "source_address_filter": types.ListType{}.WithElementType(types.StringType), - "source_filtering": types.BoolType, }, }, - "speed": schema.StringAttribute{ - Computed: true, - Description: "Link speed.", - }, - "storm_control": schema.StringAttribute{ - Computed: true, - Description: "Storm control profile name to bind.", - }, - "trunk": schema.BoolAttribute{ - Computed: true, - Description: "Interface mode is trunk.", - }, - "trunk_non_els": schema.BoolAttribute{ - Computed: true, - Description: "Port mode is trunk.", - }, - "vlan_members": schema.ListAttribute{ - ElementType: types.StringType, - Computed: true, - Description: "List of vlan membership for this interface.", - }, - "vlan_native": schema.Int64Attribute{ - Computed: true, - Description: "Vlan for untagged frames.", - }, - "vlan_native_non_els": schema.StringAttribute{ - Computed: true, - Description: "Vlan for untagged frames (non-ELS).", - }, - "vlan_tagging": schema.BoolAttribute{ - Computed: true, - Description: "802.1q VLAN tagging support.", - }, }, } } From 3c1572197afbca0943202e3d129c4cb1bb109d6a Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Tue, 5 Dec 2023 20:38:57 +0100 Subject: [PATCH 17/43] d/interface_logical: reorder Schema keys to be same to Attributes and Blocks in resource --- .../data_source_interface_logical.go | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/internal/providerfwk/data_source_interface_logical.go b/internal/providerfwk/data_source_interface_logical.go index c4a9c815..678351d5 100644 --- a/internal/providerfwk/data_source_interface_logical.go +++ b/internal/providerfwk/data_source_interface_logical.go @@ -102,10 +102,37 @@ func (dsc *interfaceLogicalDataSource) Schema( Computed: true, Description: "Interface disabled.", }, + "routing_instance": schema.StringAttribute{ + Computed: true, + Description: "Routing_instance where the interface is.", + }, + "security_inbound_protocols": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + Description: "The inbound protocols allowed.", + }, + "security_inbound_services": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + Description: "The inbound services allowed.", + }, + "security_zone": schema.StringAttribute{ + Computed: true, + Description: "Security zone where the interface is.", + }, + "vlan_id": schema.Int64Attribute{ + Computed: true, + Description: "Virtual LAN identifier value for 802.1q VLAN tags.", + }, "family_inet": schema.ObjectAttribute{ Computed: true, Description: "Family inet enabled and possible configuration.", AttributeTypes: map[string]attr.Type{ + "filter_input": types.StringType, + "filter_output": types.StringType, + "mtu": types.Int64Type, + "sampling_input": types.BoolType, + "sampling_output": types.BoolType, "address": types.ListType{}.WithElementType(types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ "cidr_ip": types.StringType, "preferred": types.BoolType, @@ -114,13 +141,13 @@ func (dsc *interfaceLogicalDataSource) Schema( "identifier": types.Int64Type, "virtual_address": types.ListType{}.WithElementType(types.StringType), "accept_data": types.BoolType, + "no_accept_data": types.BoolType, "advertise_interval": types.Int64Type, "advertisements_threshold": types.Int64Type, "authentication_key": types.StringType, "authentication_type": types.StringType, - "no_accept_data": types.BoolType, - "no_preempt": types.BoolType, "preempt": types.BoolType, + "no_preempt": types.BoolType, "priority": types.Int64Type, "track_interface": types.ListType{}.WithElementType(types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ "interface": types.StringType, @@ -154,21 +181,22 @@ func (dsc *interfaceLogicalDataSource) Schema( "update_server": types.BoolType, "vendor_id": types.StringType, }), - "filter_input": types.StringType, - "filter_output": types.StringType, - "mtu": types.Int64Type, "rpf_check": types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ "fail_filter": types.StringType, "mode_loose": types.BoolType, }), - "sampling_input": types.BoolType, - "sampling_output": types.BoolType, }, }, "family_inet6": schema.ObjectAttribute{ Computed: true, Description: "Family inet6 enabled and possible configuration.", AttributeTypes: map[string]attr.Type{ + "dad_disable": types.BoolType, + "filter_input": types.StringType, + "filter_output": types.StringType, + "mtu": types.Int64Type, + "sampling_input": types.BoolType, + "sampling_output": types.BoolType, "address": types.ListType{}.WithElementType(types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ "cidr_ip": types.StringType, "preferred": types.BoolType, @@ -178,11 +206,11 @@ func (dsc *interfaceLogicalDataSource) Schema( "virtual_address": types.ListType{}.WithElementType(types.StringType), "virtual_link_local_address": types.StringType, "accept_data": types.BoolType, + "no_accept_data": types.BoolType, "advertise_interval": types.Int64Type, "advertisements_threshold": types.Int64Type, - "no_accept_data": types.BoolType, - "no_preempt": types.BoolType, "preempt": types.BoolType, + "no_preempt": types.BoolType, "priority": types.Int64Type, "track_interface": types.ListType{}.WithElementType(types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ "interface": types.StringType, @@ -195,7 +223,6 @@ func (dsc *interfaceLogicalDataSource) Schema( })), })), })), - "dad_disable": types.BoolType, "dhcpv6_client": types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ "client_identifier_duid_type": types.StringType, "client_type": types.StringType, @@ -210,35 +237,12 @@ func (dsc *interfaceLogicalDataSource) Schema( "update_router_advertisement_interface": types.SetType{}.WithElementType(types.StringType), "update_server": types.BoolType, }), - "filter_input": types.StringType, - "filter_output": types.StringType, - "mtu": types.Int64Type, "rpf_check": types.ObjectType{}.WithAttributeTypes(map[string]attr.Type{ "fail_filter": types.StringType, "mode_loose": types.BoolType, }), - "sampling_input": types.BoolType, - "sampling_output": types.BoolType, }, }, - "routing_instance": schema.StringAttribute{ - Computed: true, - Description: "Routing_instance where the interface is.", - }, - "security_inbound_protocols": schema.SetAttribute{ - ElementType: types.StringType, - Computed: true, - Description: "The inbound protocols allowed.", - }, - "security_inbound_services": schema.SetAttribute{ - ElementType: types.StringType, - Computed: true, - Description: "The inbound services allowed.", - }, - "security_zone": schema.StringAttribute{ - Computed: true, - Description: "Security zone where the interface is.", - }, "tunnel": schema.ObjectAttribute{ Computed: true, Description: "Tunnel parameters.", @@ -248,17 +252,13 @@ func (dsc *interfaceLogicalDataSource) Schema( "allow_fragmentation": types.BoolType, "do_not_fragment": types.BoolType, "flow_label": types.Int64Type, - "no_path_mtu_discovery": types.BoolType, "path_mtu_discovery": types.BoolType, + "no_path_mtu_discovery": types.BoolType, "routing_instance_destination": types.StringType, "traffic_class": types.Int64Type, "ttl": types.Int64Type, }, }, - "vlan_id": schema.Int64Attribute{ - Computed: true, - Description: "Virtual LAN identifier value for 802.1q VLAN tags.", - }, }, } } From f1ecfb4afe4f7692d5bf64a9cd6f00a603152636 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Dec 2023 00:40:03 +0000 Subject: [PATCH 18/43] workflows: bump actions/setup-go from 4 to 5 Bumps [actions/setup-go](https://github.com/actions/setup-go) from 4 to 5. - [Release notes](https://github.com/actions/setup-go/releases) - [Commits](https://github.com/actions/setup-go/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/setup-go dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/go.yml | 6 +++--- .github/workflows/linters.yml | 4 ++-- .github/workflows/releases.yml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d65dbcf9..f8cc70e4 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up Go 1.20 - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.20' check-latest: true @@ -26,7 +26,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up Go 1.21 - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.21' check-latest: true @@ -46,7 +46,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up Go 1.21 - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.21' check-latest: true diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 764af103..775da3f8 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up Go 1.21 - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.21' check-latest: true @@ -39,7 +39,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up Go 1.21 - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.21' check-latest: true diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index e3b06c83..5f33859d 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -39,7 +39,7 @@ jobs: goarch: arm64 steps: - name: Set up Go 1.21 - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '^1.21.4' check-latest: true From 63364052335d1e2c9193603a4ffc29375495d185 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Thu, 7 Dec 2023 09:01:28 +0100 Subject: [PATCH 19/43] r/interface_physical: fix future changelog --- .changes/issue-572.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/issue-572.md b/.changes/issue-572.md index 14639bd3..ab50e0e6 100644 --- a/.changes/issue-572.md +++ b/.changes/issue-572.md @@ -1,7 +1,7 @@ ENHANCEMENTS: -* **resource/junos_interface_physical**: add `mc_ae` block argument in `parent_ether_opts` block (Partial fix [#572](https://github.com/jeremmfr/terraform-provider-junos/issues/572)) +* **resource/junos_interface_physical**: add `mc_ae` block argument in `parent_ether_opts` block (Fix [#572](https://github.com/jeremmfr/terraform-provider-junos/issues/572)) * **data-source/junos_interface_physical**: add `mc_ae` block attribute in `parent_ether_opts` block BUG FIXES: From e9dfa59547d91b0924acd3c6cc0ced6b2966b2ab Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Thu, 7 Dec 2023 09:41:28 +0100 Subject: [PATCH 20/43] workflows: Release: remove patch in go-version to setup go --- .github/workflows/releases.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index 5f33859d..3891b85d 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -41,7 +41,7 @@ jobs: - name: Set up Go 1.21 uses: actions/setup-go@v5 with: - go-version: '^1.21.4' + go-version: '1.21' check-latest: true id: go - name: Show version From 69e855e2e1e73ec0be542431bbdf6228a7b559f0 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Mon, 11 Dec 2023 08:53:15 +0100 Subject: [PATCH 21/43] r/iccp_peer: fix path on a potential diagnostics error in create --- internal/providerfwk/resource_iccp_peer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/providerfwk/resource_iccp_peer.go b/internal/providerfwk/resource_iccp_peer.go index 354c32ae..1431c9c9 100644 --- a/internal/providerfwk/resource_iccp_peer.go +++ b/internal/providerfwk/resource_iccp_peer.go @@ -298,7 +298,7 @@ func (rsc *iccpPeer) Create( } if plan.IPAddress.ValueString() == "" { resp.Diagnostics.AddAttributeError( - path.Root("peer_ip_address"), + path.Root("ip_address"), "Empty IP Address", defaultResourceCouldNotCreateWithEmptyMessage(rsc, "ip_address"), ) From c8d88a6eb6643b1dbcbf7f652ef149383c48e0de Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Mon, 11 Dec 2023 09:34:09 +0100 Subject: [PATCH 22/43] r/security_ipsec_vpn: fix no diagnostics read when setting the modified plan in ModifyPlan resource function --- internal/providerfwk/resource_security_ipsec_vpn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/providerfwk/resource_security_ipsec_vpn.go b/internal/providerfwk/resource_security_ipsec_vpn.go index da2b3a98..91251573 100644 --- a/internal/providerfwk/resource_security_ipsec_vpn.go +++ b/internal/providerfwk/resource_security_ipsec_vpn.go @@ -674,7 +674,7 @@ func (rsc *securityIpsecVpn) ModifyPlan( } } - resp.Plan.Set(ctx, plan) + resp.Diagnostics.Append(resp.Plan.Set(ctx, &plan)...) } func (rsc *securityIpsecVpn) Create( From 8cafa3a789ee08e1abd8c144501e21bc17dad90f Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Mon, 11 Dec 2023 10:18:59 +0100 Subject: [PATCH 23/43] add junos_multichassis resource Partial fix #576 --- .changes/issue-576.md | 4 + docs/resources/multichassis.md | 47 +++ internal/providerfwk/provider.go | 1 + internal/providerfwk/resource_multichassis.go | 338 ++++++++++++++++++ .../providerfwk/resource_multichassis_test.go | 34 ++ .../1/main.tf | 1 + .../2/main.tf | 3 + .../4/main.tf | 4 + 8 files changed, 432 insertions(+) create mode 100644 .changes/issue-576.md create mode 100644 docs/resources/multichassis.md create mode 100644 internal/providerfwk/resource_multichassis.go create mode 100644 internal/providerfwk/resource_multichassis_test.go create mode 100644 internal/providerfwk/testdata/TestAccResourceMultichassis_basic/1/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceMultichassis_basic/2/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceMultichassis_basic/4/main.tf diff --git a/.changes/issue-576.md b/.changes/issue-576.md new file mode 100644 index 00000000..daab8e17 --- /dev/null +++ b/.changes/issue-576.md @@ -0,0 +1,4 @@ + +FEATURES: + +* add `junos_multichassis` resource (Partial fix [#576](https://github.com/jeremmfr/terraform-provider-junos/issues/576)) diff --git a/docs/resources/multichassis.md b/docs/resources/multichassis.md new file mode 100644 index 00000000..1f622cdb --- /dev/null +++ b/docs/resources/multichassis.md @@ -0,0 +1,47 @@ +--- +page_title: "Junos: junos_multichassis" +--- + +# junos_multichassis + +-> **Note:** This resource should only be created **once**. +It's used to configure static (not object) options in `multi-chassis` block. +By default (without `clean_on_destroy` = true), destroy this resource has no effect on the Junos configuration. + +Configure static configuration in `multi-chassis` block. + +## Example Usage + +```hcl +# Configure multi-chassis +resource "junos_multichassis" "multichassis" { + mc_lag_consistency_check = true +} +``` + +## Argument Reference + +The following arguments are supported: + +- **clean_on_destroy** (Optional, Boolean) + Clean entirely `multi-chassis` block when destroy this resource. +- **mc_lag_consistency_check** (Optional, Computed, Boolean) + Consistency Check. + Computed to set to `true` when `mc_lag_consistency_check_comparison_delay_time` is specified. +- **mc_lag_consistency_check_comparison_delay_time** (Optional, Number) + Time after which local and remote config are compared (5..600 seconds). + +## Attributes Reference + +The following attributes are exported: + +- **id** (String) + An identifier for the resource with value `multichassis`. + +## Import + +Junos multi-chassis can be imported using any id, e.g. + +```shell +$ terraform import junos_multichassis.multichassis random +``` diff --git a/internal/providerfwk/provider.go b/internal/providerfwk/provider.go index 5191b090..6810ebae 100644 --- a/internal/providerfwk/provider.go +++ b/internal/providerfwk/provider.go @@ -219,6 +219,7 @@ func (p *junosProvider) Resources(_ context.Context) []func() resource.Resource newInterfacePhysicalDisableResource, newInterfacePhysicalResource, newInterfaceSt0UnitResource, + newMultichassisResource, newOamGretunnelInterfaceResource, newPolicyoptionsASPathResource, newPolicyoptionsASPathGroupResource, diff --git a/internal/providerfwk/resource_multichassis.go b/internal/providerfwk/resource_multichassis.go new file mode 100644 index 00000000..9d3c0003 --- /dev/null +++ b/internal/providerfwk/resource_multichassis.go @@ -0,0 +1,338 @@ +package providerfwk + +import ( + "context" + "strings" + + "github.com/jeremmfr/terraform-provider-junos/internal/junos" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdata" + "github.com/jeremmfr/terraform-provider-junos/internal/tfvalidator" + "github.com/jeremmfr/terraform-provider-junos/internal/utils" + + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + balt "github.com/jeremmfr/go-utils/basicalter" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ resource.Resource = &multichassis{} + _ resource.ResourceWithConfigure = &multichassis{} + _ resource.ResourceWithModifyPlan = &multichassis{} + _ resource.ResourceWithImportState = &multichassis{} +) + +type multichassis struct { + client *junos.Client +} + +func newMultichassisResource() resource.Resource { + return &multichassis{} +} + +func (rsc *multichassis) typeName() string { + return providerName + "_multichassis" +} + +func (rsc *multichassis) junosName() string { + return "multi-chassis" +} + +func (rsc *multichassis) junosClient() *junos.Client { + return rsc.client +} + +func (rsc *multichassis) Metadata( + _ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse, +) { + resp.TypeName = rsc.typeName() +} + +func (rsc *multichassis) Configure( + ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse, +) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + client, ok := req.ProviderData.(*junos.Client) + if !ok { + unexpectedResourceConfigureType(ctx, req, resp) + + return + } + rsc.client = client +} + +func (rsc *multichassis) Schema( + _ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse, +) { + resp.Schema = schema.Schema{ + Description: "Configure static configuration in `" + rsc.junosName() + "` block", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "An identifier for the resource with value " + + "`multichassis`.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "clean_on_destroy": schema.BoolAttribute{ + Optional: true, + Description: "Clean entirely `" + rsc.junosName() + "` block when destroy this resource.", + }, + "mc_lag_consistency_check": schema.BoolAttribute{ + Optional: true, + Computed: true, + Description: "Consistency Check.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "mc_lag_consistency_check_comparison_delay_time": schema.Int64Attribute{ + Optional: true, + Description: "Time after which local and remote config are compared (seconds).", + Validators: []validator.Int64{ + int64validator.Between(5, 600), + }, + }, + }, + } +} + +type multichassisData struct { + CleanOnDestroy types.Bool `tfsdk:"clean_on_destroy"` + MCLagConsistencyCheck types.Bool `tfsdk:"mc_lag_consistency_check"` + ID types.String `tfsdk:"id"` + MCLagConsistencyCheckComparaisonDelayTime types.Int64 `tfsdk:"mc_lag_consistency_check_comparison_delay_time"` +} + +func (rsc *multichassis) ModifyPlan( + ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse, +) { + if req.Plan.Raw.IsNull() { + return + } + + var config, plan multichassisData + resp.Diagnostics.Append(req.Config.Get(ctx, &config)...) + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + if config.MCLagConsistencyCheck.IsNull() { + if config.MCLagConsistencyCheckComparaisonDelayTime.IsNull() { + plan.MCLagConsistencyCheck = types.BoolNull() + } else if !plan.MCLagConsistencyCheckComparaisonDelayTime.IsNull() && + !plan.MCLagConsistencyCheckComparaisonDelayTime.IsUnknown() { + plan.MCLagConsistencyCheck = types.BoolValue(true) + } + } + + resp.Diagnostics.Append(resp.Plan.Set(ctx, &plan)...) +} + +func (rsc *multichassis) Create( + ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse, +) { + var plan multichassisData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + if plan.MCLagConsistencyCheck.IsUnknown() { + plan.MCLagConsistencyCheck = types.BoolNull() + if !plan.MCLagConsistencyCheckComparaisonDelayTime.IsNull() { + plan.MCLagConsistencyCheck = types.BoolValue(true) + } + } + + defaultResourceCreate( + ctx, + rsc, + nil, + nil, + &plan, + resp, + ) +} + +func (rsc *multichassis) Read( + ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse, +) { + var state, data multichassisData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + var _ resourceDataReadFrom0String = &data + defaultResourceRead( + ctx, + rsc, + nil, + &data, + func() { + data.CleanOnDestroy = state.CleanOnDestroy + }, + resp, + ) +} + +func (rsc *multichassis) Update( + ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse, +) { + var plan, state multichassisData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + if plan.MCLagConsistencyCheck.IsUnknown() { + plan.MCLagConsistencyCheck = types.BoolNull() + if !plan.MCLagConsistencyCheckComparaisonDelayTime.IsNull() { + plan.MCLagConsistencyCheck = types.BoolValue(true) + } + } + + var _ resourceDataDelWithOpts = &state + defaultResourceUpdate( + ctx, + rsc, + &state, + &plan, + resp, + ) +} + +func (rsc *multichassis) Delete( + ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse, +) { + var state multichassisData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + if state.CleanOnDestroy.ValueBool() { + defaultResourceDelete( + ctx, + rsc, + &state, + resp, + ) + } +} + +func (rsc *multichassis) ImportState( + ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse, +) { + var data multichassisData + + var _ resourceDataReadFrom0String = &data + defaultResourceImportState( + ctx, + rsc, + &data, + req, + resp, + "the `"+rsc.junosName()+"` block is not configured on device", + ) +} + +func (rscData *multichassisData) fillID() { + rscData.ID = types.StringValue("multichassis") +} + +func (rscData *multichassisData) nullID() bool { + return rscData.ID.IsNull() +} + +func (rscData *multichassisData) set( + _ context.Context, junSess *junos.Session, +) ( + path.Path, error, +) { + setPrefix := "set multi-chassis " + configSet := []string{ + setPrefix, + } + + if rscData.MCLagConsistencyCheck.ValueBool() { + configSet = append(configSet, setPrefix+"mc-lag consistency-check") + } + if !rscData.MCLagConsistencyCheckComparaisonDelayTime.IsNull() { + configSet = append(configSet, setPrefix+"mc-lag consistency-check comparison-delay-time "+ + utils.ConvI64toa(rscData.MCLagConsistencyCheckComparaisonDelayTime.ValueInt64())) + } + + return path.Empty(), junSess.ConfigSet(configSet) +} + +func (rscData *multichassisData) read( + _ context.Context, junSess *junos.Session, +) ( + err error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "multi-chassis" + junos.PipeDisplaySetRelative) + if err != nil { + return err + } + + if showConfig != junos.EmptyW { + rscData.fillID() + for _, item := range strings.Split(showConfig, "\n") { + if strings.Contains(item, junos.XMLStartTagConfigOut) { + continue + } + if strings.Contains(item, junos.XMLEndTagConfigOut) { + break + } + itemTrim := strings.TrimPrefix(item, junos.SetLS) + if balt.CutPrefixInString(&itemTrim, "mc-lag consistency-check") { + rscData.MCLagConsistencyCheck = types.BoolValue(true) + if balt.CutPrefixInString(&itemTrim, " comparison-delay-time ") { + rscData.MCLagConsistencyCheckComparaisonDelayTime, err = tfdata.ConvAtoi64Value(itemTrim) + if err != nil { + return err + } + } + } + } + } + + return nil +} + +func (rscData *multichassisData) delOpts( + _ context.Context, junSess *junos.Session, +) error { + delPrefix := "delete multi-chassis " + + configSet := []string{ + delPrefix + "mc-lag", + } + + return junSess.ConfigSet(configSet) +} + +func (rscData *multichassisData) del( + _ context.Context, junSess *junos.Session, +) error { + configSet := []string{ + "delete multi-chassis", + } + + return junSess.ConfigSet(configSet) +} diff --git a/internal/providerfwk/resource_multichassis_test.go b/internal/providerfwk/resource_multichassis_test.go new file mode 100644 index 00000000..ed6eac04 --- /dev/null +++ b/internal/providerfwk/resource_multichassis_test.go @@ -0,0 +1,34 @@ +package providerfwk_test + +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccResourceMultichassis_basic(t *testing.T) { + if os.Getenv("TESTACC_ROUTER") != "" { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestStepDirectory(), + }, + { + ConfigDirectory: config.TestStepDirectory(), + }, + { + ResourceName: "junos_multichassis.testacc_multichassis", + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.TestStepDirectory(), + }, + }, + }) + } +} diff --git a/internal/providerfwk/testdata/TestAccResourceMultichassis_basic/1/main.tf b/internal/providerfwk/testdata/TestAccResourceMultichassis_basic/1/main.tf new file mode 100644 index 00000000..2a49c5af --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceMultichassis_basic/1/main.tf @@ -0,0 +1 @@ +resource "junos_multichassis" "testacc_multichassis" {} diff --git a/internal/providerfwk/testdata/TestAccResourceMultichassis_basic/2/main.tf b/internal/providerfwk/testdata/TestAccResourceMultichassis_basic/2/main.tf new file mode 100644 index 00000000..dad2ece2 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceMultichassis_basic/2/main.tf @@ -0,0 +1,3 @@ +resource "junos_multichassis" "testacc_multichassis" { + mc_lag_consistency_check = true +} diff --git a/internal/providerfwk/testdata/TestAccResourceMultichassis_basic/4/main.tf b/internal/providerfwk/testdata/TestAccResourceMultichassis_basic/4/main.tf new file mode 100644 index 00000000..8cfd2be5 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceMultichassis_basic/4/main.tf @@ -0,0 +1,4 @@ +resource "junos_multichassis" "testacc_multichassis" { + clean_on_destroy = true + mc_lag_consistency_check_comparison_delay_time = 180 +} From 2ab92e8266c49f98cb7d933b792211398d5a7874 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Mon, 11 Dec 2023 10:21:08 +0100 Subject: [PATCH 24/43] add junos_multichassis_protection_peer resource Partial fix #576 --- .changes/issue-576.md | 1 + docs/resources/multichassis.md | 1 + .../resources/multichassis_protection_peer.md | 44 +++ internal/providerfwk/provider.go | 1 + .../resource_multichassis_protection_peer.go | 347 ++++++++++++++++++ ...ource_multichassis_protection_peer_test.go | 46 +++ .../1/main.tf | 22 ++ .../1/variables.tf | 3 + .../2/main.tf | 25 ++ .../2/variables.tf | 3 + 10 files changed, 493 insertions(+) create mode 100644 docs/resources/multichassis_protection_peer.md create mode 100644 internal/providerfwk/resource_multichassis_protection_peer.go create mode 100644 internal/providerfwk/resource_multichassis_protection_peer_test.go create mode 100644 internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/1/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/1/variables.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/2/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/2/variables.tf diff --git a/.changes/issue-576.md b/.changes/issue-576.md index daab8e17..00c1589c 100644 --- a/.changes/issue-576.md +++ b/.changes/issue-576.md @@ -2,3 +2,4 @@ FEATURES: * add `junos_multichassis` resource (Partial fix [#576](https://github.com/jeremmfr/terraform-provider-junos/issues/576)) +* add `junos_multichassis_protection_peer` resource (Partial fix [#576](https://github.com/jeremmfr/terraform-provider-junos/issues/576)) diff --git a/docs/resources/multichassis.md b/docs/resources/multichassis.md index 1f622cdb..d308fef8 100644 --- a/docs/resources/multichassis.md +++ b/docs/resources/multichassis.md @@ -25,6 +25,7 @@ The following arguments are supported: - **clean_on_destroy** (Optional, Boolean) Clean entirely `multi-chassis` block when destroy this resource. + It includes potential `junos_multichassis_protection_peer` resources. - **mc_lag_consistency_check** (Optional, Computed, Boolean) Consistency Check. Computed to set to `true` when `mc_lag_consistency_check_comparison_delay_time` is specified. diff --git a/docs/resources/multichassis_protection_peer.md b/docs/resources/multichassis_protection_peer.md new file mode 100644 index 00000000..951e9347 --- /dev/null +++ b/docs/resources/multichassis_protection_peer.md @@ -0,0 +1,44 @@ +--- +page_title: "Junos: junos_multichassis_protection_peer" +--- + +# junos_multichassis_protection_peer + +Provides a multi-chassis inter-chassis protection peer resource. + +## Example Usage + +```hcl +# Add a multi-chassis inter-chassis protection peer +resource "junos_multichassis_protection_peer" "peer1" { + ip_address = "192.0.2.1" + interface = "ge-0/0/3" +} +``` + +## Argument Reference + +The following arguments are supported: + +- **ip_address** (Required, String) + IP address for this peer. +- **interface** (Required, String) + Inter-Chassis protection link. +- **icl_down_delay** (Optional, Number) + Time in seconds between ICL down and MCAEs moving to standby (1..6000 seconds). + +## Attributes Reference + +The following attributes are exported: + +- **id** (String) + An identifier for the resource with format ``. + +## Import + +Junos multi-chassis inter-chassis protection peer can be imported using an id made up of +``, e.g. + +```shell +$ terraform import junos_multichassis_protection_peer.peer1 192.0.2.1 +``` diff --git a/internal/providerfwk/provider.go b/internal/providerfwk/provider.go index 6810ebae..a9dae8a6 100644 --- a/internal/providerfwk/provider.go +++ b/internal/providerfwk/provider.go @@ -220,6 +220,7 @@ func (p *junosProvider) Resources(_ context.Context) []func() resource.Resource newInterfacePhysicalResource, newInterfaceSt0UnitResource, newMultichassisResource, + newMultichassisProtectionPeerResource, newOamGretunnelInterfaceResource, newPolicyoptionsASPathResource, newPolicyoptionsASPathGroupResource, diff --git a/internal/providerfwk/resource_multichassis_protection_peer.go b/internal/providerfwk/resource_multichassis_protection_peer.go new file mode 100644 index 00000000..dbb2e8ef --- /dev/null +++ b/internal/providerfwk/resource_multichassis_protection_peer.go @@ -0,0 +1,347 @@ +package providerfwk + +import ( + "context" + "strings" + + "github.com/jeremmfr/terraform-provider-junos/internal/junos" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdata" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdiag" + "github.com/jeremmfr/terraform-provider-junos/internal/tfvalidator" + "github.com/jeremmfr/terraform-provider-junos/internal/utils" + + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + balt "github.com/jeremmfr/go-utils/basicalter" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ resource.Resource = &multichassisProtectionPeer{} + _ resource.ResourceWithConfigure = &multichassisProtectionPeer{} + _ resource.ResourceWithImportState = &multichassisProtectionPeer{} +) + +type multichassisProtectionPeer struct { + client *junos.Client +} + +func newMultichassisProtectionPeerResource() resource.Resource { + return &multichassisProtectionPeer{} +} + +func (rsc *multichassisProtectionPeer) typeName() string { + return providerName + "_multichassis_protection_peer" +} + +func (rsc *multichassisProtectionPeer) junosName() string { + return "multi-chassis multi-chassis-protection" +} + +func (rsc *multichassisProtectionPeer) junosClient() *junos.Client { + return rsc.client +} + +func (rsc *multichassisProtectionPeer) Metadata( + _ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse, +) { + resp.TypeName = rsc.typeName() +} + +func (rsc *multichassisProtectionPeer) Configure( + ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse, +) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + client, ok := req.ProviderData.(*junos.Client) + if !ok { + unexpectedResourceConfigureType(ctx, req, resp) + + return + } + rsc.client = client +} + +func (rsc *multichassisProtectionPeer) Schema( + _ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse, +) { + resp.Schema = schema.Schema{ + Description: defaultResourceSchemaDescription(rsc), + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "An identifier for the resource with format ``.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "ip_address": schema.StringAttribute{ + Required: true, + Description: "IP address for this peer.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + tfvalidator.StringIPAddress().IPv4Only(), + }, + }, + "interface": schema.StringAttribute{ + Required: true, + Description: "Inter-Chassis protection link.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + tfvalidator.StringFormat(tfvalidator.InterfaceFormat), + }, + }, + "icl_down_delay": schema.Int64Attribute{ + Optional: true, + Description: "Time in seconds between ICL down and MCAEs moving to standby (seconds).", + Validators: []validator.Int64{ + int64validator.Between(1, 6000), + }, + }, + }, + } +} + +type multichassisProtectionPeerData struct { + ID types.String `tfsdk:"id"` + IPAddress types.String `tfsdk:"ip_address"` + Interface types.String `tfsdk:"interface"` + IclDownDelay types.Int64 `tfsdk:"icl_down_delay"` +} + +func (rsc *multichassisProtectionPeer) Create( + ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse, +) { + var plan multichassisProtectionPeerData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + if plan.IPAddress.ValueString() == "" { + resp.Diagnostics.AddAttributeError( + path.Root("ip_address"), + "Empty IP Address", + defaultResourceCouldNotCreateWithEmptyMessage(rsc, "ip_address"), + ) + + return + } + + defaultResourceCreate( + ctx, + rsc, + func(fnCtx context.Context, junSess *junos.Session) bool { + peerExists, err := checkMultichassisProtectionPeerExists(fnCtx, plan.IPAddress.ValueString(), junSess) + if err != nil { + resp.Diagnostics.AddError(tfdiag.PreCheckErrSummary, err.Error()) + + return false + } + if peerExists { + resp.Diagnostics.AddError( + tfdiag.DuplicateConfigErrSummary, + defaultResourceAlreadyExistsMessage(rsc, plan.IPAddress), + ) + + return false + } + + return true + }, + func(fnCtx context.Context, junSess *junos.Session) bool { + peerExists, err := checkMultichassisProtectionPeerExists(fnCtx, plan.IPAddress.ValueString(), junSess) + if err != nil { + resp.Diagnostics.AddError(tfdiag.PostCheckErrSummary, err.Error()) + + return false + } + if !peerExists { + resp.Diagnostics.AddError( + tfdiag.NotFoundErrSummary, + defaultResourceDoesNotExistsAfterCommitMessage(rsc, plan.IPAddress), + ) + + return false + } + + return true + }, + &plan, + resp, + ) +} + +func (rsc *multichassisProtectionPeer) Read( + ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse, +) { + var state, data multichassisProtectionPeerData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + var _ resourceDataReadFrom1String = &data + defaultResourceRead( + ctx, + rsc, + []string{ + state.IPAddress.ValueString(), + }, + &data, + nil, + resp, + ) +} + +func (rsc *multichassisProtectionPeer) Update( + ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse, +) { + var plan, state multichassisProtectionPeerData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceUpdate( + ctx, + rsc, + &state, + &plan, + resp, + ) +} + +func (rsc *multichassisProtectionPeer) Delete( + ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse, +) { + var state multichassisProtectionPeerData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceDelete( + ctx, + rsc, + &state, + resp, + ) +} + +func (rsc *multichassisProtectionPeer) ImportState( + ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse, +) { + var data multichassisProtectionPeerData + + var _ resourceDataReadFrom1String = &data + defaultResourceImportState( + ctx, + rsc, + &data, + req, + resp, + defaultResourceImportDontFindIDStrMessage(rsc, req.ID, "ip_address"), + ) +} + +func checkMultichassisProtectionPeerExists( + _ context.Context, ipAddress string, junSess *junos.Session, +) ( + bool, error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "multi-chassis multi-chassis-protection " + ipAddress + junos.PipeDisplaySet) + if err != nil { + return false, err + } + if showConfig == junos.EmptyW { + return false, nil + } + + return true, nil +} + +func (rscData *multichassisProtectionPeerData) fillID() { + rscData.ID = types.StringValue(rscData.IPAddress.ValueString()) +} + +func (rscData *multichassisProtectionPeerData) nullID() bool { + return rscData.ID.IsNull() +} + +func (rscData *multichassisProtectionPeerData) set( + _ context.Context, junSess *junos.Session, +) ( + path.Path, error, +) { + setPrefix := "set multi-chassis multi-chassis-protection " + rscData.IPAddress.ValueString() + " " + configSet := []string{ + setPrefix, + setPrefix + "interface " + rscData.Interface.ValueString(), + } + + if !rscData.IclDownDelay.IsNull() { + configSet = append(configSet, setPrefix+"icl-down-delay "+ + utils.ConvI64toa(rscData.IclDownDelay.ValueInt64())) + } + + return path.Empty(), junSess.ConfigSet(configSet) +} + +func (rscData *multichassisProtectionPeerData) read( + _ context.Context, ipAddress string, junSess *junos.Session, +) ( + err error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "multi-chassis multi-chassis-protection " + ipAddress + junos.PipeDisplaySetRelative) + if err != nil { + return err + } + if showConfig != junos.EmptyW { + rscData.IPAddress = types.StringValue(ipAddress) + rscData.fillID() + for _, item := range strings.Split(showConfig, "\n") { + if strings.Contains(item, junos.XMLStartTagConfigOut) { + continue + } + if strings.Contains(item, junos.XMLEndTagConfigOut) { + break + } + itemTrim := strings.TrimPrefix(item, junos.SetLS) + switch { + case balt.CutPrefixInString(&itemTrim, "interface "): + rscData.Interface = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "icl-down-delay "): + rscData.IclDownDelay, err = tfdata.ConvAtoi64Value(itemTrim) + if err != nil { + return err + } + } + } + } + + return nil +} + +func (rscData *multichassisProtectionPeerData) del( + _ context.Context, junSess *junos.Session, +) error { + configSet := []string{ + "delete multi-chassis multi-chassis-protection " + rscData.IPAddress.ValueString(), + } + + return junSess.ConfigSet(configSet) +} diff --git a/internal/providerfwk/resource_multichassis_protection_peer_test.go b/internal/providerfwk/resource_multichassis_protection_peer_test.go new file mode 100644 index 00000000..1255f8d7 --- /dev/null +++ b/internal/providerfwk/resource_multichassis_protection_peer_test.go @@ -0,0 +1,46 @@ +package providerfwk_test + +import ( + "os" + "testing" + + "github.com/jeremmfr/terraform-provider-junos/internal/junos" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccResourceMultichassisProtectionPeer_basic(t *testing.T) { + testaccInterface := junos.DefaultInterfaceTestAcc + if iface := os.Getenv("TESTACC_INTERFACE"); iface != "" { + testaccInterface = iface + } + if os.Getenv("TESTACC_ROUTER") != "" { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestStepDirectory(), + ConfigVariables: map[string]config.Variable{ + "interface": config.StringVariable(testaccInterface), + }, + }, + { + ConfigDirectory: config.TestStepDirectory(), + ConfigVariables: map[string]config.Variable{ + "interface": config.StringVariable(testaccInterface), + }, + }, + { + ResourceName: "junos_multichassis_protection_peer.testacc_multichassis_protection_peer", + ImportState: true, + ImportStateVerify: true, + ConfigVariables: map[string]config.Variable{ + "interface": config.StringVariable(testaccInterface), + }, + }, + }, + }) + } +} diff --git a/internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/1/main.tf b/internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/1/main.tf new file mode 100644 index 00000000..f69da90f --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/1/main.tf @@ -0,0 +1,22 @@ +resource "junos_iccp" "testacc_multichassis_protection_peer" { + local_ip_addr = "192.0.2.1" +} + +resource "junos_iccp_peer" "testacc_multichassis_protection_peer" { + depends_on = [junos_iccp.testacc_multichassis_protection_peer] + + ip_address = "192.0.2.2" + redundancy_group_id_list = [101, 100] + + liveness_detection { + minimum_interval = 600 + } +} + +resource "junos_multichassis" "testacc_multichassis_protection_peer" {} + +resource "junos_multichassis_protection_peer" "testacc_multichassis_protection_peer" { + depends_on = [junos_multichassis.testacc_multichassis_protection_peer] + ip_address = junos_iccp_peer.testacc_multichassis_protection_peer.ip_address + interface = var.interface +} diff --git a/internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/1/variables.tf b/internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/1/variables.tf new file mode 100644 index 00000000..d5ed041c --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/1/variables.tf @@ -0,0 +1,3 @@ +variable "interface" { + type = string +} diff --git a/internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/2/main.tf b/internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/2/main.tf new file mode 100644 index 00000000..6b6c0043 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/2/main.tf @@ -0,0 +1,25 @@ +resource "junos_iccp" "testacc_multichassis_protection_peer" { + local_ip_addr = "192.0.2.1" +} + +resource "junos_iccp_peer" "testacc_multichassis_protection_peer" { + depends_on = [junos_iccp.testacc_multichassis_protection_peer] + + ip_address = "192.0.2.2" + redundancy_group_id_list = [101, 100] + + liveness_detection { + minimum_interval = 600 + } +} + +resource "junos_multichassis" "testacc_multichassis_protection_peer" { + clean_on_destroy = true +} + +resource "junos_multichassis_protection_peer" "testacc_multichassis_protection_peer" { + depends_on = [junos_multichassis.testacc_multichassis_protection_peer] + ip_address = junos_iccp_peer.testacc_multichassis_protection_peer.ip_address + interface = var.interface + icl_down_delay = 60 +} diff --git a/internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/2/variables.tf b/internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/2/variables.tf new file mode 100644 index 00000000..d5ed041c --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceMultichassisProtectionPeer_basic/2/variables.tf @@ -0,0 +1,3 @@ +variable "interface" { + type = string +} From 841c214e51775337093dc4213bbaadf38df4bca5 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Mon, 11 Dec 2023 11:31:45 +0100 Subject: [PATCH 25/43] r/switch_options: use new provider via framework --- .changes/issue-575.md | 7 + internal/providerfwk/provider.go | 1 + .../providerfwk/resource_switch_options.go | 270 ++++++++++++++++++ .../resource_switch_options_test.go | 31 ++ .../1/main.tf | 14 + .../3/main.tf | 1 + internal/providersdk/provider.go | 1 - .../providersdk/resource_switch_options.go | 266 ----------------- .../resource_switch_options_test.go | 56 ---- 9 files changed, 324 insertions(+), 323 deletions(-) create mode 100644 .changes/issue-575.md create mode 100644 internal/providerfwk/resource_switch_options.go create mode 100644 internal/providerfwk/resource_switch_options_test.go create mode 100644 internal/providerfwk/testdata/TestAccResourceSwitchOptions_basic/1/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceSwitchOptions_basic/3/main.tf delete mode 100644 internal/providersdk/resource_switch_options.go delete mode 100644 internal/providersdk/resource_switch_options_test.go diff --git a/.changes/issue-575.md b/.changes/issue-575.md new file mode 100644 index 00000000..480cbcde --- /dev/null +++ b/.changes/issue-575.md @@ -0,0 +1,7 @@ + +ENHANCEMENTS: + +* **resource/junos_switch_options**: + * resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) + optional boolean attributes doesn't accept value *false* + optional string attributes doesn't accept *empty* value diff --git a/internal/providerfwk/provider.go b/internal/providerfwk/provider.go index 5191b090..357aa4d8 100644 --- a/internal/providerfwk/provider.go +++ b/internal/providerfwk/provider.go @@ -249,6 +249,7 @@ func (p *junosProvider) Resources(_ context.Context) []func() resource.Resource newServicesFlowMonitoringV9TemplateResource, newServicesFlowMonitoringVIPFixTemplateResource, newStaticRouteResource, + newSwitchOptionsResource, newSystemResource, } } diff --git a/internal/providerfwk/resource_switch_options.go b/internal/providerfwk/resource_switch_options.go new file mode 100644 index 00000000..98006936 --- /dev/null +++ b/internal/providerfwk/resource_switch_options.go @@ -0,0 +1,270 @@ +package providerfwk + +import ( + "context" + "strings" + + "github.com/jeremmfr/terraform-provider-junos/internal/junos" + "github.com/jeremmfr/terraform-provider-junos/internal/tfvalidator" + + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + balt "github.com/jeremmfr/go-utils/basicalter" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ resource.Resource = &switchOptions{} + _ resource.ResourceWithConfigure = &switchOptions{} + _ resource.ResourceWithImportState = &switchOptions{} +) + +type switchOptions struct { + client *junos.Client +} + +func newSwitchOptionsResource() resource.Resource { + return &switchOptions{} +} + +func (rsc *switchOptions) typeName() string { + return providerName + "_switch_options" +} + +func (rsc *switchOptions) junosName() string { + return "switch-options" +} + +func (rsc *switchOptions) junosClient() *junos.Client { + return rsc.client +} + +func (rsc *switchOptions) Metadata( + _ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse, +) { + resp.TypeName = rsc.typeName() +} + +func (rsc *switchOptions) Configure( + ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse, +) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + client, ok := req.ProviderData.(*junos.Client) + if !ok { + unexpectedResourceConfigureType(ctx, req, resp) + + return + } + rsc.client = client +} + +func (rsc *switchOptions) Schema( + _ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse, +) { + resp.Schema = schema.Schema{ + Description: "Configure static configuration in `" + rsc.junosName() + "` block", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "An identifier for the resource with value `switch_options`.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "clean_on_destroy": schema.BoolAttribute{ + Optional: true, + Description: "Clean supported lines when destroy this resource.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "vtep_source_interface": schema.StringAttribute{ + Optional: true, + Description: "Source layer-3 IFL for VXLAN.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + tfvalidator.StringFormat(tfvalidator.InterfaceFormat), + tfvalidator.String1DotCount(), + }, + }, + }, + } +} + +type switchOptionsData struct { + CleanOnDestroy types.Bool `tfsdk:"clean_on_destroy"` + ID types.String `tfsdk:"id"` + VTEPSourceInterface types.String `tfsdk:"vtep_source_interface"` +} + +func (rsc *switchOptions) Create( + ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse, +) { + var plan switchOptionsData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceCreate( + ctx, + rsc, + nil, + nil, + &plan, + resp, + ) +} + +func (rsc *switchOptions) Read( + ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse, +) { + var state, data switchOptionsData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + var _ resourceDataReadFrom0String = &data + defaultResourceRead( + ctx, + rsc, + nil, + &data, + func() { + data.CleanOnDestroy = state.CleanOnDestroy + }, + resp, + ) +} + +func (rsc *switchOptions) Update( + ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse, +) { + var plan, state switchOptionsData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceUpdate( + ctx, + rsc, + &state, + &plan, + resp, + ) +} + +func (rsc *switchOptions) Delete( + ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse, +) { + var state switchOptionsData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + if state.CleanOnDestroy.ValueBool() { + defaultResourceDelete( + ctx, + rsc, + &state, + resp, + ) + } +} + +func (rsc *switchOptions) ImportState( + ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse, +) { + var data switchOptionsData + + var _ resourceDataReadFrom0String = &data + defaultResourceImportState( + ctx, + rsc, + &data, + req, + resp, + "", + ) +} + +func (rscData *switchOptionsData) fillID() { + rscData.ID = types.StringValue("switch_options") +} + +func (rscData *switchOptionsData) nullID() bool { + return rscData.ID.IsNull() +} + +func (rscData *switchOptionsData) set( + _ context.Context, junSess *junos.Session, +) ( + path.Path, error, +) { + configSet := make([]string, 0) + setPrefix := "set switch-options " + + if v := rscData.VTEPSourceInterface.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"vtep-source-interface "+v) + } + + return path.Empty(), junSess.ConfigSet(configSet) +} + +func (rscData *switchOptionsData) read( + _ context.Context, junSess *junos.Session, +) ( + err error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "switch-options" + junos.PipeDisplaySetRelative) + if err != nil { + return err + } + rscData.fillID() + if showConfig != junos.EmptyW { + for _, item := range strings.Split(showConfig, "\n") { + if strings.Contains(item, junos.XMLStartTagConfigOut) { + continue + } + if strings.Contains(item, junos.XMLEndTagConfigOut) { + break + } + itemTrim := strings.TrimPrefix(item, junos.SetLS) + if balt.CutPrefixInString(&itemTrim, "vtep-source-interface ") { + rscData.VTEPSourceInterface = types.StringValue(itemTrim) + } + } + } + + return nil +} + +func (rscData *switchOptionsData) del( + _ context.Context, junSess *junos.Session, +) error { + listLinesToDelete := []string{ + "vtep-source-interface", + } + + configSet := make([]string, len(listLinesToDelete)) + delPrefix := "delete switch-options " + for i, line := range listLinesToDelete { + configSet[i] = delPrefix + line + } + + return junSess.ConfigSet(configSet) +} diff --git a/internal/providerfwk/resource_switch_options_test.go b/internal/providerfwk/resource_switch_options_test.go new file mode 100644 index 00000000..a5b2433e --- /dev/null +++ b/internal/providerfwk/resource_switch_options_test.go @@ -0,0 +1,31 @@ +package providerfwk_test + +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccResourceSwitchOptions_basic(t *testing.T) { + if os.Getenv("TESTACC_ROUTER") != "" { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestStepDirectory(), + }, + { + ResourceName: "junos_switch_options.testacc_switchOpts", + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.TestStepDirectory(), + }, + }, + }) + } +} diff --git a/internal/providerfwk/testdata/TestAccResourceSwitchOptions_basic/1/main.tf b/internal/providerfwk/testdata/TestAccResourceSwitchOptions_basic/1/main.tf new file mode 100644 index 00000000..e917658a --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSwitchOptions_basic/1/main.tf @@ -0,0 +1,14 @@ +resource "junos_interface_logical" "testacc_switchOpts" { + lifecycle { + create_before_destroy = true + } + name = "lo0.0" + family_inet { + address { + cidr_ip = "192.0.2.16/32" + } + } +} +resource "junos_switch_options" "testacc_switchOpts" { + vtep_source_interface = junos_interface_logical.testacc_switchOpts.name +} diff --git a/internal/providerfwk/testdata/TestAccResourceSwitchOptions_basic/3/main.tf b/internal/providerfwk/testdata/TestAccResourceSwitchOptions_basic/3/main.tf new file mode 100644 index 00000000..af1b6258 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSwitchOptions_basic/3/main.tf @@ -0,0 +1 @@ +resource "junos_switch_options" "testacc_switchOpts" {} diff --git a/internal/providersdk/provider.go b/internal/providersdk/provider.go index fa19fd0b..c8952f95 100644 --- a/internal/providersdk/provider.go +++ b/internal/providersdk/provider.go @@ -199,7 +199,6 @@ func Provider() *schema.Provider { "junos_snmp_v3_vacm_accessgroup": resourceSnmpV3VacmAccessGroup(), "junos_snmp_v3_vacm_securitytogroup": resourceSnmpV3VacmSecurityToGroup(), "junos_snmp_view": resourceSnmpView(), - "junos_switch_options": resourceSwitchOptions(), "junos_system_login_class": resourceSystemLoginClass(), "junos_system_login_user": resourceSystemLoginUser(), "junos_system_ntp_server": resourceSystemNtpServer(), diff --git a/internal/providersdk/resource_switch_options.go b/internal/providersdk/resource_switch_options.go deleted file mode 100644 index a563a0f8..00000000 --- a/internal/providersdk/resource_switch_options.go +++ /dev/null @@ -1,266 +0,0 @@ -package providersdk - -import ( - "context" - "fmt" - "strings" - - "github.com/jeremmfr/terraform-provider-junos/internal/junos" - - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - balt "github.com/jeremmfr/go-utils/basicalter" -) - -type switchOptionsOptions struct { - vtepSourceIf string -} - -func resourceSwitchOptions() *schema.Resource { - return &schema.Resource{ - CreateWithoutTimeout: resourceSwitchOptionsCreate, - ReadWithoutTimeout: resourceSwitchOptionsRead, - UpdateWithoutTimeout: resourceSwitchOptionsUpdate, - DeleteWithoutTimeout: resourceSwitchOptionsDelete, - Importer: &schema.ResourceImporter{ - StateContext: resourceSwitchOptionsImport, - }, - Schema: map[string]*schema.Schema{ - "clean_on_destroy": { - Type: schema.TypeBool, - Optional: true, - }, - "vtep_source_interface": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { - value := v.(string) - if strings.Count(value, ".") != 1 { - errors = append(errors, fmt.Errorf( - "%q in %q need to have 1 dot", value, k)) - } - - return - }, - }, - }, - } -} - -func resourceSwitchOptionsCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - clt := m.(*junos.Client) - if clt.FakeCreateSetFile() { - junSess := clt.NewSessionWithoutNetconf(ctx) - if err := setSwitchOptions(d, junSess); err != nil { - return diag.FromErr(err) - } - d.SetId("switch_options") - - return nil - } - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return diag.FromErr(err) - } - defer junSess.Close() - if err := junSess.ConfigLock(ctx); err != nil { - return diag.FromErr(err) - } - var diagWarns diag.Diagnostics - if err := setSwitchOptions(d, junSess); err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - warns, err := junSess.CommitConf("create resource junos_switch_options") - appendDiagWarns(&diagWarns, warns) - if err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - d.SetId("switch_options") - - return append(diagWarns, resourceSwitchOptionsReadWJunSess(d, junSess)...) -} - -func resourceSwitchOptionsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - clt := m.(*junos.Client) - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return diag.FromErr(err) - } - defer junSess.Close() - - return resourceSwitchOptionsReadWJunSess(d, junSess) -} - -func resourceSwitchOptionsReadWJunSess(d *schema.ResourceData, junSess *junos.Session, -) diag.Diagnostics { - junos.MutexLock() - switchOptionsOptions, err := readSwitchOptions(junSess) - junos.MutexUnlock() - if err != nil { - return diag.FromErr(err) - } - fillSwitchOptions(d, switchOptionsOptions) - - return nil -} - -func resourceSwitchOptionsUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - d.Partial(true) - clt := m.(*junos.Client) - if clt.FakeUpdateAlso() { - junSess := clt.NewSessionWithoutNetconf(ctx) - if err := delSwitchOptions(junSess); err != nil { - return diag.FromErr(err) - } - if err := setSwitchOptions(d, junSess); err != nil { - return diag.FromErr(err) - } - d.Partial(false) - - return nil - } - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return diag.FromErr(err) - } - defer junSess.Close() - if err := junSess.ConfigLock(ctx); err != nil { - return diag.FromErr(err) - } - var diagWarns diag.Diagnostics - if err := delSwitchOptions(junSess); err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - if err := setSwitchOptions(d, junSess); err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - warns, err := junSess.CommitConf("update resource junos_switch_options") - appendDiagWarns(&diagWarns, warns) - if err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - d.Partial(false) - - return append(diagWarns, resourceSwitchOptionsReadWJunSess(d, junSess)...) -} - -func resourceSwitchOptionsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - if d.Get("clean_on_destroy").(bool) { - clt := m.(*junos.Client) - if clt.FakeDeleteAlso() { - junSess := clt.NewSessionWithoutNetconf(ctx) - if err := delSwitchOptions(junSess); err != nil { - return diag.FromErr(err) - } - - return nil - } - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return diag.FromErr(err) - } - defer junSess.Close() - if err := junSess.ConfigLock(ctx); err != nil { - return diag.FromErr(err) - } - var diagWarns diag.Diagnostics - if err := delSwitchOptions(junSess); err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - warns, err := junSess.CommitConf("delete resource junos_switch_options") - appendDiagWarns(&diagWarns, warns) - if err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - } - - return nil -} - -func resourceSwitchOptionsImport(ctx context.Context, d *schema.ResourceData, m interface{}, -) ([]*schema.ResourceData, error) { - clt := m.(*junos.Client) - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return nil, err - } - defer junSess.Close() - result := make([]*schema.ResourceData, 1) - switchOptionsOptions, err := readSwitchOptions(junSess) - if err != nil { - return nil, err - } - fillSwitchOptions(d, switchOptionsOptions) - d.SetId("switch_options") - result[0] = d - - return result, nil -} - -func setSwitchOptions(d *schema.ResourceData, junSess *junos.Session) error { - setPrefix := "set switch-options " - configSet := make([]string, 0) - - if v := d.Get("vtep_source_interface").(string); v != "" { - configSet = append(configSet, setPrefix+"vtep-source-interface "+v) - } - - return junSess.ConfigSet(configSet) -} - -func delSwitchOptions(junSess *junos.Session) error { - listLinesToDelete := []string{"vtep-source-interface"} - - configSet := make([]string, 0) - delPrefix := "delete switch-options " - for _, line := range listLinesToDelete { - configSet = append(configSet, - delPrefix+line) - } - - return junSess.ConfigSet(configSet) -} - -func readSwitchOptions(junSess *junos.Session, -) (confRead switchOptionsOptions, err error) { - showConfig, err := junSess.Command(junos.CmdShowConfig + "switch-options" + junos.PipeDisplaySetRelative) - if err != nil { - return confRead, err - } - if showConfig != junos.EmptyW { - for _, item := range strings.Split(showConfig, "\n") { - if strings.Contains(item, junos.XMLStartTagConfigOut) { - continue - } - if strings.Contains(item, junos.XMLEndTagConfigOut) { - break - } - itemTrim := strings.TrimPrefix(item, junos.SetLS) - if balt.CutPrefixInString(&itemTrim, "vtep-source-interface ") { - confRead.vtepSourceIf = itemTrim - } - } - } - - return confRead, nil -} - -func fillSwitchOptions(d *schema.ResourceData, switchOptionsOptions switchOptionsOptions) { - if tfErr := d.Set("vtep_source_interface", switchOptionsOptions.vtepSourceIf); tfErr != nil { - panic(tfErr) - } -} diff --git a/internal/providersdk/resource_switch_options_test.go b/internal/providersdk/resource_switch_options_test.go deleted file mode 100644 index 9395c731..00000000 --- a/internal/providersdk/resource_switch_options_test.go +++ /dev/null @@ -1,56 +0,0 @@ -package providersdk_test - -import ( - "os" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestAccResourceSwitchOptions_basic(t *testing.T) { - if os.Getenv("TESTACC_ROUTER") != "" { - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - Config: testAccResourceSwitchOptionsConfigCreate(), - }, - { - ResourceName: "junos_switch_options.testacc_switchOpts", - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccResourceSwitchOptionsConfigUpdate(), - }, - }, - }) - } -} - -func testAccResourceSwitchOptionsConfigCreate() string { - return ` -resource "junos_interface_logical" "testacc_switchOpts" { - lifecycle { - create_before_destroy = true - } - name = "lo0.0" - family_inet { - address { - cidr_ip = "192.0.2.16/32" - } - } -} -resource "junos_switch_options" "testacc_switchOpts" { - vtep_source_interface = junos_interface_logical.testacc_switchOpts.name -} -` -} - -func testAccResourceSwitchOptionsConfigUpdate() string { - return ` -resource "junos_switch_options" "testacc_switchOpts" { -} -` -} From 0408639ba88ce46b3571d62591f11a6ecd8b28c5 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Mon, 11 Dec 2023 11:37:25 +0100 Subject: [PATCH 26/43] r/switch_options: add service_id argument Fix #575 --- .changes/issue-575.md | 1 + docs/resources/switch_options.md | 2 ++ .../providerfwk/resource_switch_options.go | 24 ++++++++++++++++++- .../1/main.tf | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.changes/issue-575.md b/.changes/issue-575.md index 480cbcde..f6e1a7c1 100644 --- a/.changes/issue-575.md +++ b/.changes/issue-575.md @@ -5,3 +5,4 @@ ENHANCEMENTS: * resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) optional boolean attributes doesn't accept value *false* optional string attributes doesn't accept *empty* value + * add `service_id` argument (Fix [#575](https://github.com/jeremmfr/terraform-provider-junos/issues/575)) diff --git a/docs/resources/switch_options.md b/docs/resources/switch_options.md index 6c991767..892ba379 100644 --- a/docs/resources/switch_options.md +++ b/docs/resources/switch_options.md @@ -25,6 +25,8 @@ The following arguments are supported: - **clean_on_destroy** (Optional, Boolean) Clean supported lines when destroy this resource. +- **service_id** (Optional, Number) + Service ID required if multi-chassis AE is part of a bridge-domain (1..65535). - **vtep_source_interface** (Optional, String) Source layer-3 IFL for VXLAN. diff --git a/internal/providerfwk/resource_switch_options.go b/internal/providerfwk/resource_switch_options.go index 98006936..71e23cc7 100644 --- a/internal/providerfwk/resource_switch_options.go +++ b/internal/providerfwk/resource_switch_options.go @@ -5,8 +5,11 @@ import ( "strings" "github.com/jeremmfr/terraform-provider-junos/internal/junos" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdata" "github.com/jeremmfr/terraform-provider-junos/internal/tfvalidator" + "github.com/jeremmfr/terraform-provider-junos/internal/utils" + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -87,6 +90,13 @@ func (rsc *switchOptions) Schema( tfvalidator.BoolTrue(), }, }, + "service_id": schema.Int64Attribute{ + Optional: true, + Description: "Service ID required if multi-chassis AE is part of a bridge-domain.", + Validators: []validator.Int64{ + int64validator.Between(1, 65535), + }, + }, "vtep_source_interface": schema.StringAttribute{ Optional: true, Description: "Source layer-3 IFL for VXLAN.", @@ -103,6 +113,7 @@ func (rsc *switchOptions) Schema( type switchOptionsData struct { CleanOnDestroy types.Bool `tfsdk:"clean_on_destroy"` ID types.String `tfsdk:"id"` + ServiceID types.Int64 `tfsdk:"service_id"` VTEPSourceInterface types.String `tfsdk:"vtep_source_interface"` } @@ -217,6 +228,10 @@ func (rscData *switchOptionsData) set( configSet := make([]string, 0) setPrefix := "set switch-options " + if !rscData.ServiceID.IsNull() { + configSet = append(configSet, setPrefix+"service-id "+ + utils.ConvI64toa(rscData.ServiceID.ValueInt64())) + } if v := rscData.VTEPSourceInterface.ValueString(); v != "" { configSet = append(configSet, setPrefix+"vtep-source-interface "+v) } @@ -244,7 +259,13 @@ func (rscData *switchOptionsData) read( break } itemTrim := strings.TrimPrefix(item, junos.SetLS) - if balt.CutPrefixInString(&itemTrim, "vtep-source-interface ") { + switch { + case balt.CutPrefixInString(&itemTrim, "service-id "): + rscData.ServiceID, err = tfdata.ConvAtoi64Value(itemTrim) + if err != nil { + return err + } + case balt.CutPrefixInString(&itemTrim, "vtep-source-interface "): rscData.VTEPSourceInterface = types.StringValue(itemTrim) } } @@ -257,6 +278,7 @@ func (rscData *switchOptionsData) del( _ context.Context, junSess *junos.Session, ) error { listLinesToDelete := []string{ + "service-id", "vtep-source-interface", } diff --git a/internal/providerfwk/testdata/TestAccResourceSwitchOptions_basic/1/main.tf b/internal/providerfwk/testdata/TestAccResourceSwitchOptions_basic/1/main.tf index e917658a..d87cf93a 100644 --- a/internal/providerfwk/testdata/TestAccResourceSwitchOptions_basic/1/main.tf +++ b/internal/providerfwk/testdata/TestAccResourceSwitchOptions_basic/1/main.tf @@ -10,5 +10,6 @@ resource "junos_interface_logical" "testacc_switchOpts" { } } resource "junos_switch_options" "testacc_switchOpts" { + service_id = 111 vtep_source_interface = junos_interface_logical.testacc_switchOpts.name } From a4f14414880d1276f16da6529e0040ae039dcf29 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Mon, 11 Dec 2023 12:22:50 +0100 Subject: [PATCH 27/43] r/security,r/switch_options: clean_on_destroy can accept false --- .changes/issue-575.md | 1 - internal/providerfwk/resource_security.go | 3 --- internal/providerfwk/resource_switch_options.go | 3 --- 3 files changed, 7 deletions(-) diff --git a/.changes/issue-575.md b/.changes/issue-575.md index f6e1a7c1..a5d7ccf9 100644 --- a/.changes/issue-575.md +++ b/.changes/issue-575.md @@ -3,6 +3,5 @@ ENHANCEMENTS: * **resource/junos_switch_options**: * resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) - optional boolean attributes doesn't accept value *false* optional string attributes doesn't accept *empty* value * add `service_id` argument (Fix [#575](https://github.com/jeremmfr/terraform-provider-junos/issues/575)) diff --git a/internal/providerfwk/resource_security.go b/internal/providerfwk/resource_security.go index 367c8f5d..daa1c90c 100644 --- a/internal/providerfwk/resource_security.go +++ b/internal/providerfwk/resource_security.go @@ -95,9 +95,6 @@ func (rsc *security) Schema( "clean_on_destroy": schema.BoolAttribute{ Optional: true, Description: "Clean supported lines when destroy this resource.", - Validators: []validator.Bool{ - tfvalidator.BoolTrue(), - }, }, }, Blocks: map[string]schema.Block{ diff --git a/internal/providerfwk/resource_switch_options.go b/internal/providerfwk/resource_switch_options.go index 71e23cc7..d0878314 100644 --- a/internal/providerfwk/resource_switch_options.go +++ b/internal/providerfwk/resource_switch_options.go @@ -86,9 +86,6 @@ func (rsc *switchOptions) Schema( "clean_on_destroy": schema.BoolAttribute{ Optional: true, Description: "Clean supported lines when destroy this resource.", - Validators: []validator.Bool{ - tfvalidator.BoolTrue(), - }, }, "service_id": schema.Int64Attribute{ Optional: true, From ee22b7e5511075affe52f10d02627f993b4c6e07 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Mon, 11 Dec 2023 20:58:54 +0100 Subject: [PATCH 28/43] r/iccp: use set/delete word like other resources --- internal/providerfwk/resource_iccp.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/providerfwk/resource_iccp.go b/internal/providerfwk/resource_iccp.go index 8e458292..f3217204 100644 --- a/internal/providerfwk/resource_iccp.go +++ b/internal/providerfwk/resource_iccp.go @@ -222,7 +222,7 @@ func (rscData *iccpData) set( ) ( path.Path, error, ) { - setPrefix := junos.SetLS + "protocols iccp " + setPrefix := "set protocols iccp " configSet := []string{ setPrefix + "local-ip-addr " + rscData.LocalIPAddr.ValueString(), } @@ -282,12 +282,12 @@ func (rscData *iccpData) read( func (rscData *iccpData) del( _ context.Context, junSess *junos.Session, ) error { - delLine := junos.DeleteLS + "protocols iccp " + delPrefix := "delete protocols iccp " configSet := []string{ - delLine + "local-ip-addr", - delLine + "authentication-key", - delLine + "session-establishment-hold-time", + delPrefix + "local-ip-addr", + delPrefix + "authentication-key", + delPrefix + "session-establishment-hold-time", } return junSess.ConfigSet(configSet) From f6b982ffaeba2cad31113792db0bf32e893b8d93 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Tue, 12 Dec 2023 09:34:28 +0100 Subject: [PATCH 29/43] r/switch_options: simplify data del function --- internal/providerfwk/resource_switch_options.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/internal/providerfwk/resource_switch_options.go b/internal/providerfwk/resource_switch_options.go index d0878314..ea551cb2 100644 --- a/internal/providerfwk/resource_switch_options.go +++ b/internal/providerfwk/resource_switch_options.go @@ -274,15 +274,11 @@ func (rscData *switchOptionsData) read( func (rscData *switchOptionsData) del( _ context.Context, junSess *junos.Session, ) error { - listLinesToDelete := []string{ - "service-id", - "vtep-source-interface", - } - - configSet := make([]string, len(listLinesToDelete)) delPrefix := "delete switch-options " - for i, line := range listLinesToDelete { - configSet[i] = delPrefix + line + + configSet := []string{ + delPrefix + "service-id", + delPrefix + "vtep-source-interface", } return junSess.ConfigSet(configSet) From 716894e4d30508904691b4009513f3d4b269bc09 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Tue, 12 Dec 2023 16:05:17 +0100 Subject: [PATCH 30/43] provider: add commit_confirmed argument and commit_confirmed_wait_percent Fix #585 --- .changes/issue-585.md | 8 + docs/index.md | 21 +++ internal/junos/client.go | 100 ++++++----- internal/junos/client_session.go | 7 + internal/junos/constants.go | 38 ++-- internal/junos/netconf.go | 165 ++++++++++++------ internal/junos/session.go | 42 +++-- internal/providerfwk/default_resource_op.go | 6 +- internal/providerfwk/provider.go | 141 +++++++++++++-- .../providerfwk/resource_interface_logical.go | 4 +- .../resource_interface_physical.go | 8 +- .../resource_interface_physical_disable.go | 2 +- .../resource_interface_st0_unit.go | 4 +- .../resource_security_nat_static.go | 2 +- .../providerfwk/resource_security_policy.go | 2 +- .../providerfwk/resource_security_zone.go | 2 +- internal/providersdk/provider.go | 83 +++++++++ ...resource_access_address_assignment_pool.go | 6 +- .../providersdk/resource_chassis_cluster.go | 6 +- .../resource_chassis_redundancy.go | 6 +- .../resource_eventoptions_destination.go | 6 +- .../resource_eventoptions_generate_event.go | 6 +- .../resource_eventoptions_policy.go | 6 +- .../resource_forwardingoptions_dhcprelay.go | 6 +- ...ource_forwardingoptions_dhcprelay_group.go | 6 +- ...forwardingoptions_dhcprelay_servergroup.go | 6 +- .../providersdk/resource_group_dual_system.go | 6 +- .../resource_igmp_snooping_vlan.go | 6 +- .../providersdk/resource_layer2_control.go | 6 +- .../providersdk/resource_lldp_interface.go | 6 +- .../providersdk/resource_lldpmed_interface.go | 6 +- .../providersdk/resource_null_commit_file.go | 2 +- internal/providersdk/resource_ospf.go | 6 +- internal/providersdk/resource_ospf_area.go | 6 +- internal/providersdk/resource_rib_group.go | 6 +- internal/providersdk/resource_rip_group.go | 6 +- internal/providersdk/resource_rip_neighbor.go | 6 +- .../providersdk/resource_routing_options.go | 6 +- internal/providersdk/resource_rstp.go | 6 +- .../providersdk/resource_rstp_interface.go | 6 +- ...ce_security_dynamic_address_feed_server.go | 6 +- .../resource_security_dynamic_address_name.go | 6 +- .../resource_security_idp_custom_attack.go | 6 +- ...source_security_idp_custom_attack_group.go | 6 +- .../resource_security_idp_policy.go | 6 +- .../resource_security_log_stream.go | 6 +- .../providersdk/resource_security_screen.go | 6 +- .../resource_security_screen_whitelist.go | 6 +- ...source_security_utm_custom_url_category.go | 6 +- ...esource_security_utm_custom_url_pattern.go | 6 +- .../resource_security_utm_policy.go | 6 +- ..._profile_web_filtering_juniper_enhanced.go | 6 +- ...utm_profile_web_filtering_juniper_local.go | 6 +- ...profile_web_filtering_websense_redirect.go | 6 +- internal/providersdk/resource_services.go | 6 +- ...e_services_advanced_anti_malware_policy.go | 6 +- .../resource_services_proxy_profile.go | 6 +- .../resource_services_rpm_probe.go | 6 +- ...e_services_security_intelligence_policy.go | 6 +- ..._services_security_intelligence_profile.go | 6 +- ...esource_services_ssl_initiation_profile.go | 6 +- ...es_user_identification_ad_access_domain.go | 6 +- ..._identification_device_identity_profile.go | 6 +- internal/providersdk/resource_snmp.go | 6 +- .../providersdk/resource_snmp_clientlist.go | 6 +- .../providersdk/resource_snmp_community.go | 6 +- .../providersdk/resource_snmp_v3_community.go | 6 +- .../providersdk/resource_snmp_v3_usm_user.go | 6 +- .../resource_snmp_v3_vacm_accessgroup.go | 6 +- .../resource_snmp_v3_vacm_securitytogroup.go | 6 +- internal/providersdk/resource_snmp_view.go | 6 +- .../resource_system_login_class.go | 6 +- .../providersdk/resource_system_login_user.go | 6 +- .../providersdk/resource_system_ntp_server.go | 6 +- .../resource_system_radius_server.go | 6 +- .../resource_system_root_authentication.go | 4 +- ..._system_services_dhcp_localserver_group.go | 6 +- .../resource_system_syslog_file.go | 6 +- .../resource_system_syslog_host.go | 6 +- internal/providersdk/resource_vlan.go | 6 +- internal/providersdk/resource_vstp.go | 6 +- .../providersdk/resource_vstp_interface.go | 6 +- internal/providersdk/resource_vstp_vlan.go | 6 +- .../providersdk/resource_vstp_vlan_group.go | 6 +- 84 files changed, 669 insertions(+), 362 deletions(-) create mode 100644 .changes/issue-585.md diff --git a/.changes/issue-585.md b/.changes/issue-585.md new file mode 100644 index 00000000..017bfa4b --- /dev/null +++ b/.changes/issue-585.md @@ -0,0 +1,8 @@ + +FEATURES: + +* add `commit_confirmed` and `commit_confirmed_wait_percent` provider argument to be able use `commit confirmed` feature to commit the resource actions (Fix [#585](https://github.com/jeremmfr/terraform-provider-junos/issues/585)) + +ENHANCEMENTS: + +* display all errors when configuration commit generate multiple errors diff --git a/docs/index.md b/docs/index.md index e358cb7f..45038c1e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -134,6 +134,27 @@ The following arguments are supported in the `provider` block: It can also be sourced from the `JUNOS_SLEEP_LOCK` environment variable. Defaults to `10`. +- **commit_confirmed** (Optional, Number) + Number of minutes until automatic rollback (1..65535). + It can also be sourced from the `JUNOS_COMMIT_CONFIRMED` environment variable. + + **If this argument is specified**, for each resource action with commit, + the commit will take place in three steps: + - commit with the `confirmed` option and with the value of this argument as `confirm-timeout`. + - wait for ``% of the minutes defined in the value of this argument. + - confirm commit to avoid rollback with the `commit check` command. + + If a gracefully shutting down call with `Ctrl-c` is received by Terraform, + the wait step is stopped and provider returns an error. + +- **commit_confirmed_wait_percent** (Optional, Number) + Percentage of `` minute(s) to wait between + `commit confirmed` (commit with automatic rollback) and + `commit check` (confirmation) commands (0..99). + No effect if `` is not used. + It can also be sourced from the `JUNOS_COMMIT_CONFIRMED_WAIT_PERCENT` environment variable. + Defaults to `90`. + --- ### SSH options diff --git a/internal/junos/client.go b/internal/junos/client.go index d2f0fdfc..0ce00a72 100644 --- a/internal/junos/client.go +++ b/internal/junos/client.go @@ -6,48 +6,52 @@ const directoryPermission = 0o755 // Client information to connect on Junos Device and more. type Client struct { - fakeUpdateAlso bool - fakeDeleteAlso bool - junosPort int - junosSSHTimeoutToEstab int - junosSSHRetryToEstab int - sleepLock int - sleepShort int - sleepSSHClosed int - filePermission int64 - junosIP string - junosUserName string - junosPassword string - junosSSHKeyPEM string - junosSSHKeyFile string - junosSSHKeyPass string - groupIntDel string - logFileDst string - fakeCreateSetFile string - junosSSHCiphers []string + fakeUpdateAlso bool + fakeDeleteAlso bool + junosCommitConfirmed int + junosCommitConfirmedWaitPercent int + junosPort int + junosSSHTimeoutToEstab int + junosSSHRetryToEstab int + sleepLock int + sleepShort int + sleepSSHClosed int + filePermission int64 + junosIP string + junosUserName string + junosPassword string + junosSSHKeyPEM string + junosSSHKeyFile string + junosSSHKeyPass string + groupIntDel string + logFileDst string + fakeCreateSetFile string + junosSSHCiphers []string } func NewClient(ip string) *Client { return &Client{ - junosIP: ip, - junosPort: 830, - junosUserName: "netconf", - junosPassword: "", - junosSSHKeyPEM: "", - junosSSHKeyFile: "", - junosSSHKeyPass: "", - groupIntDel: "", - sleepShort: 100, - sleepLock: 10, - sleepSSHClosed: 0, - junosSSHCiphers: DefaultSSHCiphers(), - junosSSHTimeoutToEstab: 0, - junosSSHRetryToEstab: 1, - filePermission: 0o644, - logFileDst: "", - fakeCreateSetFile: "", - fakeUpdateAlso: false, - fakeDeleteAlso: false, + junosIP: ip, + junosPort: 830, + junosUserName: "netconf", + junosPassword: "", + junosSSHKeyPEM: "", + junosSSHKeyFile: "", + junosSSHKeyPass: "", + groupIntDel: "", + sleepShort: 100, + sleepLock: 10, + junosCommitConfirmed: 0, + junosCommitConfirmedWaitPercent: 90, + sleepSSHClosed: 0, + junosSSHCiphers: DefaultSSHCiphers(), + junosSSHTimeoutToEstab: 0, + junosSSHRetryToEstab: 1, + filePermission: 0o644, + logFileDst: "", + fakeCreateSetFile: "", + fakeUpdateAlso: false, + fakeDeleteAlso: false, } } @@ -105,6 +109,24 @@ func (clt *Client) WithSleepLock(sleep int) *Client { return clt } +func (clt *Client) WithCommitConfirmed(timeout int) (*Client, error) { + if timeout < 1 || timeout > 65535 { + return clt, fmt.Errorf("bad value for timeout of commit confirmed") + } + clt.junosCommitConfirmed = timeout + + return clt, nil +} + +func (clt *Client) WithCommitConfirmedWaitPercent(percent int) (*Client, error) { + if percent < 0 || percent > 99 { + return clt, fmt.Errorf("bad value for wait percent of timeout before the commit confirm") + } + clt.junosCommitConfirmedWaitPercent = percent + + return clt, nil +} + func (clt *Client) WithSleepSSHClosed(sleep int) *Client { clt.sleepSSHClosed = sleep @@ -125,7 +147,7 @@ func (clt *Client) WithSSHTimeoutToEstablish(timeout int) *Client { func (clt *Client) WithSSHRetryToEstablish(retry int) (*Client, error) { if retry < 1 || retry > 10 { - return clt, fmt.Errorf("bad value to number of retry to establishing SSH connection") + return clt, fmt.Errorf("bad value for number of retry to establishing SSH connection") } clt.junosSSHRetryToEstab = retry diff --git a/internal/junos/client_session.go b/internal/junos/client_session.go index 818f77c3..ccaf285d 100644 --- a/internal/junos/client_session.go +++ b/internal/junos/client_session.go @@ -5,6 +5,7 @@ import ( "fmt" "net" "strconv" + "time" ) func (clt *Client) StartNewSession(ctx context.Context) (*Session, error) { @@ -43,6 +44,12 @@ func (clt *Client) StartNewSession(ctx context.Context) (*Session, error) { return nil, err } + sess.commitConfirmedTimeout = clt.junosCommitConfirmed + sess.commitConfirmedWait = time.Duration( + int( + (time.Duration(clt.junosCommitConfirmed)*time.Minute).Microseconds(), + )*clt.junosCommitConfirmedWaitPercent/100, + ) * time.Microsecond sess.logFile = func(message string) { message = "[" + sess.localAddress + "->" + sess.remoteAddress + "]" + message clt.logFile(message) diff --git a/internal/junos/constants.go b/internal/junos/constants.go index d6b10ae5..377cb058 100644 --- a/internal/junos/constants.go +++ b/internal/junos/constants.go @@ -35,24 +35,26 @@ const ( CantReadValuesNotEnoughFields = "can't read values for %s in '%s': not enough fields" - EnvHost = "JUNOS_HOST" - EnvPort = "JUNOS_PORT" - EnvUsername = "JUNOS_USERNAME" - EnvPassword = "JUNOS_PASSWORD" - EnvKeyPem = "JUNOS_KEYPEM" - EnvKeyFile = "JUNOS_KEYFILE" - EnvKeyPass = "JUNOS_KEYPASS" - EnvGroupInterfaceDelete = "JUNOS_GROUP_INTERFACE_DELETE" - EnvSleepShort = "JUNOS_SLEEP_SHORT" - EnvSleepLock = "JUNOS_SLEEP_LOCK" - EnvSleepSSHClosed = "JUNOS_SLEEP_SSH_CLOSED" - EnvSSHTimeoutToEstablish = "JUNOS_SSH_TIMEOUT_TO_ESTABLISH" - EnvSSHRetryToEstablish = "JUNOS_SSH_RETRY_TO_ESTABLISH" - EnvFilePermission = "JUNOS_FILE_PERMISSION" - EnvLogPath = "JUNOS_LOG_PATH" - EnvFakecreateSetfile = "JUNOS_FAKECREATE_SETFILE" - EnvFakeupdateAlso = "JUNOS_FAKEUPDATE_ALSO" - EnvFakedeleteAlso = "JUNOS_FAKEDELETE_ALSO" + EnvHost = "JUNOS_HOST" + EnvPort = "JUNOS_PORT" + EnvUsername = "JUNOS_USERNAME" + EnvPassword = "JUNOS_PASSWORD" + EnvKeyPem = "JUNOS_KEYPEM" + EnvKeyFile = "JUNOS_KEYFILE" + EnvKeyPass = "JUNOS_KEYPASS" + EnvGroupInterfaceDelete = "JUNOS_GROUP_INTERFACE_DELETE" + EnvSleepShort = "JUNOS_SLEEP_SHORT" + EnvSleepLock = "JUNOS_SLEEP_LOCK" + EnvCommitConfirmed = "JUNOS_COMMIT_CONFIRMED" + EnvCommitConfirmedWaitPercent = "JUNOS_COMMIT_CONFIRMED_WAIT_PERCENT" + EnvSleepSSHClosed = "JUNOS_SLEEP_SSH_CLOSED" + EnvSSHTimeoutToEstablish = "JUNOS_SSH_TIMEOUT_TO_ESTABLISH" + EnvSSHRetryToEstablish = "JUNOS_SSH_RETRY_TO_ESTABLISH" + EnvFilePermission = "JUNOS_FILE_PERMISSION" + EnvLogPath = "JUNOS_LOG_PATH" + EnvFakecreateSetfile = "JUNOS_FAKECREATE_SETFILE" + EnvFakeupdateAlso = "JUNOS_FAKEUPDATE_ALSO" + EnvFakedeleteAlso = "JUNOS_FAKEDELETE_ALSO" DefaultInterfaceTestAcc = "ge-0/0/3" DefaultInterfaceTestAcc2 = "ge-0/0/4" diff --git a/internal/junos/netconf.go b/internal/junos/netconf.go index 45f070d7..bdf5ff37 100644 --- a/internal/junos/netconf.go +++ b/internal/junos/netconf.go @@ -1,10 +1,12 @@ package junos import ( + "context" "encoding/xml" "errors" "fmt" "strings" + "time" "github.com/jeremmfr/terraform-provider-junos/internal/utils" @@ -16,9 +18,19 @@ const ( rpcCommand = "%s" rpcConfigStringSet = "" + - "%s" - rpcSystemInfo = "" - rpcCommit = "%s" + "%s" + + "" + rpcSystemInfo = "" + rpcCommit = "" + + "%s" + + "" + rpcCommitConfirmed = "" + + "%s" + + "%d" + + "" + rpcCommitCheck = "" + + "" + + "" rpcCandidateLock = "" rpcCandidateUnlock = "" rpcClearCandidate = "" @@ -144,11 +156,15 @@ func (sess *Session) netconfCommand(cmd string) (string, error) { if err != nil { return "", fmt.Errorf("executing netconf command: %w", err) } - if reply.Errors != nil { - for _, m := range reply.Errors { - return "", errors.New(m.Error()) - } + + errs := make([]string, len(reply.Errors)) + for i, m := range reply.Errors { + errs[i] = m.Error() + } + if len(errs) > 0 { + return "", errors.New(strings.Join(errs, "\n")) } + if reply.Data == "" || strings.Count(reply.Data, "") <= 2 { return EmptyW, errors.New("no output available - please check the syntax of your command") } @@ -165,10 +181,13 @@ func (sess *Session) netconfCommandXML(cmd string) (string, error) { if err != nil { return "", fmt.Errorf("executing netconf xml command: %w", err) } - if reply.Errors != nil { - for _, m := range reply.Errors { - return "", errors.New(m.Error()) - } + + errs := make([]string, len(reply.Errors)) + for i, m := range reply.Errors { + errs[i] = m.Error() + } + if len(errs) > 0 { + return "", errors.New(strings.Join(errs, "\n")) } return reply.Data, nil @@ -182,15 +201,12 @@ func (sess *Session) netconfConfigSet(cmd []string) (string, error) { } // logFile("netconfConfigSet.Reply:" + reply.RawReply) message := "" - if reply.Errors != nil { - for _, m := range reply.Errors { - message += m.Message - } - return message, nil + for _, m := range reply.Errors { + message += m.Message } - return "", nil + return message, nil } // netConfConfigLock locks the candidate configuration. @@ -199,88 +215,123 @@ func (sess *Session) netconfConfigLock() bool { if err != nil { return false } - if reply.Errors != nil { + if len(reply.Errors) > 0 { return false } return true } -func (sess *Session) netconfConfigClear() []error { +func (sess *Session) netconfConfigClear() (errs []error) { reply, err := sess.netconf.Exec(netconf.RawMethod(rpcClearCandidate)) if err != nil { return []error{fmt.Errorf("executing netconf config clear: %w", err)} } - if reply.Errors != nil { - errs := make([]error, 0) - for _, m := range reply.Errors { - errs = append(errs, errors.New("config clear: "+m.Message)) - } - return errs + for _, m := range reply.Errors { + errs = append(errs, errors.New("config clear: "+m.Message)) } - return []error{} + return errs } // Unlock unlocks the candidate configuration. -func (sess *Session) netconfConfigUnlock() []error { +func (sess *Session) netconfConfigUnlock() (errs []error) { reply, err := sess.netconf.Exec(netconf.RawMethod(rpcCandidateUnlock)) if err != nil { return []error{fmt.Errorf("executing netconf config unlock: %w", err)} } - if reply.Errors != nil { - errs := make([]error, 0) - for _, m := range reply.Errors { - errs = append(errs, errors.New("config unlock: "+m.Message)) - } - return errs + for _, m := range reply.Errors { + errs = append(errs, errors.New("config unlock: "+m.Message)) } - return []error{} + return errs } // netconfCommit commits the configuration. -func (sess *Session) netconfCommit(logMessage string) (_warn []error, _err error) { +// +// return potential warnings and/or error. +func (sess *Session) netconfCommit(logMessage string) (_ []error, _ error) { reply, err := sess.netconf.Exec(netconf.RawMethod(fmt.Sprintf(rpcCommit, logMessage))) if err != nil { - return []error{}, fmt.Errorf("executing netconf commit: %w", err) + return nil, fmt.Errorf("executing netconf commit: %w", err) } - if reply.Errors != nil { - warnings := make([]error, 0) - for _, m := range reply.Errors { - if m.Severity == errorSeverity { - return warnings, errors.New(m.Error()) - } + return readNetconfCommitReply(reply, "commit-configuration") +} + +// netconfCommitConfirmed commits the configuration with confirmed option and confirmed timeout, +// then wait percentage of timeout and send afterwards the confirmation with commit check. +// +// return potential warnings and/or error. +func (sess *Session) netconfCommitConfirmed(ctx context.Context, logMessage string) (warnings []error, _ error) { + reply, err := sess.netconf.Exec( + netconf.RawMethod(fmt.Sprintf(rpcCommitConfirmed, logMessage, sess.commitConfirmedTimeout)), + ) + if err != nil { + return warnings, fmt.Errorf("executing netconf commit (confirmed %d): %w", sess.commitConfirmedTimeout, err) + } + + replyWarns, err := readNetconfCommitReply(reply, "commit-configuration(confirmed)") + warnings = append(warnings, replyWarns...) + if err != nil { + return warnings, err + } + + select { + case <-ctx.Done(): + return warnings, fmt.Errorf("confirmation of commit with 'confirmed' option aborted before done") + case <-time.After(sess.commitConfirmedWait): + } + + replyConfirm, err := sess.netconf.Exec(netconf.RawMethod(rpcCommitCheck)) + if err != nil { + return warnings, fmt.Errorf("executing netconf commit check (to confirm): %w", err) + } + + replyWarns, err = readNetconfCommitReply(replyConfirm, "commit-configuration(check)") + warnings = append(warnings, replyWarns...) + if err != nil { + return warnings, err + } + + return warnings, nil +} + +func readNetconfCommitReply(reply *netconf.RPCReply, commitType string) (warnings []error, _ error) { + errs := make([]string, 0, len(reply.Errors)) + for _, m := range reply.Errors { + if m.Severity == errorSeverity { + errs = append(errs, m.Error()) + } else { warnings = append(warnings, errors.New(m.Error())) } - - return warnings, nil + } + if len(errs) > 0 { + return warnings, errors.New(strings.Join(errs, "\n")) } - var errs commitResults + var result commitResults if strings.Contains(reply.Data, "") { - err = xml.Unmarshal([]byte(reply.Data), &errs) - if err != nil { - return []error{}, fmt.Errorf("unmarshaling xml reply %q of commit-configuration: %w", reply.Data, err) + if err := xml.Unmarshal([]byte(reply.Data), &result); err != nil { + return warnings, fmt.Errorf("unmarshaling xml reply %q of %s: %w", reply.Data, commitType, err) } - if errs.Errors != nil { - warnings := make([]error, 0) - for _, m := range errs.Errors { - if m.Severity == errorSeverity { - return []error{}, errors.New(m.Error()) - } + errs = make([]string, 0, len(result.Errors)) + for _, m := range result.Errors { + if m.Severity == errorSeverity { + errs = append(errs, m.Error()) + } else { warnings = append(warnings, errors.New(m.Error())) } - - return warnings, nil + } + if len(errs) > 0 { + return warnings, errors.New(strings.Join(errs, "\n")) } } - return []error{}, nil + return warnings, nil } // Close disconnects our session to the device. diff --git a/internal/junos/session.go b/internal/junos/session.go index 1770cd5e..8baf8c9e 100644 --- a/internal/junos/session.go +++ b/internal/junos/session.go @@ -17,15 +17,17 @@ import ( // Session : store Junos device info and session. type Session struct { - SystemInformation sysInfo - netconf *netconf.Session - localAddress string - remoteAddress string - logFile func(string) - fakeSetFile func([]string) error - sleepShort int - sleepLock int - sleepSSHClosed int + SystemInformation sysInfo + netconf *netconf.Session + localAddress string + remoteAddress string + logFile func(string) + fakeSetFile func([]string) error + sleepShort int + sleepLock int + commitConfirmedTimeout int + commitConfirmedWait time.Duration + sleepSSHClosed int } type sshAuthMethod struct { @@ -288,22 +290,30 @@ func (sess *Session) ConfigClear() (errs []error) { } // CommitConf commit the configuration with message via netconf. -func (sess *Session) CommitConf(logMessage string) (_warnings []error, _err error) { - sess.logFile(fmt.Sprintf("[CommitConf] commit %q", logMessage)) - warns, err := sess.netconfCommit(logMessage) +func (sess *Session) CommitConf(ctx context.Context, logMessage string) (warnings []error, err error) { + if sess.commitConfirmedTimeout > 0 { + sess.logFile(fmt.Sprintf( + "[CommitConf] commit confirmed %d (wait %s) %q", + sess.commitConfirmedTimeout, sess.commitConfirmedWait, logMessage, + )) + warnings, err = sess.netconfCommitConfirmed(ctx, logMessage) + } else { + sess.logFile(fmt.Sprintf("[CommitConf] commit %q", logMessage)) + warnings, err = sess.netconfCommit(logMessage) + } utils.SleepShort(sess.sleepShort) - if len(warns) > 0 { - for _, w := range warns { + if len(warnings) > 0 { + for _, w := range warnings { sess.logFile(fmt.Sprintf("[CommitConf] commit warning: %q", w)) } } if err != nil { sess.logFile(fmt.Sprintf("[CommitConf] commit error: %q", err)) - return warns, err + return warnings, err } - return warns, nil + return warnings, nil } func (sess *Session) Close() { diff --git a/internal/providerfwk/default_resource_op.go b/internal/providerfwk/default_resource_op.go index 00e79f94..b26ae4e6 100644 --- a/internal/providerfwk/default_resource_op.go +++ b/internal/providerfwk/default_resource_op.go @@ -124,7 +124,7 @@ func defaultResourceCreate( return } - warns, err := junSess.CommitConf("create resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "create resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) @@ -268,7 +268,7 @@ func defaultResourceUpdate( return } - warns, err := junSess.CommitConf("update resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "update resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) @@ -318,7 +318,7 @@ func defaultResourceDelete( return } - warns, err := junSess.CommitConf("delete resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "delete resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) diff --git a/internal/providerfwk/provider.go b/internal/providerfwk/provider.go index cc79295e..dc6adf43 100644 --- a/internal/providerfwk/provider.go +++ b/internal/providerfwk/provider.go @@ -33,25 +33,27 @@ var _ provider.Provider = &junosProvider{} type junosProvider struct{} type junosProviderModel struct { - IP types.String `tfsdk:"ip"` - Port types.Int64 `tfsdk:"port"` - Username types.String `tfsdk:"username"` - Password types.String `tfsdk:"password"` - SSHKeyPem types.String `tfsdk:"sshkey_pem"` - SSHKeyFile types.String `tfsdk:"sshkeyfile"` - SSHKeyPass types.String `tfsdk:"keypass"` - GroupIntDel types.String `tfsdk:"group_interface_delete"` - CmdSleepShort types.Int64 `tfsdk:"cmd_sleep_short"` - CmdSleepLock types.Int64 `tfsdk:"cmd_sleep_lock"` - SleepSSHClosed types.Int64 `tfsdk:"ssh_sleep_closed"` - SSHCiphers types.List `tfsdk:"ssh_ciphers"` - SSHTimeoutToEstab types.Int64 `tfsdk:"ssh_timeout_to_establish"` - SSHRetryToEstab types.Int64 `tfsdk:"ssh_retry_to_establish"` - FilePermission types.String `tfsdk:"file_permission"` - DebugNetconfLogPath types.String `tfsdk:"debug_netconf_log_path"` - FakeCreateSetFile types.String `tfsdk:"fake_create_with_setfile"` - FakeUpdateAlso types.Bool `tfsdk:"fake_update_also"` - FakeDeleteAlso types.Bool `tfsdk:"fake_delete_also"` + IP types.String `tfsdk:"ip"` + Port types.Int64 `tfsdk:"port"` + Username types.String `tfsdk:"username"` + Password types.String `tfsdk:"password"` + SSHKeyPem types.String `tfsdk:"sshkey_pem"` + SSHKeyFile types.String `tfsdk:"sshkeyfile"` + SSHKeyPass types.String `tfsdk:"keypass"` + GroupIntDel types.String `tfsdk:"group_interface_delete"` + CmdSleepShort types.Int64 `tfsdk:"cmd_sleep_short"` + CmdSleepLock types.Int64 `tfsdk:"cmd_sleep_lock"` + CommitConfirmed types.Int64 `tfsdk:"commit_confirmed"` + CommitConfirmedWaitPercent types.Int64 `tfsdk:"commit_confirmed_wait_percent"` + SleepSSHClosed types.Int64 `tfsdk:"ssh_sleep_closed"` + SSHCiphers types.List `tfsdk:"ssh_ciphers"` + SSHTimeoutToEstab types.Int64 `tfsdk:"ssh_timeout_to_establish"` + SSHRetryToEstab types.Int64 `tfsdk:"ssh_retry_to_establish"` + FilePermission types.String `tfsdk:"file_permission"` + DebugNetconfLogPath types.String `tfsdk:"debug_netconf_log_path"` + FakeCreateSetFile types.String `tfsdk:"fake_create_with_setfile"` + FakeUpdateAlso types.Bool `tfsdk:"fake_update_also"` + FakeDeleteAlso types.Bool `tfsdk:"fake_delete_also"` } const ( @@ -125,6 +127,30 @@ func (p *junosProvider) Schema( "to lock candidate configuration on a Junos device." + " May also be provided via " + junos.EnvSleepLock + " environment variable.", }, + "commit_confirmed": schema.Int64Attribute{ + Optional: true, + Description: "Number of minutes until automatic rollback." + + " May also be provided via " + junos.EnvCommitConfirmed + " environment variable." + + " For each resource action with commit, commit with `confirmed` option and" + + " with the value ot this argument as `confirm-timeout`, " + + " wait for ``% of the minutes defined in the value of this argument," + + " and confirm commit to avoid rollback with the `commit check` command.", + Validators: []validator.Int64{ + int64validator.Between(1, 65535), + }, + }, + "commit_confirmed_wait_percent": schema.Int64Attribute{ + Optional: true, + Description: "Percentage of `` minute(s) to wait between" + + " `commit confirmed` (commit with automatic rollback) and" + + " `commit check` (confirmation) commands." + + " No effect if `` is not used." + + " May also be provided via " + junos.EnvCommitConfirmedWaitPercent + " environment variable." + + " Defaults to 90.", + Validators: []validator.Int64{ + int64validator.Between(0, 99), + }, + }, "ssh_sleep_closed": schema.Int64Attribute{ Optional: true, Description: "Seconds to wait after Terraform provider closed a ssh connection." + @@ -349,6 +375,22 @@ func (p *junosProvider) Configure( fmt.Sprintf(instructionUnknownMessage, junos.EnvSleepLock), ) } + if config.CommitConfirmed.IsUnknown() { + resp.Diagnostics.AddAttributeError( + path.Root("commit_confirmed"), + tfdiag.UnknownJunosAttrErrSummary, + unknownValueErrorMessage+"for 'commit_confirmed' attribute."+ + fmt.Sprintf(instructionUnknownMessage, junos.EnvCommitConfirmed), + ) + } + if config.CommitConfirmedWaitPercent.IsUnknown() { + resp.Diagnostics.AddAttributeError( + path.Root("commit_confirmed_wait_percent"), + tfdiag.UnknownJunosAttrErrSummary, + unknownValueErrorMessage+"for 'commit_confirmed_wait_percent' attribute."+ + fmt.Sprintf(instructionUnknownMessage, junos.EnvCommitConfirmedWaitPercent), + ) + } if config.SleepSSHClosed.IsUnknown() { resp.Diagnostics.AddAttributeError( path.Root("ssh_sleep_closed"), @@ -560,6 +602,67 @@ func (p *junosProvider) Configure( } } + if !config.CommitConfirmed.IsNull() { + if _, err := client.WithCommitConfirmed(int(config.CommitConfirmed.ValueInt64())); err != nil { + resp.Diagnostics.AddAttributeWarning( + path.Root("commit_confirmed"), + "Bad value in commit_confirmed", + fmt.Sprintf("Error to use value in commit_confirmed attribute: %s\n"+ + "So the attribute is not used", err), + ) + } + } else if v := os.Getenv(junos.EnvCommitConfirmed); v != "" { + d, err := strconv.Atoi(v) + if err != nil { + resp.Diagnostics.AddAttributeWarning( + path.Root("commit_confirmed"), + "Error to parse "+junos.EnvCommitConfirmed, + fmt.Sprintf("Error to parse value in "+junos.EnvCommitConfirmed+" environment variable: %s\n"+ + "So the variable is not used", err), + ) + } else { + if _, err := client.WithCommitConfirmed(d); err != nil { + resp.Diagnostics.AddAttributeWarning( + path.Root("commit_confirmed"), + "Bad value in "+junos.EnvCommitConfirmed, + fmt.Sprintf("Error to use value in "+junos.EnvCommitConfirmed+" environment variable: %s\n"+ + "So the variable is not used", err), + ) + } + } + } + + _, _ = client.WithCommitConfirmedWaitPercent(90) // default value for commit_confirmed_wait_percent + if !config.CommitConfirmedWaitPercent.IsNull() { + if _, err := client.WithCommitConfirmedWaitPercent(int(config.CommitConfirmedWaitPercent.ValueInt64())); err != nil { + resp.Diagnostics.AddAttributeWarning( + path.Root("commit_confirmed_wait_percent"), + "Bad value in commit_confirmed_wait_percent", + fmt.Sprintf("Error to use value in commit_confirmed_wait_percent attribute: %s\n"+ + "So the attribute is not used", err), + ) + } + } else if v := os.Getenv(junos.EnvCommitConfirmedWaitPercent); v != "" { + d, err := strconv.Atoi(v) + if err != nil { + resp.Diagnostics.AddAttributeWarning( + path.Root("commit_confirmed_wait_percent"), + "Error to parse "+junos.EnvCommitConfirmedWaitPercent, + fmt.Sprintf("Error to parse value in "+junos.EnvCommitConfirmedWaitPercent+" environment variable: %s\n"+ + "So the variable is not used", err), + ) + } else { + if _, err := client.WithCommitConfirmedWaitPercent(d); err != nil { + resp.Diagnostics.AddAttributeWarning( + path.Root("commit_confirmed_wait_percent"), + "Bad value in "+junos.EnvCommitConfirmedWaitPercent, + fmt.Sprintf("Error to use value in "+junos.EnvCommitConfirmedWaitPercent+" environment variable: %s\n"+ + "So the variable is not used", err), + ) + } + } + } + if !config.SleepSSHClosed.IsNull() { client.WithSleepSSHClosed(int(config.SleepSSHClosed.ValueInt64())) } else if v := os.Getenv(junos.EnvSleepSSHClosed); v != "" { diff --git a/internal/providerfwk/resource_interface_logical.go b/internal/providerfwk/resource_interface_logical.go index 5dd61a7f..444826f0 100644 --- a/internal/providerfwk/resource_interface_logical.go +++ b/internal/providerfwk/resource_interface_logical.go @@ -1792,7 +1792,7 @@ func (rsc *interfaceLogical) Create( return } - warns, err := junSess.CommitConf("create resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "create resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) @@ -2051,7 +2051,7 @@ func (rsc *interfaceLogical) Update( return } - warns, err := junSess.CommitConf("update resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "update resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) diff --git a/internal/providerfwk/resource_interface_physical.go b/internal/providerfwk/resource_interface_physical.go index 9661d29a..6a1f0f80 100644 --- a/internal/providerfwk/resource_interface_physical.go +++ b/internal/providerfwk/resource_interface_physical.go @@ -1319,7 +1319,7 @@ func (rsc *interfacePhysical) Create( return } - warns, err := junSess.CommitConf("create resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "create resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) @@ -1508,7 +1508,7 @@ func (rsc *interfacePhysical) Update( return } - warns, err := junSess.CommitConf("update resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "update resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) @@ -1561,7 +1561,7 @@ func (rsc *interfacePhysical) Delete( return } - warns, err := junSess.CommitConf("delete resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "delete resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) @@ -1584,7 +1584,7 @@ func (rsc *interfacePhysical) Delete( return } - warns, err = junSess.CommitConf("disable(NC) resource " + rsc.typeName()) + warns, err = junSess.CommitConf(ctx, "disable(NC) resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) diff --git a/internal/providerfwk/resource_interface_physical_disable.go b/internal/providerfwk/resource_interface_physical_disable.go index 3c731763..9097aeb8 100644 --- a/internal/providerfwk/resource_interface_physical_disable.go +++ b/internal/providerfwk/resource_interface_physical_disable.go @@ -190,7 +190,7 @@ func (rsc *interfacePhysicalDisable) Create( return } - warns, err := junSess.CommitConf("create resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "create resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) diff --git a/internal/providerfwk/resource_interface_st0_unit.go b/internal/providerfwk/resource_interface_st0_unit.go index 343b6a55..cd06bb3e 100644 --- a/internal/providerfwk/resource_interface_st0_unit.go +++ b/internal/providerfwk/resource_interface_st0_unit.go @@ -115,7 +115,7 @@ func (rsc *interfaceSt0Unit) Create( return } - warns, err := junSess.CommitConf("create resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "create resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) @@ -267,7 +267,7 @@ func (rsc *interfaceSt0Unit) Delete( return } - warns, err := junSess.CommitConf("delete resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "delete resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) diff --git a/internal/providerfwk/resource_security_nat_static.go b/internal/providerfwk/resource_security_nat_static.go index 442051ff..5c040a17 100644 --- a/internal/providerfwk/resource_security_nat_static.go +++ b/internal/providerfwk/resource_security_nat_static.go @@ -675,7 +675,7 @@ func (rsc *securityNatStatic) Update( return } - warns, err := junSess.CommitConf("update resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "update resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) diff --git a/internal/providerfwk/resource_security_policy.go b/internal/providerfwk/resource_security_policy.go index b61a8893..f9ac29ca 100644 --- a/internal/providerfwk/resource_security_policy.go +++ b/internal/providerfwk/resource_security_policy.go @@ -737,7 +737,7 @@ func (rsc *securityPolicy) Update( return } - warns, err := junSess.CommitConf("update resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "update resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) diff --git a/internal/providerfwk/resource_security_zone.go b/internal/providerfwk/resource_security_zone.go index 95786dba..25e072eb 100644 --- a/internal/providerfwk/resource_security_zone.go +++ b/internal/providerfwk/resource_security_zone.go @@ -796,7 +796,7 @@ func (rsc *securityZone) Update( return } - warns, err := junSess.CommitConf("update resource " + rsc.typeName()) + warns, err := junSess.CommitConf(ctx, "update resource "+rsc.typeName()) resp.Diagnostics.Append(tfdiag.Warns(tfdiag.ConfigCommitWarnSummary, warns)...) if err != nil { resp.Diagnostics.AddError(tfdiag.ConfigCommitErrSummary, err.Error()) diff --git a/internal/providersdk/provider.go b/internal/providersdk/provider.go index c8952f95..bb190ce2 100644 --- a/internal/providersdk/provider.go +++ b/internal/providersdk/provider.go @@ -81,6 +81,28 @@ func Provider() *schema.Provider { "to lock candidate configuration on a Junos device." + " May also be provided via " + junos.EnvSleepLock + " environment variable.", }, + "commit_confirmed": { + Type: schema.TypeInt, + Optional: true, + Description: "Number of minutes until automatic rollback." + + " May also be provided via " + junos.EnvCommitConfirmed + " environment variable." + + " For each resource action with commit, commit with `confirmed` option and" + + " with the value ot this argument as `confirm-timeout`, " + + " wait for ``% of the minutes defined in the value of this argument," + + " and confirm commit to avoid rollback with the `commit check` command.", + ValidateFunc: validation.IntBetween(1, 65535), + }, + "commit_confirmed_wait_percent": { + Type: schema.TypeInt, + Optional: true, + Description: "Percentage of `` minute(s) to wait between" + + " `commit confirmed` (commit with automatic rollback) and" + + " `commit check` (confirmation) commands." + + " No effect if `` is not used." + + " May also be provided via " + junos.EnvCommitConfirmedWaitPercent + " environment variable." + + " Defaults to 90.", + ValidateFunc: validation.IntBetween(0, 99), + }, "ssh_sleep_closed": { Type: schema.TypeInt, Optional: true, @@ -344,6 +366,67 @@ func configureProvider(_ context.Context, d *schema.ResourceData) (interface{}, } } + if v, ok := d.GetOk("commit_confirmed"); ok { + if _, err := client.WithCommitConfirmed(v.(int)); err != nil { + diagWarns = append(diagWarns, diag.Diagnostic{ + Severity: diag.Warning, + Summary: "Bad value in commit_confirmed", + Detail: fmt.Sprintf("Error to use value in commit_confirmed attribute: %s\n"+ + "So the attribute is not used", err), + }) + } + } else if v := os.Getenv(junos.EnvCommitConfirmed); v != "" { + d, err := strconv.Atoi(v) + if err != nil { + diagWarns = append(diagWarns, diag.Diagnostic{ + Severity: diag.Warning, + Summary: "Error to parse " + junos.EnvCommitConfirmed, + Detail: fmt.Sprintf("Error to parse value in "+junos.EnvCommitConfirmed+" environment variable: %s\n"+ + "So the variable is not used", err), + }) + } else { + if _, err := client.WithCommitConfirmed(d); err != nil { + diagWarns = append(diagWarns, diag.Diagnostic{ + Severity: diag.Warning, + Summary: "Bad value in " + junos.EnvCommitConfirmed, + Detail: fmt.Sprintf("Error to use value in "+junos.EnvCommitConfirmed+" environment variable: %s\n"+ + "So the variable is not used", err), + }) + } + } + } + + _, _ = client.WithCommitConfirmedWaitPercent(90) // default value for commit_confirmed_wait_percent + if v, ok := d.GetOk("commit_confirmed_wait_percent"); ok { + if _, err := client.WithCommitConfirmedWaitPercent(v.(int)); err != nil { + diagWarns = append(diagWarns, diag.Diagnostic{ + Severity: diag.Warning, + Summary: "Bad value in commit_confirmed_wait_percent", + Detail: fmt.Sprintf("Error to use value in commit_confirmed_wait_percent attribute: %s\n"+ + "So the attribute is not used", err), + }) + } + } else if v := os.Getenv(junos.EnvCommitConfirmedWaitPercent); v != "" { + d, err := strconv.Atoi(v) + if err != nil { + diagWarns = append(diagWarns, diag.Diagnostic{ + Severity: diag.Warning, + Summary: "Error to parse " + junos.EnvCommitConfirmedWaitPercent, + Detail: fmt.Sprintf("Error to parse value in "+junos.EnvCommitConfirmedWaitPercent+" environment variable: %s\n"+ + "So the variable is not used", err), + }) + } else { + if _, err := client.WithCommitConfirmedWaitPercent(d); err != nil { + diagWarns = append(diagWarns, diag.Diagnostic{ + Severity: diag.Warning, + Summary: "Bad value in " + junos.EnvCommitConfirmedWaitPercent, + Detail: fmt.Sprintf("Error to use value in "+junos.EnvCommitConfirmedWaitPercent+" environment variable: %s\n"+ + "So the variable is not used", err), + }) + } + } + } + if v, ok := d.GetOk("ssh_sleep_closed"); ok { client.WithSleepSSHClosed(v.(int)) } else if v := os.Getenv(junos.EnvSleepSSHClosed); v != "" { diff --git a/internal/providersdk/resource_access_address_assignment_pool.go b/internal/providersdk/resource_access_address_assignment_pool.go index a99edb8c..7ba036a8 100644 --- a/internal/providersdk/resource_access_address_assignment_pool.go +++ b/internal/providersdk/resource_access_address_assignment_pool.go @@ -533,7 +533,7 @@ func resourceAccessAddressAssignPoolCreate(ctx context.Context, d *schema.Resour return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_access_address_assignment_pool") + warns, err := junSess.CommitConf(ctx, "create resource junos_access_address_assignment_pool") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -634,7 +634,7 @@ func resourceAccessAddressAssignPoolUpdate(ctx context.Context, d *schema.Resour return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_access_address_assignment_pool") + warns, err := junSess.CommitConf(ctx, "update resource junos_access_address_assignment_pool") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -679,7 +679,7 @@ func resourceAccessAddressAssignPoolDelete(ctx context.Context, d *schema.Resour return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_access_address_assignment_pool") + warns, err := junSess.CommitConf(ctx, "delete resource junos_access_address_assignment_pool") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_chassis_cluster.go b/internal/providersdk/resource_chassis_cluster.go index ce2db324..c7b4cd20 100644 --- a/internal/providersdk/resource_chassis_cluster.go +++ b/internal/providersdk/resource_chassis_cluster.go @@ -251,7 +251,7 @@ func resourceChassisClusterCreate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_chassis_cluster") + warns, err := junSess.CommitConf(ctx, "create resource junos_chassis_cluster") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -321,7 +321,7 @@ func resourceChassisClusterUpdate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_chassis_cluster") + warns, err := junSess.CommitConf(ctx, "update resource junos_chassis_cluster") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -357,7 +357,7 @@ func resourceChassisClusterDelete(ctx context.Context, _ *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_chassis_cluster") + warns, err := junSess.CommitConf(ctx, "delete resource junos_chassis_cluster") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_chassis_redundancy.go b/internal/providersdk/resource_chassis_redundancy.go index 32974920..94423522 100644 --- a/internal/providersdk/resource_chassis_redundancy.go +++ b/internal/providersdk/resource_chassis_redundancy.go @@ -115,7 +115,7 @@ func resourceChassisRedundancyCreate(ctx context.Context, d *schema.ResourceData return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_chassis_redundancy") + warns, err := junSess.CommitConf(ctx, "create resource junos_chassis_redundancy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -185,7 +185,7 @@ func resourceChassisRedundancyUpdate(ctx context.Context, d *schema.ResourceData return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_chassis_redundancy") + warns, err := junSess.CommitConf(ctx, "update resource junos_chassis_redundancy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -221,7 +221,7 @@ func resourceChassisRedundancyDelete(ctx context.Context, _ *schema.ResourceData return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_chassis_redundancy") + warns, err := junSess.CommitConf(ctx, "delete resource junos_chassis_redundancy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_eventoptions_destination.go b/internal/providersdk/resource_eventoptions_destination.go index 5bda200a..9174876d 100644 --- a/internal/providersdk/resource_eventoptions_destination.go +++ b/internal/providersdk/resource_eventoptions_destination.go @@ -104,7 +104,7 @@ func resourceEventoptionsDestinationCreate(ctx context.Context, d *schema.Resour return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_eventoptions_destination") + warns, err := junSess.CommitConf(ctx, "create resource junos_eventoptions_destination") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -188,7 +188,7 @@ func resourceEventoptionsDestinationUpdate(ctx context.Context, d *schema.Resour return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_eventoptions_destination") + warns, err := junSess.CommitConf(ctx, "update resource junos_eventoptions_destination") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -225,7 +225,7 @@ func resourceEventoptionsDestinationDelete(ctx context.Context, d *schema.Resour return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_eventoptions_destination") + warns, err := junSess.CommitConf(ctx, "delete resource junos_eventoptions_destination") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_eventoptions_generate_event.go b/internal/providersdk/resource_eventoptions_generate_event.go index c6fce309..03d607ee 100644 --- a/internal/providersdk/resource_eventoptions_generate_event.go +++ b/internal/providersdk/resource_eventoptions_generate_event.go @@ -97,7 +97,7 @@ func resourceEventoptionsGenerateEventCreate(ctx context.Context, d *schema.Reso return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_eventoptions_generate_event") + warns, err := junSess.CommitConf(ctx, "create resource junos_eventoptions_generate_event") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -182,7 +182,7 @@ func resourceEventoptionsGenerateEventUpdate(ctx context.Context, d *schema.Reso return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_eventoptions_generate_event") + warns, err := junSess.CommitConf(ctx, "update resource junos_eventoptions_generate_event") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -219,7 +219,7 @@ func resourceEventoptionsGenerateEventDelete(ctx context.Context, d *schema.Reso return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_eventoptions_generate_event") + warns, err := junSess.CommitConf(ctx, "delete resource junos_eventoptions_generate_event") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_eventoptions_policy.go b/internal/providersdk/resource_eventoptions_policy.go index 0ca245ed..1db6c631 100644 --- a/internal/providersdk/resource_eventoptions_policy.go +++ b/internal/providersdk/resource_eventoptions_policy.go @@ -507,7 +507,7 @@ func resourceEventoptionsPolicyCreate(ctx context.Context, d *schema.ResourceDat return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_eventoptions_policy") + warns, err := junSess.CommitConf(ctx, "create resource junos_eventoptions_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -590,7 +590,7 @@ func resourceEventoptionsPolicyUpdate(ctx context.Context, d *schema.ResourceDat return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_eventoptions_policy") + warns, err := junSess.CommitConf(ctx, "update resource junos_eventoptions_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -626,7 +626,7 @@ func resourceEventoptionsPolicyDelete(ctx context.Context, d *schema.ResourceDat return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_eventoptions_policy") + warns, err := junSess.CommitConf(ctx, "delete resource junos_eventoptions_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_forwardingoptions_dhcprelay.go b/internal/providersdk/resource_forwardingoptions_dhcprelay.go index d860e0ff..b6f470dd 100644 --- a/internal/providersdk/resource_forwardingoptions_dhcprelay.go +++ b/internal/providersdk/resource_forwardingoptions_dhcprelay.go @@ -598,7 +598,7 @@ func resourceForwardingOptionsDhcpRelayCreate(ctx context.Context, d *schema.Res return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_forwardingoptions_dhcprelay") + warns, err := junSess.CommitConf(ctx, "create resource junos_forwardingoptions_dhcprelay") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -692,7 +692,7 @@ func resourceForwardingOptionsDhcpRelayUpdate(ctx context.Context, d *schema.Res return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_forwardingoptions_dhcprelay") + warns, err := junSess.CommitConf(ctx, "update resource junos_forwardingoptions_dhcprelay") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -731,7 +731,7 @@ func resourceForwardingOptionsDhcpRelayDelete(ctx context.Context, d *schema.Res return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_forwardingoptions_dhcprelay") + warns, err := junSess.CommitConf(ctx, "delete resource junos_forwardingoptions_dhcprelay") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_forwardingoptions_dhcprelay_group.go b/internal/providersdk/resource_forwardingoptions_dhcprelay_group.go index a331985a..f1e7c4dd 100644 --- a/internal/providersdk/resource_forwardingoptions_dhcprelay_group.go +++ b/internal/providersdk/resource_forwardingoptions_dhcprelay_group.go @@ -644,7 +644,7 @@ func resourceForwardingOptionsDhcpRelayGroupCreate(ctx context.Context, d *schem return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_forwardingoptions_dhcprelay_group") + warns, err := junSess.CommitConf(ctx, "create resource junos_forwardingoptions_dhcprelay_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -751,7 +751,7 @@ func resourceForwardingOptionsDhcpRelayGroupUpdate(ctx context.Context, d *schem return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_forwardingoptions_dhcprelay_group") + warns, err := junSess.CommitConf(ctx, "update resource junos_forwardingoptions_dhcprelay_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -791,7 +791,7 @@ func resourceForwardingOptionsDhcpRelayGroupDelete(ctx context.Context, d *schem return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_forwardingoptions_dhcprelay_group") + warns, err := junSess.CommitConf(ctx, "delete resource junos_forwardingoptions_dhcprelay_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_forwardingoptions_dhcprelay_servergroup.go b/internal/providersdk/resource_forwardingoptions_dhcprelay_servergroup.go index c319a070..36d8d438 100644 --- a/internal/providersdk/resource_forwardingoptions_dhcprelay_servergroup.go +++ b/internal/providersdk/resource_forwardingoptions_dhcprelay_servergroup.go @@ -129,7 +129,7 @@ func resourceForwardingOptionsDhcpRelayServerGroupCreate(ctx context.Context, d return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_forwardingoptions_dhcprelay_servergroup") + warns, err := junSess.CommitConf(ctx, "create resource junos_forwardingoptions_dhcprelay_servergroup") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -236,7 +236,7 @@ func resourceForwardingOptionsDhcpRelayServerGroupUpdate(ctx context.Context, d return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_forwardingoptions_dhcprelay_servergroup") + warns, err := junSess.CommitConf(ctx, "update resource junos_forwardingoptions_dhcprelay_servergroup") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -276,7 +276,7 @@ func resourceForwardingOptionsDhcpRelayServerGroupDelete(ctx context.Context, d return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_forwardingoptions_dhcprelay_servergroup") + warns, err := junSess.CommitConf(ctx, "delete resource junos_forwardingoptions_dhcprelay_servergroup") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_group_dual_system.go b/internal/providersdk/resource_group_dual_system.go index 0bf4e897..e2958d0c 100644 --- a/internal/providersdk/resource_group_dual_system.go +++ b/internal/providersdk/resource_group_dual_system.go @@ -221,7 +221,7 @@ func resourceGroupDualSystemCreate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_group_dual_system") + warns, err := junSess.CommitConf(ctx, "create resource junos_group_dual_system") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -322,7 +322,7 @@ func resourceGroupDualSystemUpdate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_group_dual_system") + warns, err := junSess.CommitConf(ctx, "update resource junos_group_dual_system") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -376,7 +376,7 @@ func resourceGroupDualSystemDelete(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_group_dual_system") + warns, err := junSess.CommitConf(ctx, "delete resource junos_group_dual_system") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_igmp_snooping_vlan.go b/internal/providersdk/resource_igmp_snooping_vlan.go index e4bea627..68830c91 100644 --- a/internal/providersdk/resource_igmp_snooping_vlan.go +++ b/internal/providersdk/resource_igmp_snooping_vlan.go @@ -216,7 +216,7 @@ func resourceIgmpSnoopingVlanCreate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_igmp_snooping_vlan") + warns, err := junSess.CommitConf(ctx, "create resource junos_igmp_snooping_vlan") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -313,7 +313,7 @@ func resourceIgmpSnoopingVlanUpdate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_igmp_snooping_vlan") + warns, err := junSess.CommitConf(ctx, "update resource junos_igmp_snooping_vlan") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -349,7 +349,7 @@ func resourceIgmpSnoopingVlanDelete(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_igmp_snooping_vlan") + warns, err := junSess.CommitConf(ctx, "delete resource junos_igmp_snooping_vlan") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_layer2_control.go b/internal/providersdk/resource_layer2_control.go index 44ba4232..baf00d7b 100644 --- a/internal/providersdk/resource_layer2_control.go +++ b/internal/providersdk/resource_layer2_control.go @@ -140,7 +140,7 @@ func resourceLayer2ControlCreate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_layer2_control") + warns, err := junSess.CommitConf(ctx, "create resource junos_layer2_control") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -210,7 +210,7 @@ func resourceLayer2ControlUpdate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_layer2_control") + warns, err := junSess.CommitConf(ctx, "update resource junos_layer2_control") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -246,7 +246,7 @@ func resourceLayer2ControlDelete(ctx context.Context, _ *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_layer2_control") + warns, err := junSess.CommitConf(ctx, "delete resource junos_layer2_control") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_lldp_interface.go b/internal/providersdk/resource_lldp_interface.go index 28446621..42517eca 100644 --- a/internal/providersdk/resource_lldp_interface.go +++ b/internal/providersdk/resource_lldp_interface.go @@ -126,7 +126,7 @@ func resourceLldpInterfaceCreate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_lldp_interface") + warns, err := junSess.CommitConf(ctx, "create resource junos_lldp_interface") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -209,7 +209,7 @@ func resourceLldpInterfaceUpdate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_lldp_interface") + warns, err := junSess.CommitConf(ctx, "update resource junos_lldp_interface") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -245,7 +245,7 @@ func resourceLldpInterfaceDelete(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_lldp_interface") + warns, err := junSess.CommitConf(ctx, "delete resource junos_lldp_interface") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_lldpmed_interface.go b/internal/providersdk/resource_lldpmed_interface.go index 996beb37..a948403b 100644 --- a/internal/providersdk/resource_lldpmed_interface.go +++ b/internal/providersdk/resource_lldpmed_interface.go @@ -171,7 +171,7 @@ func resourceLldpMedInterfaceCreate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_lldpmed_interface") + warns, err := junSess.CommitConf(ctx, "create resource junos_lldpmed_interface") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -254,7 +254,7 @@ func resourceLldpMedInterfaceUpdate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_lldpmed_interface") + warns, err := junSess.CommitConf(ctx, "update resource junos_lldpmed_interface") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -290,7 +290,7 @@ func resourceLldpMedInterfaceDelete(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_lldpmed_interface") + warns, err := junSess.CommitConf(ctx, "delete resource junos_lldpmed_interface") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_null_commit_file.go b/internal/providersdk/resource_null_commit_file.go index c80fb37e..6395a251 100644 --- a/internal/providersdk/resource_null_commit_file.go +++ b/internal/providersdk/resource_null_commit_file.go @@ -71,7 +71,7 @@ func resourceNullCommitFileCreate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("commit a file with resource junos_null_commit_file") + warns, err := junSess.CommitConf(ctx, "commit a file with resource junos_null_commit_file") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_ospf.go b/internal/providersdk/resource_ospf.go index 36f5b31e..6fa1a7e1 100644 --- a/internal/providersdk/resource_ospf.go +++ b/internal/providersdk/resource_ospf.go @@ -323,7 +323,7 @@ func resourceOspfCreate(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_ospf") + warns, err := junSess.CommitConf(ctx, "create resource junos_ospf") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -406,7 +406,7 @@ func resourceOspfUpdate(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_ospf") + warns, err := junSess.CommitConf(ctx, "update resource junos_ospf") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -443,7 +443,7 @@ func resourceOspfDelete(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_ospf") + warns, err := junSess.CommitConf(ctx, "delete resource junos_ospf") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_ospf_area.go b/internal/providersdk/resource_ospf_area.go index 12095afe..27648eea 100644 --- a/internal/providersdk/resource_ospf_area.go +++ b/internal/providersdk/resource_ospf_area.go @@ -657,7 +657,7 @@ func resourceOspfAreaCreate(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_ospf_area") + warns, err := junSess.CommitConf(ctx, "create resource junos_ospf_area") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -765,7 +765,7 @@ func resourceOspfAreaUpdate(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_ospf_area") + warns, err := junSess.CommitConf(ctx, "update resource junos_ospf_area") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -801,7 +801,7 @@ func resourceOspfAreaDelete(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_ospf_area") + warns, err := junSess.CommitConf(ctx, "delete resource junos_ospf_area") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_rib_group.go b/internal/providersdk/resource_rib_group.go index a147fe5d..70cbdbe5 100644 --- a/internal/providersdk/resource_rib_group.go +++ b/internal/providersdk/resource_rib_group.go @@ -95,7 +95,7 @@ func resourceRibGroupCreate(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_rib_group") + warns, err := junSess.CommitConf(ctx, "create resource junos_rib_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -208,7 +208,7 @@ func resourceRibGroupUpdate(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_rib_group") + warns, err := junSess.CommitConf(ctx, "update resource junos_rib_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -244,7 +244,7 @@ func resourceRibGroupDelete(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_rib_group") + warns, err := junSess.CommitConf(ctx, "delete resource junos_rib_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_rip_group.go b/internal/providersdk/resource_rip_group.go index ade5241d..e150088c 100644 --- a/internal/providersdk/resource_rip_group.go +++ b/internal/providersdk/resource_rip_group.go @@ -234,7 +234,7 @@ func resourceRipGroupCreate(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_rip_group") + warns, err := junSess.CommitConf(ctx, "create resource junos_rip_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -348,7 +348,7 @@ func resourceRipGroupUpdate(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_rip_group") + warns, err := junSess.CommitConf(ctx, "update resource junos_rip_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -396,7 +396,7 @@ func resourceRipGroupDelete(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_rip_group") + warns, err := junSess.CommitConf(ctx, "delete resource junos_rip_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_rip_neighbor.go b/internal/providersdk/resource_rip_neighbor.go index f3577baa..99c52101 100644 --- a/internal/providersdk/resource_rip_neighbor.go +++ b/internal/providersdk/resource_rip_neighbor.go @@ -355,7 +355,7 @@ func resourceRipNeighborCreate(ctx context.Context, d *schema.ResourceData, m in return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_rip_neighbor") + warns, err := junSess.CommitConf(ctx, "create resource junos_rip_neighbor") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -470,7 +470,7 @@ func resourceRipNeighborUpdate(ctx context.Context, d *schema.ResourceData, m in return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_rip_neighbor") + warns, err := junSess.CommitConf(ctx, "update resource junos_rip_neighbor") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -518,7 +518,7 @@ func resourceRipNeighborDelete(ctx context.Context, d *schema.ResourceData, m in return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_rip_neighbor") + warns, err := junSess.CommitConf(ctx, "delete resource junos_rip_neighbor") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_routing_options.go b/internal/providersdk/resource_routing_options.go index 98e9e783..6b30cbb1 100644 --- a/internal/providersdk/resource_routing_options.go +++ b/internal/providersdk/resource_routing_options.go @@ -215,7 +215,7 @@ func resourceRoutingOptionsCreate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_routing_options") + warns, err := junSess.CommitConf(ctx, "create resource junos_routing_options") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -307,7 +307,7 @@ func resourceRoutingOptionsUpdate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_routing_options") + warns, err := junSess.CommitConf(ctx, "update resource junos_routing_options") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -344,7 +344,7 @@ func resourceRoutingOptionsDelete(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_routing_options") + warns, err := junSess.CommitConf(ctx, "delete resource junos_routing_options") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_rstp.go b/internal/providersdk/resource_rstp.go index 196c37c3..effea00e 100644 --- a/internal/providersdk/resource_rstp.go +++ b/internal/providersdk/resource_rstp.go @@ -176,7 +176,7 @@ func resourceRstpCreate(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_rstp") + warns, err := junSess.CommitConf(ctx, "create resource junos_rstp") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -259,7 +259,7 @@ func resourceRstpUpdate(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_rstp") + warns, err := junSess.CommitConf(ctx, "update resource junos_rstp") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -295,7 +295,7 @@ func resourceRstpDelete(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_rstp") + warns, err := junSess.CommitConf(ctx, "delete resource junos_rstp") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_rstp_interface.go b/internal/providersdk/resource_rstp_interface.go index f94ff05e..2c5bdcf7 100644 --- a/internal/providersdk/resource_rstp_interface.go +++ b/internal/providersdk/resource_rstp_interface.go @@ -159,7 +159,7 @@ func resourceRstpInterfaceCreate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_rstp_interface") + warns, err := junSess.CommitConf(ctx, "create resource junos_rstp_interface") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -256,7 +256,7 @@ func resourceRstpInterfaceUpdate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_rstp_interface") + warns, err := junSess.CommitConf(ctx, "update resource junos_rstp_interface") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -292,7 +292,7 @@ func resourceRstpInterfaceDelete(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_rstp_interface") + warns, err := junSess.CommitConf(ctx, "delete resource junos_rstp_interface") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_dynamic_address_feed_server.go b/internal/providersdk/resource_security_dynamic_address_feed_server.go index 26fd01fe..2e152dda 100644 --- a/internal/providersdk/resource_security_dynamic_address_feed_server.go +++ b/internal/providersdk/resource_security_dynamic_address_feed_server.go @@ -161,7 +161,7 @@ func resourceSecurityDynamicAddressFeedServerCreate(ctx context.Context, d *sche return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_dynamic_address_feed_server") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_dynamic_address_feed_server") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -250,7 +250,7 @@ func resourceSecurityDynamicAddressFeedServerUpdate(ctx context.Context, d *sche return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_dynamic_address_feed_server") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_dynamic_address_feed_server") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -287,7 +287,7 @@ func resourceSecurityDynamicAddressFeedServerDelete(ctx context.Context, d *sche return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_dynamic_address_feed_server") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_dynamic_address_feed_server") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_dynamic_address_name.go b/internal/providersdk/resource_security_dynamic_address_name.go index 40381aeb..bdf92916 100644 --- a/internal/providersdk/resource_security_dynamic_address_name.go +++ b/internal/providersdk/resource_security_dynamic_address_name.go @@ -134,7 +134,7 @@ func resourceSecurityDynamicAddressNameCreate(ctx context.Context, d *schema.Res return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_dynamic_address_name") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_dynamic_address_name") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -219,7 +219,7 @@ func resourceSecurityDynamicAddressNameUpdate(ctx context.Context, d *schema.Res return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_dynamic_address_name") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_dynamic_address_name") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -256,7 +256,7 @@ func resourceSecurityDynamicAddressNameDelete(ctx context.Context, d *schema.Res return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_dynamic_address_name") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_dynamic_address_name") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_idp_custom_attack.go b/internal/providersdk/resource_security_idp_custom_attack.go index 23151344..167e8167 100644 --- a/internal/providersdk/resource_security_idp_custom_attack.go +++ b/internal/providersdk/resource_security_idp_custom_attack.go @@ -860,7 +860,7 @@ func resourceSecurityIdpCustomAttackCreate(ctx context.Context, d *schema.Resour return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_idp_custom_attack") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_idp_custom_attack") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -944,7 +944,7 @@ func resourceSecurityIdpCustomAttackUpdate(ctx context.Context, d *schema.Resour return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_idp_custom_attack") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_idp_custom_attack") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -981,7 +981,7 @@ func resourceSecurityIdpCustomAttackDelete(ctx context.Context, d *schema.Resour return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_idp_custom_attack") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_idp_custom_attack") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_idp_custom_attack_group.go b/internal/providersdk/resource_security_idp_custom_attack_group.go index 2e58ca18..91bfc250 100644 --- a/internal/providersdk/resource_security_idp_custom_attack_group.go +++ b/internal/providersdk/resource_security_idp_custom_attack_group.go @@ -84,7 +84,7 @@ func resourceSecurityIdpCustomAttackGroupCreate(ctx context.Context, d *schema.R return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_idp_custom_attack_group") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_idp_custom_attack_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -170,7 +170,7 @@ func resourceSecurityIdpCustomAttackGroupUpdate(ctx context.Context, d *schema.R return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_idp_custom_attack_group") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_idp_custom_attack_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -207,7 +207,7 @@ func resourceSecurityIdpCustomAttackGroupDelete(ctx context.Context, d *schema.R return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_idp_custom_attack_group") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_idp_custom_attack_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_idp_policy.go b/internal/providersdk/resource_security_idp_policy.go index 8c7b5c5c..6c88aee6 100644 --- a/internal/providersdk/resource_security_idp_policy.go +++ b/internal/providersdk/resource_security_idp_policy.go @@ -322,7 +322,7 @@ func resourceSecurityIdpPolicyCreate(ctx context.Context, d *schema.ResourceData return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_idp_policy") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_idp_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -405,7 +405,7 @@ func resourceSecurityIdpPolicyUpdate(ctx context.Context, d *schema.ResourceData return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_idp_policy") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_idp_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -441,7 +441,7 @@ func resourceSecurityIdpPolicyDelete(ctx context.Context, d *schema.ResourceData return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_idp_policy") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_idp_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_log_stream.go b/internal/providersdk/resource_security_log_stream.go index ed907c00..4dee241c 100644 --- a/internal/providersdk/resource_security_log_stream.go +++ b/internal/providersdk/resource_security_log_stream.go @@ -166,7 +166,7 @@ func resourceSecurityLogStreamCreate(ctx context.Context, d *schema.ResourceData return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_log_stream") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_log_stream") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -249,7 +249,7 @@ func resourceSecurityLogStreamUpdate(ctx context.Context, d *schema.ResourceData return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_log_stream") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_log_stream") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -285,7 +285,7 @@ func resourceSecurityLogStreamDelete(ctx context.Context, d *schema.ResourceData return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_log_stream") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_log_stream") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_screen.go b/internal/providersdk/resource_security_screen.go index b8a6035b..63e9d32b 100644 --- a/internal/providersdk/resource_security_screen.go +++ b/internal/providersdk/resource_security_screen.go @@ -642,7 +642,7 @@ func resourceSecurityScreenCreate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_screen") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_screen") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -725,7 +725,7 @@ func resourceSecurityScreenUpdate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_screen") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_screen") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -761,7 +761,7 @@ func resourceSecurityScreenDelete(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_screen") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_screen") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_screen_whitelist.go b/internal/providersdk/resource_security_screen_whitelist.go index d3e14c3c..c3f973d4 100644 --- a/internal/providersdk/resource_security_screen_whitelist.go +++ b/internal/providersdk/resource_security_screen_whitelist.go @@ -89,7 +89,7 @@ func resourceSecurityScreenWhiteListCreate(ctx context.Context, d *schema.Resour return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_screen_whitelist") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_screen_whitelist") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -174,7 +174,7 @@ func resourceSecurityScreenWhiteListUpdate(ctx context.Context, d *schema.Resour return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_screen_whitelist") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_screen_whitelist") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -211,7 +211,7 @@ func resourceSecurityScreenWhiteListDelete(ctx context.Context, d *schema.Resour return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_screen_whitelist") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_screen_whitelist") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_utm_custom_url_category.go b/internal/providersdk/resource_security_utm_custom_url_category.go index 79b7c332..307864ff 100644 --- a/internal/providersdk/resource_security_utm_custom_url_category.go +++ b/internal/providersdk/resource_security_utm_custom_url_category.go @@ -86,7 +86,7 @@ func resourceSecurityUtmCustomURLCategoryCreate(ctx context.Context, d *schema.R return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_utm_custom_url_category") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_utm_custom_url_category") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -171,7 +171,7 @@ func resourceSecurityUtmCustomURLCategoryUpdate(ctx context.Context, d *schema.R return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_utm_custom_url_category") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_utm_custom_url_category") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -208,7 +208,7 @@ func resourceSecurityUtmCustomURLCategoryDelete(ctx context.Context, d *schema.R return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_utm_custom_url_category") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_utm_custom_url_category") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_utm_custom_url_pattern.go b/internal/providersdk/resource_security_utm_custom_url_pattern.go index 935db62e..1543f479 100644 --- a/internal/providersdk/resource_security_utm_custom_url_pattern.go +++ b/internal/providersdk/resource_security_utm_custom_url_pattern.go @@ -85,7 +85,7 @@ func resourceSecurityUtmCustomURLPatternCreate(ctx context.Context, d *schema.Re return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_utm_custom_url_pattern") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_utm_custom_url_pattern") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -170,7 +170,7 @@ func resourceSecurityUtmCustomURLPatternUpdate(ctx context.Context, d *schema.Re return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_utm_custom_url_pattern") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_utm_custom_url_pattern") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -207,7 +207,7 @@ func resourceSecurityUtmCustomURLPatternDelete(ctx context.Context, d *schema.Re return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_utm_custom_url_pattern") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_utm_custom_url_pattern") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_utm_policy.go b/internal/providersdk/resource_security_utm_policy.go index ea73e01f..5ac64cb3 100644 --- a/internal/providersdk/resource_security_utm_policy.go +++ b/internal/providersdk/resource_security_utm_policy.go @@ -178,7 +178,7 @@ func resourceSecurityUtmPolicyCreate(ctx context.Context, d *schema.ResourceData return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_utm_policy") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_utm_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -261,7 +261,7 @@ func resourceSecurityUtmPolicyUpdate(ctx context.Context, d *schema.ResourceData return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_utm_policy") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_utm_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -297,7 +297,7 @@ func resourceSecurityUtmPolicyDelete(ctx context.Context, d *schema.ResourceData return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_utm_policy") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_utm_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_utm_profile_web_filtering_juniper_enhanced.go b/internal/providersdk/resource_security_utm_profile_web_filtering_juniper_enhanced.go index b10a7fbf..44cbaf73 100644 --- a/internal/providersdk/resource_security_utm_profile_web_filtering_juniper_enhanced.go +++ b/internal/providersdk/resource_security_utm_profile_web_filtering_juniper_enhanced.go @@ -234,7 +234,7 @@ func resourceSecurityUtmProfileWebFilteringEnhancedCreate(ctx context.Context, d return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_utm_profile_web_filtering_juniper_enhanced") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_utm_profile_web_filtering_juniper_enhanced") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -320,7 +320,7 @@ func resourceSecurityUtmProfileWebFilteringEnhancedUpdate(ctx context.Context, d return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_utm_profile_web_filtering_juniper_enhanced") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_utm_profile_web_filtering_juniper_enhanced") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -357,7 +357,7 @@ func resourceSecurityUtmProfileWebFilteringEnhancedDelete(ctx context.Context, d return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_utm_profile_web_filtering_juniper_enhanced") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_utm_profile_web_filtering_juniper_enhanced") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_utm_profile_web_filtering_juniper_local.go b/internal/providersdk/resource_security_utm_profile_web_filtering_juniper_local.go index 8191dfa6..f2560b2e 100644 --- a/internal/providersdk/resource_security_utm_profile_web_filtering_juniper_local.go +++ b/internal/providersdk/resource_security_utm_profile_web_filtering_juniper_local.go @@ -127,7 +127,7 @@ func resourceSecurityUtmProfileWebFilteringLocalCreate(ctx context.Context, d *s return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_utm_profile_web_filtering_juniper_local") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_utm_profile_web_filtering_juniper_local") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -213,7 +213,7 @@ func resourceSecurityUtmProfileWebFilteringLocalUpdate(ctx context.Context, d *s return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_utm_profile_web_filtering_juniper_local") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_utm_profile_web_filtering_juniper_local") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -250,7 +250,7 @@ func resourceSecurityUtmProfileWebFilteringLocalDelete(ctx context.Context, d *s return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_utm_profile_web_filtering_juniper_local") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_utm_profile_web_filtering_juniper_local") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_security_utm_profile_web_filtering_websense_redirect.go b/internal/providersdk/resource_security_utm_profile_web_filtering_websense_redirect.go index f79b86ba..599d6eef 100644 --- a/internal/providersdk/resource_security_utm_profile_web_filtering_websense_redirect.go +++ b/internal/providersdk/resource_security_utm_profile_web_filtering_websense_redirect.go @@ -151,7 +151,7 @@ func resourceSecurityUtmProfileWebFilteringWebsenseCreate(ctx context.Context, d return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_security_utm_profile_web_filtering_websense_redirect") + warns, err := junSess.CommitConf(ctx, "create resource junos_security_utm_profile_web_filtering_websense_redirect") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -237,7 +237,7 @@ func resourceSecurityUtmProfileWebFilteringWebsenseUpdate(ctx context.Context, d return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_security_utm_profile_web_filtering_websense_redirect") + warns, err := junSess.CommitConf(ctx, "update resource junos_security_utm_profile_web_filtering_websense_redirect") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -274,7 +274,7 @@ func resourceSecurityUtmProfileWebFilteringWebsenseDelete(ctx context.Context, d return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_security_utm_profile_web_filtering_websense_redirect") + warns, err := junSess.CommitConf(ctx, "delete resource junos_security_utm_profile_web_filtering_websense_redirect") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_services.go b/internal/providersdk/resource_services.go index 5fe17f2e..319e7f88 100644 --- a/internal/providersdk/resource_services.go +++ b/internal/providersdk/resource_services.go @@ -642,7 +642,7 @@ func resourceServicesCreate(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_services") + warns, err := junSess.CommitConf(ctx, "create resource junos_services") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -711,7 +711,7 @@ func resourceServicesUpdate(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_services") + warns, err := junSess.CommitConf(ctx, "update resource junos_services") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -748,7 +748,7 @@ func resourceServicesDelete(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_services") + warns, err := junSess.CommitConf(ctx, "delete resource junos_services") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_services_advanced_anti_malware_policy.go b/internal/providersdk/resource_services_advanced_anti_malware_policy.go index 636a61e4..4ac4499a 100644 --- a/internal/providersdk/resource_services_advanced_anti_malware_policy.go +++ b/internal/providersdk/resource_services_advanced_anti_malware_policy.go @@ -182,7 +182,7 @@ func resourceServicesAdvancedAntiMalwarePolicyCreate(ctx context.Context, d *sch return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_services_advanced_anti_malware_policy") + warns, err := junSess.CommitConf(ctx, "create resource junos_services_advanced_anti_malware_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -275,7 +275,7 @@ func resourceServicesAdvancedAntiMalwarePolicyUpdate(ctx context.Context, d *sch return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_services_advanced_anti_malware_policy") + warns, err := junSess.CommitConf(ctx, "update resource junos_services_advanced_anti_malware_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -312,7 +312,7 @@ func resourceServicesAdvancedAntiMalwarePolicyDelete(ctx context.Context, d *sch return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_services_advanced_anti_malware_policy") + warns, err := junSess.CommitConf(ctx, "delete resource junos_services_advanced_anti_malware_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_services_proxy_profile.go b/internal/providersdk/resource_services_proxy_profile.go index 96dba7bb..806c70cf 100644 --- a/internal/providersdk/resource_services_proxy_profile.go +++ b/internal/providersdk/resource_services_proxy_profile.go @@ -87,7 +87,7 @@ func resourceServicesProxyProfileCreate(ctx context.Context, d *schema.ResourceD return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_services_proxy_profile") + warns, err := junSess.CommitConf(ctx, "create resource junos_services_proxy_profile") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -172,7 +172,7 @@ func resourceServicesProxyProfileUpdate(ctx context.Context, d *schema.ResourceD return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_services_proxy_profile") + warns, err := junSess.CommitConf(ctx, "update resource junos_services_proxy_profile") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -209,7 +209,7 @@ func resourceServicesProxyProfileDelete(ctx context.Context, d *schema.ResourceD return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_services_proxy_profile") + warns, err := junSess.CommitConf(ctx, "delete resource junos_services_proxy_profile") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_services_rpm_probe.go b/internal/providersdk/resource_services_rpm_probe.go index 34df6274..bbdd7320 100644 --- a/internal/providersdk/resource_services_rpm_probe.go +++ b/internal/providersdk/resource_services_rpm_probe.go @@ -360,7 +360,7 @@ func resourceServicesRpmProbeCreate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_services_rpm_probe") + warns, err := junSess.CommitConf(ctx, "create resource junos_services_rpm_probe") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -445,7 +445,7 @@ func resourceServicesRpmProbeUpdate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_services_rpm_probe") + warns, err := junSess.CommitConf(ctx, "update resource junos_services_rpm_probe") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -482,7 +482,7 @@ func resourceServicesRpmProbeDelete(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_services_rpm_probe") + warns, err := junSess.CommitConf(ctx, "delete resource junos_services_rpm_probe") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_services_security_intelligence_policy.go b/internal/providersdk/resource_services_security_intelligence_policy.go index 7562ceda..f81577f3 100644 --- a/internal/providersdk/resource_services_security_intelligence_policy.go +++ b/internal/providersdk/resource_services_security_intelligence_policy.go @@ -99,7 +99,7 @@ func resourceServicesSecurityIntellPolicyCreate(ctx context.Context, d *schema.R return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_services_security_intelligence_policy") + warns, err := junSess.CommitConf(ctx, "create resource junos_services_security_intelligence_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -184,7 +184,7 @@ func resourceServicesSecurityIntellPolicyUpdate(ctx context.Context, d *schema.R return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_services_security_intelligence_policy") + warns, err := junSess.CommitConf(ctx, "update resource junos_services_security_intelligence_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -221,7 +221,7 @@ func resourceServicesSecurityIntellPolicyDelete(ctx context.Context, d *schema.R return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_services_security_intelligence_policy") + warns, err := junSess.CommitConf(ctx, "delete resource junos_services_security_intelligence_policy") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_services_security_intelligence_profile.go b/internal/providersdk/resource_services_security_intelligence_profile.go index c6c7172e..6f106714 100644 --- a/internal/providersdk/resource_services_security_intelligence_profile.go +++ b/internal/providersdk/resource_services_security_intelligence_profile.go @@ -160,7 +160,7 @@ func resourceServicesSecurityIntellProfileCreate(ctx context.Context, d *schema. return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_services_security_intelligence_profile") + warns, err := junSess.CommitConf(ctx, "create resource junos_services_security_intelligence_profile") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -246,7 +246,7 @@ func resourceServicesSecurityIntellProfileUpdate(ctx context.Context, d *schema. return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_services_security_intelligence_profile") + warns, err := junSess.CommitConf(ctx, "update resource junos_services_security_intelligence_profile") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -283,7 +283,7 @@ func resourceServicesSecurityIntellProfileDelete(ctx context.Context, d *schema. return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_services_security_intelligence_profile") + warns, err := junSess.CommitConf(ctx, "delete resource junos_services_security_intelligence_profile") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_services_ssl_initiation_profile.go b/internal/providersdk/resource_services_ssl_initiation_profile.go index d86abe43..47bdcd48 100644 --- a/internal/providersdk/resource_services_ssl_initiation_profile.go +++ b/internal/providersdk/resource_services_ssl_initiation_profile.go @@ -143,7 +143,7 @@ func resourceServicesSSLInitiationProfileCreate(ctx context.Context, d *schema.R return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_services_ssl_initiation_profile") + warns, err := junSess.CommitConf(ctx, "create resource junos_services_ssl_initiation_profile") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -229,7 +229,7 @@ func resourceServicesSSLInitiationProfileUpdate(ctx context.Context, d *schema.R return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_services_ssl_initiation_profile") + warns, err := junSess.CommitConf(ctx, "update resource junos_services_ssl_initiation_profile") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -266,7 +266,7 @@ func resourceServicesSSLInitiationProfileDelete(ctx context.Context, d *schema.R return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_services_ssl_initiation_profile") + warns, err := junSess.CommitConf(ctx, "delete resource junos_services_ssl_initiation_profile") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_services_user_identification_ad_access_domain.go b/internal/providersdk/resource_services_user_identification_ad_access_domain.go index 5b65093a..4f279917 100644 --- a/internal/providersdk/resource_services_user_identification_ad_access_domain.go +++ b/internal/providersdk/resource_services_user_identification_ad_access_domain.go @@ -171,7 +171,7 @@ func resourceServicesUserIdentAdAccessDomainCreate(ctx context.Context, d *schem return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_services_user_identification_ad_access_domain") + warns, err := junSess.CommitConf(ctx, "create resource junos_services_user_identification_ad_access_domain") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -261,7 +261,7 @@ func resourceServicesUserIdentAdAccessDomainUpdate(ctx context.Context, d *schem return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_services_user_identification_ad_access_domain") + warns, err := junSess.CommitConf(ctx, "update resource junos_services_user_identification_ad_access_domain") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -298,7 +298,7 @@ func resourceServicesUserIdentAdAccessDomainDelete(ctx context.Context, d *schem return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_services_user_identification_ad_access_domain") + warns, err := junSess.CommitConf(ctx, "delete resource junos_services_user_identification_ad_access_domain") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_services_user_identification_device_identity_profile.go b/internal/providersdk/resource_services_user_identification_device_identity_profile.go index 0d2e1ed1..09edde8f 100644 --- a/internal/providersdk/resource_services_user_identification_device_identity_profile.go +++ b/internal/providersdk/resource_services_user_identification_device_identity_profile.go @@ -107,7 +107,7 @@ func resourceServicesUserIdentDeviceIdentityProfileCreate(ctx context.Context, d return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_services_user_identification_device_identity_profile") + warns, err := junSess.CommitConf(ctx, "create resource junos_services_user_identification_device_identity_profile") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -200,7 +200,7 @@ func resourceServicesUserIdentDeviceIdentityProfileUpdate(ctx context.Context, d return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_services_user_identification_device_identity_profile") + warns, err := junSess.CommitConf(ctx, "update resource junos_services_user_identification_device_identity_profile") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -238,7 +238,7 @@ func resourceServicesUserIdentDeviceIdentityProfileDelete(ctx context.Context, d return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_services_user_identification_device_identity_profile") + warns, err := junSess.CommitConf(ctx, "delete resource junos_services_user_identification_device_identity_profile") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_snmp.go b/internal/providersdk/resource_snmp.go index 93abafda..64463ea4 100644 --- a/internal/providersdk/resource_snmp.go +++ b/internal/providersdk/resource_snmp.go @@ -184,7 +184,7 @@ func resourceSnmpCreate(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_snmp") + warns, err := junSess.CommitConf(ctx, "create resource junos_snmp") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -253,7 +253,7 @@ func resourceSnmpUpdate(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_snmp") + warns, err := junSess.CommitConf(ctx, "update resource junos_snmp") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -290,7 +290,7 @@ func resourceSnmpDelete(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_snmp") + warns, err := junSess.CommitConf(ctx, "delete resource junos_snmp") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_snmp_clientlist.go b/internal/providersdk/resource_snmp_clientlist.go index f2e160ff..9783ddff 100644 --- a/internal/providersdk/resource_snmp_clientlist.go +++ b/internal/providersdk/resource_snmp_clientlist.go @@ -77,7 +77,7 @@ func resourceSnmpClientlistCreate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_snmp_clientlist") + warns, err := junSess.CommitConf(ctx, "create resource junos_snmp_clientlist") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -160,7 +160,7 @@ func resourceSnmpClientlistUpdate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_snmp_clientlist") + warns, err := junSess.CommitConf(ctx, "update resource junos_snmp_clientlist") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -196,7 +196,7 @@ func resourceSnmpClientlistDelete(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_snmp_clientlist") + warns, err := junSess.CommitConf(ctx, "delete resource junos_snmp_clientlist") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_snmp_community.go b/internal/providersdk/resource_snmp_community.go index 707d498c..23522cad 100644 --- a/internal/providersdk/resource_snmp_community.go +++ b/internal/providersdk/resource_snmp_community.go @@ -126,7 +126,7 @@ func resourceSnmpCommunityCreate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_snmp_community") + warns, err := junSess.CommitConf(ctx, "create resource junos_snmp_community") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -209,7 +209,7 @@ func resourceSnmpCommunityUpdate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_snmp_community") + warns, err := junSess.CommitConf(ctx, "update resource junos_snmp_community") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -245,7 +245,7 @@ func resourceSnmpCommunityDelete(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_snmp_community") + warns, err := junSess.CommitConf(ctx, "delete resource junos_snmp_community") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_snmp_v3_community.go b/internal/providersdk/resource_snmp_v3_community.go index 2687c1d9..b33d2d32 100644 --- a/internal/providersdk/resource_snmp_v3_community.go +++ b/internal/providersdk/resource_snmp_v3_community.go @@ -94,7 +94,7 @@ func resourceSnmpV3CommunityCreate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_snmp_v3_community") + warns, err := junSess.CommitConf(ctx, "create resource junos_snmp_v3_community") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -177,7 +177,7 @@ func resourceSnmpV3CommunityUpdate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_snmp_v3_community") + warns, err := junSess.CommitConf(ctx, "update resource junos_snmp_v3_community") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -213,7 +213,7 @@ func resourceSnmpV3CommunityDelete(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_snmp_v3_community") + warns, err := junSess.CommitConf(ctx, "delete resource junos_snmp_v3_community") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_snmp_v3_usm_user.go b/internal/providersdk/resource_snmp_v3_usm_user.go index 8309352a..08620b18 100644 --- a/internal/providersdk/resource_snmp_v3_usm_user.go +++ b/internal/providersdk/resource_snmp_v3_usm_user.go @@ -156,7 +156,7 @@ func resourceSnmpV3UsmUserCreate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_snmp_v3_usm_user") + warns, err := junSess.CommitConf(ctx, "create resource junos_snmp_v3_usm_user") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -272,7 +272,7 @@ func resourceSnmpV3UsmUserUpdate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_snmp_v3_usm_user") + warns, err := junSess.CommitConf(ctx, "update resource junos_snmp_v3_usm_user") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -318,7 +318,7 @@ func resourceSnmpV3UsmUserDelete(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_snmp_v3_usm_user") + warns, err := junSess.CommitConf(ctx, "delete resource junos_snmp_v3_usm_user") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_snmp_v3_vacm_accessgroup.go b/internal/providersdk/resource_snmp_v3_vacm_accessgroup.go index 60d17bc3..ce9d17b9 100644 --- a/internal/providersdk/resource_snmp_v3_vacm_accessgroup.go +++ b/internal/providersdk/resource_snmp_v3_vacm_accessgroup.go @@ -169,7 +169,7 @@ func resourceSnmpV3VacmAccessGroupCreate(ctx context.Context, d *schema.Resource return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_snmp_v3_vacm_accessgroup") + warns, err := junSess.CommitConf(ctx, "create resource junos_snmp_v3_vacm_accessgroup") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -252,7 +252,7 @@ func resourceSnmpV3VacmAccessGroupUpdate(ctx context.Context, d *schema.Resource return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_snmp_v3_vacm_accessgroup") + warns, err := junSess.CommitConf(ctx, "update resource junos_snmp_v3_vacm_accessgroup") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -288,7 +288,7 @@ func resourceSnmpV3VacmAccessGroupDelete(ctx context.Context, d *schema.Resource return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_snmp_v3_vacm_accessgroup") + warns, err := junSess.CommitConf(ctx, "delete resource junos_snmp_v3_vacm_accessgroup") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_snmp_v3_vacm_securitytogroup.go b/internal/providersdk/resource_snmp_v3_vacm_securitytogroup.go index 3afffb07..ab9bdc31 100644 --- a/internal/providersdk/resource_snmp_v3_vacm_securitytogroup.go +++ b/internal/providersdk/resource_snmp_v3_vacm_securitytogroup.go @@ -93,7 +93,7 @@ func resourceSnmpV3VacmSecurityToGroupCreate(ctx context.Context, d *schema.Reso return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_snmp_v3_vacm_securitytogroup") + warns, err := junSess.CommitConf(ctx, "create resource junos_snmp_v3_vacm_securitytogroup") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -187,7 +187,7 @@ func resourceSnmpV3VacmSecurityToGroupUpdate(ctx context.Context, d *schema.Reso return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_snmp_v3_vacm_securitytogroup") + warns, err := junSess.CommitConf(ctx, "update resource junos_snmp_v3_vacm_securitytogroup") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -224,7 +224,7 @@ func resourceSnmpV3VacmSecurityToGroupDelete(ctx context.Context, d *schema.Reso return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_snmp_v3_vacm_securitytogroup") + warns, err := junSess.CommitConf(ctx, "delete resource junos_snmp_v3_vacm_securitytogroup") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_snmp_view.go b/internal/providersdk/resource_snmp_view.go index 62fd2382..00ee7dfa 100644 --- a/internal/providersdk/resource_snmp_view.go +++ b/internal/providersdk/resource_snmp_view.go @@ -86,7 +86,7 @@ func resourceSnmpViewCreate(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_snmp_view") + warns, err := junSess.CommitConf(ctx, "create resource junos_snmp_view") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -169,7 +169,7 @@ func resourceSnmpViewUpdate(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_snmp_view") + warns, err := junSess.CommitConf(ctx, "update resource junos_snmp_view") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -205,7 +205,7 @@ func resourceSnmpViewDelete(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_snmp_view") + warns, err := junSess.CommitConf(ctx, "delete resource junos_snmp_view") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_system_login_class.go b/internal/providersdk/resource_system_login_class.go index 324c150e..7e2dc63f 100644 --- a/internal/providersdk/resource_system_login_class.go +++ b/internal/providersdk/resource_system_login_class.go @@ -224,7 +224,7 @@ func resourceSystemLoginClassCreate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_system_login_class") + warns, err := junSess.CommitConf(ctx, "create resource junos_system_login_class") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -307,7 +307,7 @@ func resourceSystemLoginClassUpdate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_system_login_class") + warns, err := junSess.CommitConf(ctx, "update resource junos_system_login_class") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -343,7 +343,7 @@ func resourceSystemLoginClassDelete(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_system_login_class") + warns, err := junSess.CommitConf(ctx, "delete resource junos_system_login_class") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_system_login_user.go b/internal/providersdk/resource_system_login_user.go index bdb61244..b9bdc6d5 100644 --- a/internal/providersdk/resource_system_login_user.go +++ b/internal/providersdk/resource_system_login_user.go @@ -133,7 +133,7 @@ func resourceSystemLoginUserCreate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_system_login_user") + warns, err := junSess.CommitConf(ctx, "create resource junos_system_login_user") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -217,7 +217,7 @@ func resourceSystemLoginUserUpdate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_system_login_user") + warns, err := junSess.CommitConf(ctx, "update resource junos_system_login_user") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -254,7 +254,7 @@ func resourceSystemLoginUserDelete(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_system_login_user") + warns, err := junSess.CommitConf(ctx, "delete resource junos_system_login_user") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_system_ntp_server.go b/internal/providersdk/resource_system_ntp_server.go index e15fcc03..10ee38f9 100644 --- a/internal/providersdk/resource_system_ntp_server.go +++ b/internal/providersdk/resource_system_ntp_server.go @@ -99,7 +99,7 @@ func resourceSystemNtpServerCreate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_system_ntp_server") + warns, err := junSess.CommitConf(ctx, "create resource junos_system_ntp_server") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -182,7 +182,7 @@ func resourceSystemNtpServerUpdate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_system_ntp_server") + warns, err := junSess.CommitConf(ctx, "update resource junos_system_ntp_server") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -219,7 +219,7 @@ func resourceSystemNtpServerDelete(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_system_ntp_server") + warns, err := junSess.CommitConf(ctx, "delete resource junos_system_ntp_server") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_system_radius_server.go b/internal/providersdk/resource_system_radius_server.go index b5d68693..79cb6106 100644 --- a/internal/providersdk/resource_system_radius_server.go +++ b/internal/providersdk/resource_system_radius_server.go @@ -158,7 +158,7 @@ func resourceSystemRadiusServerCreate(ctx context.Context, d *schema.ResourceDat return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_system_radius_server") + warns, err := junSess.CommitConf(ctx, "create resource junos_system_radius_server") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -241,7 +241,7 @@ func resourceSystemRadiusServerUpdate(ctx context.Context, d *schema.ResourceDat return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_system_radius_server") + warns, err := junSess.CommitConf(ctx, "update resource junos_system_radius_server") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -277,7 +277,7 @@ func resourceSystemRadiusServerDelete(ctx context.Context, d *schema.ResourceDat return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_system_radius_server") + warns, err := junSess.CommitConf(ctx, "delete resource junos_system_radius_server") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_system_root_authentication.go b/internal/providersdk/resource_system_root_authentication.go index 0714f184..57382b7e 100644 --- a/internal/providersdk/resource_system_root_authentication.go +++ b/internal/providersdk/resource_system_root_authentication.go @@ -100,7 +100,7 @@ func resourceSystemRootAuthenticationCreate(ctx context.Context, d *schema.Resou return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_system_root_authentication") + warns, err := junSess.CommitConf(ctx, "create resource junos_system_root_authentication") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -171,7 +171,7 @@ func resourceSystemRootAuthenticationUpdate(ctx context.Context, d *schema.Resou return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_system_root_authentication") + warns, err := junSess.CommitConf(ctx, "update resource junos_system_root_authentication") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_system_services_dhcp_localserver_group.go b/internal/providersdk/resource_system_services_dhcp_localserver_group.go index 0791b539..034e1210 100644 --- a/internal/providersdk/resource_system_services_dhcp_localserver_group.go +++ b/internal/providersdk/resource_system_services_dhcp_localserver_group.go @@ -813,7 +813,7 @@ func resourceSystemServicesDhcpLocalServerGroupCreate(ctx context.Context, d *sc return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_system_services_dhcp_localserver_group") + warns, err := junSess.CommitConf(ctx, "create resource junos_system_services_dhcp_localserver_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -930,7 +930,7 @@ func resourceSystemServicesDhcpLocalServerGroupUpdate(ctx context.Context, d *sc return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_system_services_dhcp_localserver_group") + warns, err := junSess.CommitConf(ctx, "update resource junos_system_services_dhcp_localserver_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -977,7 +977,7 @@ func resourceSystemServicesDhcpLocalServerGroupDelete(ctx context.Context, d *sc return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_system_services_dhcp_localserver_group") + warns, err := junSess.CommitConf(ctx, "delete resource junos_system_services_dhcp_localserver_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_system_syslog_file.go b/internal/providersdk/resource_system_syslog_file.go index e79e55b2..c1fb47a7 100644 --- a/internal/providersdk/resource_system_syslog_file.go +++ b/internal/providersdk/resource_system_syslog_file.go @@ -273,7 +273,7 @@ func resourceSystemSyslogFileCreate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_system_syslog_file") + warns, err := junSess.CommitConf(ctx, "create resource junos_system_syslog_file") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -356,7 +356,7 @@ func resourceSystemSyslogFileUpdate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_system_syslog_file") + warns, err := junSess.CommitConf(ctx, "update resource junos_system_syslog_file") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -392,7 +392,7 @@ func resourceSystemSyslogFileDelete(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_system_syslog_file") + warns, err := junSess.CommitConf(ctx, "delete resource junos_system_syslog_file") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_system_syslog_host.go b/internal/providersdk/resource_system_syslog_host.go index 6e61069c..2459d3de 100644 --- a/internal/providersdk/resource_system_syslog_host.go +++ b/internal/providersdk/resource_system_syslog_host.go @@ -229,7 +229,7 @@ func resourceSystemSyslogHostCreate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_system_syslog_host") + warns, err := junSess.CommitConf(ctx, "create resource junos_system_syslog_host") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -312,7 +312,7 @@ func resourceSystemSyslogHostUpdate(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_system_syslog_host") + warns, err := junSess.CommitConf(ctx, "update resource junos_system_syslog_host") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -348,7 +348,7 @@ func resourceSystemSyslogHostDelete(ctx context.Context, d *schema.ResourceData, return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_system_syslog_host") + warns, err := junSess.CommitConf(ctx, "delete resource junos_system_syslog_host") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_vlan.go b/internal/providersdk/resource_vlan.go index 04d03e87..f521f2c0 100644 --- a/internal/providersdk/resource_vlan.go +++ b/internal/providersdk/resource_vlan.go @@ -192,7 +192,7 @@ func resourceVlanCreate(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_vlan") + warns, err := junSess.CommitConf(ctx, "create resource junos_vlan") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -286,7 +286,7 @@ func resourceVlanUpdate(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_vlan") + warns, err := junSess.CommitConf(ctx, "update resource junos_vlan") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -322,7 +322,7 @@ func resourceVlanDelete(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_vlan") + warns, err := junSess.CommitConf(ctx, "delete resource junos_vlan") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_vstp.go b/internal/providersdk/resource_vstp.go index f2efaa8a..3d085ba2 100644 --- a/internal/providersdk/resource_vstp.go +++ b/internal/providersdk/resource_vstp.go @@ -125,7 +125,7 @@ func resourceVstpCreate(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_vstp") + warns, err := junSess.CommitConf(ctx, "create resource junos_vstp") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -208,7 +208,7 @@ func resourceVstpUpdate(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_vstp") + warns, err := junSess.CommitConf(ctx, "update resource junos_vstp") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -244,7 +244,7 @@ func resourceVstpDelete(ctx context.Context, d *schema.ResourceData, m interface return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_vstp") + warns, err := junSess.CommitConf(ctx, "delete resource junos_vstp") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_vstp_interface.go b/internal/providersdk/resource_vstp_interface.go index 4c03789e..289c70bd 100644 --- a/internal/providersdk/resource_vstp_interface.go +++ b/internal/providersdk/resource_vstp_interface.go @@ -308,7 +308,7 @@ func resourceVstpInterfaceCreate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_vstp_interface") + warns, err := junSess.CommitConf(ctx, "create resource junos_vstp_interface") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -439,7 +439,7 @@ func resourceVstpInterfaceUpdate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_vstp_interface") + warns, err := junSess.CommitConf(ctx, "update resource junos_vstp_interface") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -487,7 +487,7 @@ func resourceVstpInterfaceDelete(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_vstp_interface") + warns, err := junSess.CommitConf(ctx, "delete resource junos_vstp_interface") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_vstp_vlan.go b/internal/providersdk/resource_vstp_vlan.go index 9835668f..9cbcd625 100644 --- a/internal/providersdk/resource_vstp_vlan.go +++ b/internal/providersdk/resource_vstp_vlan.go @@ -142,7 +142,7 @@ func resourceVstpVlanCreate(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_vstp_vlan") + warns, err := junSess.CommitConf(ctx, "create resource junos_vstp_vlan") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -236,7 +236,7 @@ func resourceVstpVlanUpdate(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_vstp_vlan") + warns, err := junSess.CommitConf(ctx, "update resource junos_vstp_vlan") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -277,7 +277,7 @@ func resourceVstpVlanDelete(ctx context.Context, d *schema.ResourceData, m inter return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_vstp_vlan") + warns, err := junSess.CommitConf(ctx, "delete resource junos_vstp_vlan") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) diff --git a/internal/providersdk/resource_vstp_vlan_group.go b/internal/providersdk/resource_vstp_vlan_group.go index 9e0ab2ef..8d65fd0e 100644 --- a/internal/providersdk/resource_vstp_vlan_group.go +++ b/internal/providersdk/resource_vstp_vlan_group.go @@ -149,7 +149,7 @@ func resourceVstpVlanGroupCreate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("create resource junos_vstp_vlan_group") + warns, err := junSess.CommitConf(ctx, "create resource junos_vstp_vlan_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -252,7 +252,7 @@ func resourceVstpVlanGroupUpdate(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("update resource junos_vstp_vlan_group") + warns, err := junSess.CommitConf(ctx, "update resource junos_vstp_vlan_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) @@ -298,7 +298,7 @@ func resourceVstpVlanGroupDelete(ctx context.Context, d *schema.ResourceData, m return append(diagWarns, diag.FromErr(err)...) } - warns, err := junSess.CommitConf("delete resource junos_vstp_vlan_group") + warns, err := junSess.CommitConf(ctx, "delete resource junos_vstp_vlan_group") appendDiagWarns(&diagWarns, warns) if err != nil { appendDiagWarns(&diagWarns, junSess.ConfigClear()) From 3886492dba2bcfeb2dcd50ce8acab91d23bf1607 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Dec 2023 00:25:45 +0000 Subject: [PATCH 31/43] workflows: bump github/codeql-action from 2 to 3 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/v2...v3) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/go_analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go_analysis.yml b/.github/workflows/go_analysis.yml index 4a181a43..741c1f97 100644 --- a/.github/workflows/go_analysis.yml +++ b/.github/workflows/go_analysis.yml @@ -30,10 +30,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: config-file: ./.github/codeql-config.yml - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v3 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 From 75d0851a796f9134feb2bca6403719a8fdcc3149 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Thu, 14 Dec 2023 09:39:43 +0100 Subject: [PATCH 32/43] deps: bump github.com/hashicorp/terraform-plugin-sdk/v2 to v2.30.0 with the go replace to minor fix to accept empty list of primitives on apply --- go.mod | 14 +++++++------- go.sum | 31 ++++++++++++++++--------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index 71b47cd6..f2488425 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 github.com/hashicorp/terraform-plugin-go v0.19.1 github.com/hashicorp/terraform-plugin-mux v0.12.0 - github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0 + github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0 github.com/hashicorp/terraform-plugin-testing v1.5.1 github.com/jeremmfr/go-netconf v0.4.14 github.com/jeremmfr/go-utils v0.11.0 @@ -18,7 +18,7 @@ require ( ) require ( - github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect + github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/agext/levenshtein v1.2.2 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/cloudflare/circl v1.3.3 // indirect @@ -32,8 +32,8 @@ require ( github.com/hashicorp/go-plugin v1.5.2 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/go-version v1.6.0 // indirect - github.com/hashicorp/hc-install v0.6.0 // indirect - github.com/hashicorp/hcl/v2 v2.18.0 // indirect + github.com/hashicorp/hc-install v0.6.1 // indirect + github.com/hashicorp/hcl/v2 v2.19.1 // indirect github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-exec v0.19.0 // indirect github.com/hashicorp/terraform-json v0.17.1 // indirect @@ -52,9 +52,9 @@ require ( github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - github.com/zclconf/go-cty v1.14.0 // indirect + github.com/zclconf/go-cty v1.14.1 // indirect golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect - golang.org/x/mod v0.12.0 // indirect + golang.org/x/mod v0.13.0 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect @@ -64,4 +64,4 @@ require ( google.golang.org/protobuf v1.31.0 // indirect ) -replace github.com/hashicorp/terraform-plugin-sdk/v2 => github.com/jeremmfr/terraform-plugin-sdk/v2 v2.29.1-0.20230913082525-7f46c82c0820 +replace github.com/hashicorp/terraform-plugin-sdk/v2 => github.com/jeremmfr/terraform-plugin-sdk/v2 v2.30.1-0.20231214083343-f81fd9584261 diff --git a/go.sum b/go.sum index 3b7c1a4e..5dd6b259 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= -github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs= -github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= @@ -12,6 +12,7 @@ github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZ github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -19,8 +20,8 @@ github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= -github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= -github.com/go-git/go-git/v5 v5.8.1 h1:Zo79E4p7TRk0xoRgMq0RShiTHGKcKI4+DI6BfJc/Q+A= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-git/v5 v5.9.0 h1:cD9SFA7sHVRdJ7AYck1ZaAa/yeuBvGPxwXDL8cxrObY= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -53,10 +54,10 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hc-install v0.6.0 h1:fDHnU7JNFNSQebVKYhHZ0va1bC6SrPQ8fpebsvNr2w4= -github.com/hashicorp/hc-install v0.6.0/go.mod h1:10I912u3nntx9Umo1VAeYPUUuehk0aRQJYpMwbX5wQA= -github.com/hashicorp/hcl/v2 v2.18.0 h1:wYnG7Lt31t2zYkcquwgKo6MWXzRUDIeIVU5naZwHLl8= -github.com/hashicorp/hcl/v2 v2.18.0/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= +github.com/hashicorp/hc-install v0.6.1 h1:IGxShH7AVhPaSuSJpKtVi/EFORNjO+OYVJJrAtGG2mY= +github.com/hashicorp/hc-install v0.6.1/go.mod h1:0fW3jpg+wraYSnFDJ6Rlie3RvLf1bIqVIkzoon4KoVE= +github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI= +github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-exec v0.19.0 h1:FpqZ6n50Tk95mItTSS9BjeOVUb4eg81SpgVtZNNtFSM= @@ -88,8 +89,8 @@ github.com/jeremmfr/go-utils v0.11.0 h1:+0Y1pXp2UJKh6Rw0QxPxe0zLv70GzyThAIEMkqKV github.com/jeremmfr/go-utils v0.11.0/go.mod h1:Lkn95iSzCRviFhn2/0XmqzWGmxI+kkoqKAZqip7VUmM= github.com/jeremmfr/junosdecode v1.1.1 h1:wOFfJIwLXP9s0eQzzAhuX7a7N1mc+AWgDLYAmR7VoWg= github.com/jeremmfr/junosdecode v1.1.1/go.mod h1:nTY0XbZC2ePbZdV0wuUboSMtGrJxtpwWVYfHjrS2Oqw= -github.com/jeremmfr/terraform-plugin-sdk/v2 v2.29.1-0.20230913082525-7f46c82c0820 h1:NfBGagrPGV0InEMFvcqwIuYgeBzU//NwvEPSiTGSxZM= -github.com/jeremmfr/terraform-plugin-sdk/v2 v2.29.1-0.20230913082525-7f46c82c0820/go.mod h1:qH/34G25Ugdj5FcM95cSoXzUgIbgfhVLXCcEcYaMwq8= +github.com/jeremmfr/terraform-plugin-sdk/v2 v2.30.1-0.20231214083343-f81fd9584261 h1:fhu0oK9l1HGyr9tnEMyHXJjlFzlppl1K7bKqR2IJ9ag= +github.com/jeremmfr/terraform-plugin-sdk/v2 v2.30.1-0.20231214083343-f81fd9584261/go.mod h1:ydFcxbdj6klCqYEPkPvdvFKiNGKZLUs+896ODUXCyao= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -133,8 +134,8 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/zclconf/go-cty v1.14.0 h1:/Xrd39K7DXbHzlisFP9c4pHao4yyf+/Ug9LEz+Y/yhc= -github.com/zclconf/go-cty v1.14.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty v1.14.1 h1:t9fyA35fwjjUMcmL5hLER+e/rEPqrbCK1/OSE4SI9KA= +github.com/zclconf/go-cty v1.14.1/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= @@ -146,8 +147,8 @@ golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 h1:EDuYyU/MkFXllv9QF9819VlI9 golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= +golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -203,8 +204,8 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= From f2b157d3c341248acb4aad4793e3404b8ca7d909 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Dec 2023 09:42:37 +0000 Subject: [PATCH 33/43] deps: bump github.com/hashicorp/terraform-plugin-testing Bumps [github.com/hashicorp/terraform-plugin-testing](https://github.com/hashicorp/terraform-plugin-testing) from 1.5.1 to 1.6.0. - [Release notes](https://github.com/hashicorp/terraform-plugin-testing/releases) - [Changelog](https://github.com/hashicorp/terraform-plugin-testing/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/terraform-plugin-testing/compare/v1.5.1...v1.6.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/terraform-plugin-testing dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index f2488425..e09c78fc 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/hashicorp/terraform-plugin-go v0.19.1 github.com/hashicorp/terraform-plugin-mux v0.12.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0 - github.com/hashicorp/terraform-plugin-testing v1.5.1 + github.com/hashicorp/terraform-plugin-testing v1.6.0 github.com/jeremmfr/go-netconf v0.4.14 github.com/jeremmfr/go-utils v0.11.0 github.com/jeremmfr/junosdecode v1.1.1 @@ -36,7 +36,7 @@ require ( github.com/hashicorp/hcl/v2 v2.19.1 // indirect github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-exec v0.19.0 // indirect - github.com/hashicorp/terraform-json v0.17.1 // indirect + github.com/hashicorp/terraform-json v0.18.0 // indirect github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect github.com/hashicorp/terraform-registry-address v0.2.3 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect diff --git a/go.sum b/go.sum index 5dd6b259..6f4c5eb0 100644 --- a/go.sum +++ b/go.sum @@ -62,8 +62,8 @@ github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-exec v0.19.0 h1:FpqZ6n50Tk95mItTSS9BjeOVUb4eg81SpgVtZNNtFSM= github.com/hashicorp/terraform-exec v0.19.0/go.mod h1:tbxUpe3JKruE9Cuf65mycSIT8KiNPZ0FkuTE3H4urQg= -github.com/hashicorp/terraform-json v0.17.1 h1:eMfvh/uWggKmY7Pmb3T85u86E2EQg6EQHgyRwf3RkyA= -github.com/hashicorp/terraform-json v0.17.1/go.mod h1:Huy6zt6euxaY9knPAFKjUITn8QxUFIe9VuSzb4zn/0o= +github.com/hashicorp/terraform-json v0.18.0 h1:pCjgJEqqDESv4y0Tzdqfxr/edOIGkjs8keY42xfNBwU= +github.com/hashicorp/terraform-json v0.18.0/go.mod h1:qdeBs11ovMzo5puhrRibdD6d2Dq6TyE/28JiU4tIQxk= github.com/hashicorp/terraform-plugin-framework v1.4.2 h1:P7a7VP1GZbjc4rv921Xy5OckzhoiO3ig6SGxwelD2sI= github.com/hashicorp/terraform-plugin-framework v1.4.2/go.mod h1:GWl3InPFZi2wVQmdVnINPKys09s9mLmTZr95/ngLnbY= github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc= @@ -74,8 +74,8 @@ github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9T github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= github.com/hashicorp/terraform-plugin-mux v0.12.0 h1:TJlmeslQ11WlQtIFAfth0vXx+gSNgvMEng2Rn9z3WZY= github.com/hashicorp/terraform-plugin-mux v0.12.0/go.mod h1:8MR0AgmV+Q03DIjyrAKxXyYlq2EUnYBQP8gxAAA0zeM= -github.com/hashicorp/terraform-plugin-testing v1.5.1 h1:T4aQh9JAhmWo4+t1A7x+rnxAJHCDIYW9kXyo4sVO92c= -github.com/hashicorp/terraform-plugin-testing v1.5.1/go.mod h1:dg8clO6K59rZ8w9EshBmDp1CxTIPu3yA4iaDpX1h5u0= +github.com/hashicorp/terraform-plugin-testing v1.6.0 h1:Wsnfh+7XSVRfwcr2jZYHsnLOnZl7UeaOBvsx6dl/608= +github.com/hashicorp/terraform-plugin-testing v1.6.0/go.mod h1:cJGG0/8j9XhHaJZRC+0sXFI4uzqQZ9Az4vh6C4GJpFE= github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM= github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= From 95c3c5f6b1567f7afea7a6ed5b061e8341bf85b4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Dec 2023 00:58:45 +0000 Subject: [PATCH 34/43] deps: bump github.com/hashicorp/terraform-plugin-go Bumps [github.com/hashicorp/terraform-plugin-go](https://github.com/hashicorp/terraform-plugin-go) from 0.19.1 to 0.20.0. - [Release notes](https://github.com/hashicorp/terraform-plugin-go/releases) - [Changelog](https://github.com/hashicorp/terraform-plugin-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/terraform-plugin-go/compare/v0.19.1...v0.20.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/terraform-plugin-go dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 12 ++++++------ go.sum | 28 ++++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index e09c78fc..f4e252fb 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/terraform-plugin-framework v1.4.2 github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 - github.com/hashicorp/terraform-plugin-go v0.19.1 + github.com/hashicorp/terraform-plugin-go v0.20.0 github.com/hashicorp/terraform-plugin-mux v0.12.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0 github.com/hashicorp/terraform-plugin-testing v1.6.0 @@ -29,7 +29,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-hclog v1.5.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/hashicorp/go-plugin v1.5.2 // indirect + github.com/hashicorp/go-plugin v1.6.0 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/go-version v1.6.0 // indirect github.com/hashicorp/hc-install v0.6.1 // indirect @@ -40,7 +40,7 @@ require ( github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect github.com/hashicorp/terraform-registry-address v0.2.3 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect - github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect + github.com/hashicorp/yamux v0.1.1 // indirect github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.14 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect @@ -58,9 +58,9 @@ require ( golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect - google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect - google.golang.org/grpc v1.59.0 // indirect + google.golang.org/appengine v1.6.8 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect + google.golang.org/grpc v1.60.0 // indirect google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/go.sum b/go.sum index 6f4c5eb0..d67171b2 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,8 @@ github.com/go-git/go-git/v5 v5.9.0 h1:cD9SFA7sHVRdJ7AYck1ZaAa/yeuBvGPxwXDL8cxrOb github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -47,8 +47,8 @@ github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+ github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= 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.5.2 h1:aWv8eimFqWlsEiMrYZdPYl+FdHaBJSN4AWwGWfT1G2Y= -github.com/hashicorp/go-plugin v1.5.2/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= +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-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= @@ -68,8 +68,8 @@ github.com/hashicorp/terraform-plugin-framework v1.4.2 h1:P7a7VP1GZbjc4rv921Xy5O github.com/hashicorp/terraform-plugin-framework v1.4.2/go.mod h1:GWl3InPFZi2wVQmdVnINPKys09s9mLmTZr95/ngLnbY= github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc= github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg= -github.com/hashicorp/terraform-plugin-go v0.19.1 h1:lf/jTGTeELcz5IIbn/94mJdmnTjRYm6S6ct/JqCSr50= -github.com/hashicorp/terraform-plugin-go v0.19.1/go.mod h1:5NMIS+DXkfacX6o5HCpswda5yjkSYfKzn1Nfl9l+qRs= +github.com/hashicorp/terraform-plugin-go v0.20.0 h1:oqvoUlL+2EUbKNsJbIt3zqqZ7wi6lzn4ufkn/UA51xQ= +github.com/hashicorp/terraform-plugin-go v0.20.0/go.mod h1:Rr8LBdMlY53a3Z/HpP+ZU3/xCDqtKNCkeI9qOyT10QE= 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.12.0 h1:TJlmeslQ11WlQtIFAfth0vXx+gSNgvMEng2Rn9z3WZY= @@ -80,8 +80,8 @@ github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTV github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM= github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= -github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= -github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= +github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jeremmfr/go-netconf v0.4.14 h1:kENaS5/8WootwGEIPUPke31sqsMbc7MpSJBbzY81t/A= github.com/jeremmfr/go-netconf v0.4.14/go.mod h1:Le5V8n/aoOifpdJK4BmxWW0CRhJWIaUkwpcQT75Y2NE= @@ -150,7 +150,6 @@ golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 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= @@ -194,6 +193,7 @@ 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.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= @@ -209,12 +209,12 @@ golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= -google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= -google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= -google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= +google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= +google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 h1:6GQBEOdGkX6MMTLT9V+TjtIRZCw9VPD5Z+yHY9wMgS0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97/go.mod h1:v7nGkzlmW8P3n/bKmWBn2WpBjpOEx8Q6gMueudAmKfY= +google.golang.org/grpc v1.60.0 h1:6FQAR0kM31P6MRdeluor2w2gPaS4SVNrD/DNTxrQ15k= +google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= 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.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= From 949e3f901019089ab71dfec74f4688b1f713ef12 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Dec 2023 08:43:45 +0000 Subject: [PATCH 35/43] deps: bump github.com/hashicorp/terraform-plugin-mux Bumps [github.com/hashicorp/terraform-plugin-mux](https://github.com/hashicorp/terraform-plugin-mux) from 0.12.0 to 0.13.0. - [Release notes](https://github.com/hashicorp/terraform-plugin-mux/releases) - [Changelog](https://github.com/hashicorp/terraform-plugin-mux/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/terraform-plugin-mux/compare/v0.12.0...v0.13.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/terraform-plugin-mux dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f4e252fb..41eadd48 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/hashicorp/terraform-plugin-framework v1.4.2 github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 github.com/hashicorp/terraform-plugin-go v0.20.0 - github.com/hashicorp/terraform-plugin-mux v0.12.0 + github.com/hashicorp/terraform-plugin-mux v0.13.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0 github.com/hashicorp/terraform-plugin-testing v1.6.0 github.com/jeremmfr/go-netconf v0.4.14 diff --git a/go.sum b/go.sum index d67171b2..5da248da 100644 --- a/go.sum +++ b/go.sum @@ -72,8 +72,8 @@ github.com/hashicorp/terraform-plugin-go v0.20.0 h1:oqvoUlL+2EUbKNsJbIt3zqqZ7wi6 github.com/hashicorp/terraform-plugin-go v0.20.0/go.mod h1:Rr8LBdMlY53a3Z/HpP+ZU3/xCDqtKNCkeI9qOyT10QE= 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.12.0 h1:TJlmeslQ11WlQtIFAfth0vXx+gSNgvMEng2Rn9z3WZY= -github.com/hashicorp/terraform-plugin-mux v0.12.0/go.mod h1:8MR0AgmV+Q03DIjyrAKxXyYlq2EUnYBQP8gxAAA0zeM= +github.com/hashicorp/terraform-plugin-mux v0.13.0 h1:79U401/3nd8CWwDGtTHc8F3miSCAS9XGtVarxSTDgwA= +github.com/hashicorp/terraform-plugin-mux v0.13.0/go.mod h1:Ndv0FtwDG2ogzH59y64f2NYimFJ6I0smRgFUKfm6dyQ= github.com/hashicorp/terraform-plugin-testing v1.6.0 h1:Wsnfh+7XSVRfwcr2jZYHsnLOnZl7UeaOBvsx6dl/608= github.com/hashicorp/terraform-plugin-testing v1.6.0/go.mod h1:cJGG0/8j9XhHaJZRC+0sXFI4uzqQZ9Az4vh6C4GJpFE= github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= From 5e70f6c8107bc33967ebebaef23a6ad21a189c57 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Fri, 15 Dec 2023 13:44:17 +0100 Subject: [PATCH 36/43] deps: bump github.com/hashicorp/terraform-plugin-sdk/v2 to v2.31.0 with the go replace to minor fix to accept empty list of primitives on apply --- go.mod | 10 +++++----- go.sum | 21 ++++++++++----------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 41eadd48..244c5f41 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 github.com/hashicorp/terraform-plugin-go v0.20.0 github.com/hashicorp/terraform-plugin-mux v0.13.0 - github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0 + github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0 github.com/hashicorp/terraform-plugin-testing v1.6.0 github.com/jeremmfr/go-netconf v0.4.14 github.com/jeremmfr/go-utils v0.11.0 @@ -32,7 +32,7 @@ require ( github.com/hashicorp/go-plugin v1.6.0 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/go-version v1.6.0 // indirect - github.com/hashicorp/hc-install v0.6.1 // indirect + github.com/hashicorp/hc-install v0.6.2 // indirect github.com/hashicorp/hcl/v2 v2.19.1 // indirect github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-exec v0.19.0 // indirect @@ -54,8 +54,8 @@ require ( github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/zclconf/go-cty v1.14.1 // indirect golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect - golang.org/x/mod v0.13.0 // indirect - golang.org/x/net v0.17.0 // indirect + golang.org/x/mod v0.14.0 // indirect + golang.org/x/net v0.18.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.8 // indirect @@ -64,4 +64,4 @@ require ( google.golang.org/protobuf v1.31.0 // indirect ) -replace github.com/hashicorp/terraform-plugin-sdk/v2 => github.com/jeremmfr/terraform-plugin-sdk/v2 v2.30.1-0.20231214083343-f81fd9584261 +replace github.com/hashicorp/terraform-plugin-sdk/v2 => github.com/jeremmfr/terraform-plugin-sdk/v2 v2.31.1-0.20231215123912-f688d221c088 diff --git a/go.sum b/go.sum index 5da248da..8f7e9598 100644 --- a/go.sum +++ b/go.sum @@ -2,7 +2,6 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg= github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= -github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= @@ -21,7 +20,7 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= -github.com/go-git/go-git/v5 v5.9.0 h1:cD9SFA7sHVRdJ7AYck1ZaAa/yeuBvGPxwXDL8cxrObY= +github.com/go-git/go-git/v5 v5.10.1 h1:tu8/D8i+TWxgKpzQ3Vc43e+kkhXqtsZCKI/egajKnxk= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -54,8 +53,8 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hc-install v0.6.1 h1:IGxShH7AVhPaSuSJpKtVi/EFORNjO+OYVJJrAtGG2mY= -github.com/hashicorp/hc-install v0.6.1/go.mod h1:0fW3jpg+wraYSnFDJ6Rlie3RvLf1bIqVIkzoon4KoVE= +github.com/hashicorp/hc-install v0.6.2 h1:V1k+Vraqz4olgZ9UzKiAcbman9i9scg9GgSt/U3mw/M= +github.com/hashicorp/hc-install v0.6.2/go.mod h1:2JBpd+NCFKiHiu/yYCGaPyPHhZLxXTpz8oreHa/a3Ps= github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI= github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= @@ -89,8 +88,8 @@ github.com/jeremmfr/go-utils v0.11.0 h1:+0Y1pXp2UJKh6Rw0QxPxe0zLv70GzyThAIEMkqKV github.com/jeremmfr/go-utils v0.11.0/go.mod h1:Lkn95iSzCRviFhn2/0XmqzWGmxI+kkoqKAZqip7VUmM= github.com/jeremmfr/junosdecode v1.1.1 h1:wOFfJIwLXP9s0eQzzAhuX7a7N1mc+AWgDLYAmR7VoWg= github.com/jeremmfr/junosdecode v1.1.1/go.mod h1:nTY0XbZC2ePbZdV0wuUboSMtGrJxtpwWVYfHjrS2Oqw= -github.com/jeremmfr/terraform-plugin-sdk/v2 v2.30.1-0.20231214083343-f81fd9584261 h1:fhu0oK9l1HGyr9tnEMyHXJjlFzlppl1K7bKqR2IJ9ag= -github.com/jeremmfr/terraform-plugin-sdk/v2 v2.30.1-0.20231214083343-f81fd9584261/go.mod h1:ydFcxbdj6klCqYEPkPvdvFKiNGKZLUs+896ODUXCyao= +github.com/jeremmfr/terraform-plugin-sdk/v2 v2.31.1-0.20231215123912-f688d221c088 h1:6eP0jM/2Rh5wtu/jLhnXZBGbrk1tg3qhuabw2rnaoGQ= +github.com/jeremmfr/terraform-plugin-sdk/v2 v2.31.1-0.20231215123912-f688d221c088/go.mod h1:i2C41tszDjiWfziPQDL5R/f3Zp0gahXe5No/MIO9rCE= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -121,7 +120,7 @@ github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= -github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJCpM= +github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= @@ -147,8 +146,8 @@ golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 h1:EDuYyU/MkFXllv9QF9819VlI9 golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= -golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -157,8 +156,8 @@ golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/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-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= From 3756f74432143275ce012a59314074540936f8dd Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Fri, 15 Dec 2023 14:46:10 +0100 Subject: [PATCH 37/43] r/system: add web_management_session_* arguments in services block Fix #594 --- .changes/issue-594.md | 4 + docs/resources/system.md | 4 + internal/providerfwk/resource_system.go | 100 ++++++++++++++++-- .../TestAccResourceSystem_basic/1/main.tf | 2 + 4 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 .changes/issue-594.md diff --git a/.changes/issue-594.md b/.changes/issue-594.md new file mode 100644 index 00000000..5321df80 --- /dev/null +++ b/.changes/issue-594.md @@ -0,0 +1,4 @@ + +ENHANCEMENTS: + +* **resource/junos_system**: add `web_management_session_idle_timeout` and `web_management_session_limit` arguments in `services` block (Fix [#594](https://github.com/jeremmfr/terraform-provider-junos/issues/594)) diff --git a/docs/resources/system.md b/docs/resources/system.md index c0ef3bd7..cdb353a9 100644 --- a/docs/resources/system.md +++ b/docs/resources/system.md @@ -170,6 +170,10 @@ The following arguments are supported: - **web_management_https** (Optional, Block) Declare `web-management https` configuration. See [below for nested schema](#web_management_https-arguments-for-services). + - **web_management_session_idle_timeout** (Optional, Number) + Default timeout of web-management sessions (1..1440 minutes). + - **web_management_session_limit** (Optional, Number) + Maximum number of web-management sessions to allow (1..1024). - **syslog** (Optional, Block) Declare `syslog` configuration. - **archive** (Optional, Block) diff --git a/internal/providerfwk/resource_system.go b/internal/providerfwk/resource_system.go index 2c891a83..f331f5e6 100644 --- a/internal/providerfwk/resource_system.go +++ b/internal/providerfwk/resource_system.go @@ -901,6 +901,22 @@ func (rsc *system) Schema( }, "services": schema.SingleNestedBlock{ Description: "Declare `services` configuration.", + Attributes: map[string]schema.Attribute{ + "web_management_session_idle_timeout": schema.Int64Attribute{ + Optional: true, + Description: "Default timeout of web-management sessions (minutes).", + Validators: []validator.Int64{ + int64validator.Between(1, 1440), + }, + }, + "web_management_session_limit": schema.Int64Attribute{ + Optional: true, + Description: "Maximum number of web-management sessions to allow.", + Validators: []validator.Int64{ + int64validator.Between(1, 1024), + }, + }, + }, Blocks: map[string]schema.Block{ "netconf_ssh": schema.SingleNestedBlock{ Description: "Declare `netconf ssh` configuration.", @@ -1934,16 +1950,23 @@ func (block *systemBlockPortsConfig) isEmpty() bool { } } +//nolint:lll type systemBlockServices struct { - NetconfSSH *systemBlockServicesBlockNetconfSSH `tfsdk:"netconf_ssh"` - NetconfTraceoptions *systemBlockServicesBlockNetconfTraceoptions `tfsdk:"netconf_traceoptions"` - SSH *systemBlockServicesBlockSSH `tfsdk:"ssh"` - WebManagementHTTP *systemBlockServicesBlockWebManagementHTTP `tfsdk:"web_management_http"` - WebManagementHTTPS *systemBlockServicesBlockWebManagementHTTPS `tfsdk:"web_management_https"` + WebManagementSessionIdleTimeout types.Int64 `tfsdk:"web_management_session_idle_timeout"` + WebManagementSessionLimit types.Int64 `tfsdk:"web_management_session_limit"` + NetconfSSH *systemBlockServicesBlockNetconfSSH `tfsdk:"netconf_ssh"` + NetconfTraceoptions *systemBlockServicesBlockNetconfTraceoptions `tfsdk:"netconf_traceoptions"` + SSH *systemBlockServicesBlockSSH `tfsdk:"ssh"` + WebManagementHTTP *systemBlockServicesBlockWebManagementHTTP `tfsdk:"web_management_http"` + WebManagementHTTPS *systemBlockServicesBlockWebManagementHTTPS `tfsdk:"web_management_https"` } func (block *systemBlockServices) isEmpty() bool { switch { + case !block.WebManagementSessionIdleTimeout.IsNull(): + return false + case !block.WebManagementSessionLimit.IsNull(): + return false case block.NetconfSSH != nil: return false case block.NetconfTraceoptions != nil: @@ -1959,16 +1982,23 @@ func (block *systemBlockServices) isEmpty() bool { } } +//nolint:lll type systemBlockServicesConfig struct { - NetconfSSH *systemBlockServicesBlockNetconfSSH `tfsdk:"netconf_ssh"` - NetconfTraceoptions *systemBlockServicesBlockNetconfTraceoptionsConfig `tfsdk:"netconf_traceoptions"` - SSH *systemBlockServicesBlockSSHConfig `tfsdk:"ssh"` - WebManagementHTTP *systemBlockServicesBlockWebManagementHTTPConfig `tfsdk:"web_management_http"` - WebManagementHTTPS *systemBlockServicesBlockWebManagementHTTPSConfig `tfsdk:"web_management_https"` + WebManagementSessionIdleTimeout types.Int64 `tfsdk:"web_management_session_idle_timeout"` + WebManagementSessionLimit types.Int64 `tfsdk:"web_management_session_limit"` + NetconfSSH *systemBlockServicesBlockNetconfSSH `tfsdk:"netconf_ssh"` + NetconfTraceoptions *systemBlockServicesBlockNetconfTraceoptionsConfig `tfsdk:"netconf_traceoptions"` + SSH *systemBlockServicesBlockSSHConfig `tfsdk:"ssh"` + WebManagementHTTP *systemBlockServicesBlockWebManagementHTTPConfig `tfsdk:"web_management_http"` + WebManagementHTTPS *systemBlockServicesBlockWebManagementHTTPSConfig `tfsdk:"web_management_https"` } func (block *systemBlockServicesConfig) isEmpty() bool { switch { + case !block.WebManagementSessionIdleTimeout.IsNull(): + return false + case !block.WebManagementSessionLimit.IsNull(): + return false case block.NetconfSSH != nil: return false case block.NetconfTraceoptions != nil: @@ -2686,6 +2716,26 @@ func (rsc *system) ValidateConfig( //nolint:gocognit } } } + if !config.Services.WebManagementSessionIdleTimeout.IsNull() { + if config.Services.WebManagementHTTP == nil && config.Services.WebManagementHTTPS == nil { + resp.Diagnostics.AddAttributeError( + path.Root("services").AtName("web_management_session_idle_timeout"), + tfdiag.MissingConfigErrSummary, + "web_management_http or web_management_https block must be specified"+ + " with web_management_session_idle_timeout in services block", + ) + } + } + if !config.Services.WebManagementSessionLimit.IsNull() { + if config.Services.WebManagementHTTP == nil && config.Services.WebManagementHTTPS == nil { + resp.Diagnostics.AddAttributeError( + path.Root("services").AtName("web_management_session_limit"), + tfdiag.MissingConfigErrSummary, + "web_management_http or web_management_https block must be specified"+ + " with web_management_session_limit in services block", + ) + } + } if config.Services.WebManagementHTTPS != nil { if config.Services.WebManagementHTTPS.LocalCertificate.IsNull() && config.Services.WebManagementHTTPS.PkiLocalCertificate.IsNull() && @@ -3422,6 +3472,24 @@ func (block *systemBlockServices) configSet() ( configSet := make([]string, 0) setPrefix := "set system services " + if !block.WebManagementSessionIdleTimeout.IsNull() { + if block.WebManagementHTTP == nil && block.WebManagementHTTPS == nil { + return configSet, path.Root("services").AtName("web_management_session_idle_timeout"), + fmt.Errorf("web_management_http or web_management_https block must be specified" + + " with web_management_session_idle_timeout in services block") + } + configSet = append(configSet, setPrefix+"web-management session idle-timeout "+ + utils.ConvI64toa(block.WebManagementSessionIdleTimeout.ValueInt64())) + } + if !block.WebManagementSessionLimit.IsNull() { + if block.WebManagementHTTP == nil && block.WebManagementHTTPS == nil { + return configSet, path.Root("services").AtName("web_management_session_limit"), + fmt.Errorf("web_management_http or web_management_https block must be specified" + + " with web_management_session_limit in services block") + } + configSet = append(configSet, setPrefix+"web-management session session-limit "+ + utils.ConvI64toa(block.WebManagementSessionLimit.ValueInt64())) + } if block.NetconfSSH != nil { if block.NetconfSSH.isEmpty() { return configSet, path.Root("services").AtName("netconf_ssh").AtName("*"), @@ -3815,6 +3883,16 @@ func (rscData *systemData) read( rscData.Services = &systemBlockServices{} } switch { + case balt.CutPrefixInString(&itemTrim, "services web-management session idle-timeout "): + rscData.Services.WebManagementSessionIdleTimeout, err = tfdata.ConvAtoi64Value(itemTrim) + if err != nil { + return err + } + case balt.CutPrefixInString(&itemTrim, "services web-management session session-limit "): + rscData.Services.WebManagementSessionLimit, err = tfdata.ConvAtoi64Value(itemTrim) + if err != nil { + return err + } case bchk.StringHasOneOfPrefixes(itemTrim, systemBlockServicesBlockNetconfSSH{}.junosLines()): if rscData.Services.NetconfSSH == nil { rscData.Services.NetconfSSH = &systemBlockServicesBlockNetconfSSH{} @@ -4215,6 +4293,8 @@ func (block *systemBlockPorts) read(itemTrim string) (err error) { func (systemBlockServices) junosLines() []string { s := make([]string, 0, 50) + s = append(s, "services web-management session idle-timeout") + s = append(s, "services web-management session session-limit") s = append(s, systemBlockServicesBlockNetconfSSH{}.junosLines()...) s = append(s, "services netconf traceoptions") s = append(s, systemBlockServicesBlockSSH{}.junosLines()...) diff --git a/internal/providerfwk/testdata/TestAccResourceSystem_basic/1/main.tf b/internal/providerfwk/testdata/TestAccResourceSystem_basic/1/main.tf index 3859d5be..d0160e1c 100644 --- a/internal/providerfwk/testdata/TestAccResourceSystem_basic/1/main.tf +++ b/internal/providerfwk/testdata/TestAccResourceSystem_basic/1/main.tf @@ -141,6 +141,8 @@ resource "junos_system" "testacc_system" { root_login = "deny" tcp_forwarding = true } + web_management_session_idle_timeout = 600 + web_management_session_limit = 100 web_management_http { interface = ["fxp0.0"] port = 80 From 62289d5014c3a9281a0031e5db18afcce2fc4ed6 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Fri, 15 Dec 2023 19:43:17 +0100 Subject: [PATCH 38/43] r/system_syslog_host: use new provider via framework --- .changes/issue-593.md | 9 + internal/providerfwk/provider.go | 1 + .../resource_system_syslog_host.go | 680 ++++++++++++++++++ .../resource_system_syslog_host_test.go | 73 +- .../1/main.tf | 4 + .../2/main.tf | 6 + .../3/main.tf | 27 + .../1/main.tf | 27 + .../1/provider.tf | 10 + .../2/main.tf | 1 + .../upgradestate_system_syslog_host.go | 188 +++++ .../upgradestate_system_syslog_host_test.go | 29 + internal/providersdk/func_common.go | 20 - internal/providersdk/provider.go | 1 - .../resource_system_syslog_host.go | 661 ----------------- 15 files changed, 991 insertions(+), 746 deletions(-) create mode 100644 .changes/issue-593.md create mode 100644 internal/providerfwk/resource_system_syslog_host.go rename internal/{providersdk => providerfwk}/resource_system_syslog_host_test.go (63%) create mode 100644 internal/providerfwk/testdata/TestAccResourceSystemSyslogHost_basic/1/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceSystemSyslogHost_basic/2/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceSystemSyslogHost_basic/3/main.tf create mode 100644 internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic/1/main.tf create mode 100644 internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic/1/provider.tf create mode 120000 internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic/2/main.tf create mode 100644 internal/providerfwk/upgradestate_system_syslog_host.go create mode 100644 internal/providerfwk/upgradestate_system_syslog_host_test.go delete mode 100644 internal/providersdk/resource_system_syslog_host.go diff --git a/.changes/issue-593.md b/.changes/issue-593.md new file mode 100644 index 00000000..b14283f0 --- /dev/null +++ b/.changes/issue-593.md @@ -0,0 +1,9 @@ + +FEATURES: + +ENHANCEMENTS: + +* **resource/junos_system_syslog_host**: resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) + optional boolean attributes doesn't accept value *false* + optional string attributes doesn't accept *empty* value + the resource schema has been upgraded to have one-blocks in single mode instead of list diff --git a/internal/providerfwk/provider.go b/internal/providerfwk/provider.go index dc6adf43..4e6e88b5 100644 --- a/internal/providerfwk/provider.go +++ b/internal/providerfwk/provider.go @@ -279,6 +279,7 @@ func (p *junosProvider) Resources(_ context.Context) []func() resource.Resource newStaticRouteResource, newSwitchOptionsResource, newSystemResource, + newSystemSyslogHostResource, } } diff --git a/internal/providerfwk/resource_system_syslog_host.go b/internal/providerfwk/resource_system_syslog_host.go new file mode 100644 index 00000000..7755d654 --- /dev/null +++ b/internal/providerfwk/resource_system_syslog_host.go @@ -0,0 +1,680 @@ +package providerfwk + +import ( + "context" + "strings" + + "github.com/jeremmfr/terraform-provider-junos/internal/junos" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdata" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdiag" + "github.com/jeremmfr/terraform-provider-junos/internal/tfplanmodifier" + "github.com/jeremmfr/terraform-provider-junos/internal/tfvalidator" + "github.com/jeremmfr/terraform-provider-junos/internal/utils" + + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + balt "github.com/jeremmfr/go-utils/basicalter" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ resource.Resource = &systemSyslogHost{} + _ resource.ResourceWithConfigure = &systemSyslogHost{} + _ resource.ResourceWithImportState = &systemSyslogHost{} + _ resource.ResourceWithUpgradeState = &systemSyslogHost{} +) + +type systemSyslogHost struct { + client *junos.Client +} + +func newSystemSyslogHostResource() resource.Resource { + return &systemSyslogHost{} +} + +func (rsc *systemSyslogHost) typeName() string { + return providerName + "_system_syslog_host" +} + +func (rsc *systemSyslogHost) junosName() string { + return "system syslog host" +} + +func (rsc *systemSyslogHost) junosClient() *junos.Client { + return rsc.client +} + +func (rsc *systemSyslogHost) Metadata( + _ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse, +) { + resp.TypeName = rsc.typeName() +} + +func (rsc *systemSyslogHost) Configure( + ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse, +) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + client, ok := req.ProviderData.(*junos.Client) + if !ok { + unexpectedResourceConfigureType(ctx, req, resp) + + return + } + rsc.client = client +} + +func (rsc *systemSyslogHost) Schema( + _ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse, +) { + resp.Schema = schema.Schema{ + Version: 1, + Description: defaultResourceSchemaDescription(rsc), + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "An identifier for the resource with format ``.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "host": schema.StringAttribute{ + Required: true, + Description: "Host to be notified.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 250), + tfvalidator.StringFormat(tfvalidator.DNSNameFormat), + }, + }, + "allow_duplicates": schema.BoolAttribute{ + Optional: true, + Description: "Do not suppress the repeated message.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "exclude_hostname": schema.BoolAttribute{ + Optional: true, + Description: "Exclude hostname field in messages.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "explicit_priority": schema.BoolAttribute{ + Optional: true, + Description: "Include priority and facility in messages.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "facility_override": schema.StringAttribute{ + Optional: true, + Description: "Alternate facility for logging to remote host.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogFacilities()...), + }, + }, + "log_prefix": schema.StringAttribute{ + Optional: true, + Description: "Prefix for all logging to this host.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + tfvalidator.StringDoubleQuoteExclusion(), + }, + }, + "match": schema.StringAttribute{ + Optional: true, + Description: "Regular expression for lines to be logged.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + tfvalidator.StringDoubleQuoteExclusion(), + }, + }, + "match_strings": schema.ListAttribute{ + ElementType: types.StringType, + Optional: true, + Description: "Matching string(s) for lines to be logged.", + Validators: []validator.List{ + listvalidator.SizeAtLeast(1), + listvalidator.ValueStringsAre( + stringvalidator.LengthAtLeast(1), + tfvalidator.StringDoubleQuoteExclusion(), + ), + }, + }, + "port": schema.Int64Attribute{ + Optional: true, + Description: "Port number.", + Validators: []validator.Int64{ + int64validator.Between(1, 65535), + }, + }, + "source_address": schema.StringAttribute{ + Optional: true, + Description: "Use specified address as source address.", + Validators: []validator.String{ + tfvalidator.StringIPAddress(), + }, + }, + "any_severity": schema.StringAttribute{ + Optional: true, + Description: "All facilities sseverity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "authorization_severity": schema.StringAttribute{ + Optional: true, + Description: "Authorization system severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "changelog_severity": schema.StringAttribute{ + Optional: true, + Description: "Configuration change log severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "conflictlog_severity": schema.StringAttribute{ + Optional: true, + Description: "Configuration conflict log severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "daemon_severity": schema.StringAttribute{ + Optional: true, + Description: "Various system processes severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "dfc_severity": schema.StringAttribute{ + Optional: true, + Description: "Dynamic flow capture severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "external_severity": schema.StringAttribute{ + Optional: true, + Description: "Local external applications severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "firewall_severity": schema.StringAttribute{ + Optional: true, + Description: "Firewall filtering system severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "ftp_severity": schema.StringAttribute{ + Optional: true, + Description: "FTP process severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "interactivecommands_severity": schema.StringAttribute{ + Optional: true, + Description: "Commands executed by the UI severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "kernel_severity": schema.StringAttribute{ + Optional: true, + Description: "Kernel severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "ntp_severity": schema.StringAttribute{ + Optional: true, + Description: "NTP process severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "pfe_severity": schema.StringAttribute{ + Optional: true, + Description: "Packet Forwarding Engine severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "security_severity": schema.StringAttribute{ + Optional: true, + Description: "Security related severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "user_severity": schema.StringAttribute{ + Optional: true, + Description: "User processes severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + }, + Blocks: map[string]schema.Block{ + "structured_data": schema.SingleNestedBlock{ + Description: "Log system message in structured format.", + Attributes: map[string]schema.Attribute{ + "brief": schema.BoolAttribute{ + Optional: true, + Description: "Omit English-language text from end of logged message.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + }, + PlanModifiers: []planmodifier.Object{ + tfplanmodifier.BlockRemoveNull(), + }, + }, + }, + } +} + +type systemSyslogHostData struct { + AllowDuplicates types.Bool `tfsdk:"allow_duplicates"` + ExcludeHostname types.Bool `tfsdk:"exclude_hostname"` + ExplicitPriority types.Bool `tfsdk:"explicit_priority"` + ID types.String `tfsdk:"id"` + Host types.String `tfsdk:"host"` + FacilityOverride types.String `tfsdk:"facility_override"` + LogPrefix types.String `tfsdk:"log_prefix"` + Match types.String `tfsdk:"match"` + MatchStrings []types.String `tfsdk:"match_strings"` + Port types.Int64 `tfsdk:"port"` + SourceAddress types.String `tfsdk:"source_address"` + AnySeverity types.String `tfsdk:"any_severity"` + AuthorizationSeverity types.String `tfsdk:"authorization_severity"` + ChangelogSeverity types.String `tfsdk:"changelog_severity"` + ConflictlogSeverity types.String `tfsdk:"conflictlog_severity"` + DaemonSeverity types.String `tfsdk:"daemon_severity"` + DfcSeverity types.String `tfsdk:"dfc_severity"` + ExternalSeverity types.String `tfsdk:"external_severity"` + FirewallSeverity types.String `tfsdk:"firewall_severity"` + FtpSeverity types.String `tfsdk:"ftp_severity"` + InteractivecommandsSeverity types.String `tfsdk:"interactivecommands_severity"` + KernelSeverity types.String `tfsdk:"kernel_severity"` + NtpSeverity types.String `tfsdk:"ntp_severity"` + PfeSeverity types.String `tfsdk:"pfe_severity"` + SecuritySeverity types.String `tfsdk:"security_severity"` + UserSeverity types.String `tfsdk:"user_severity"` + StructuredData *systemSyslogHostBlockStructuredData `tfsdk:"structured_data"` +} + +type systemSyslogHostBlockStructuredData struct { + Brief types.Bool `tfsdk:"brief"` +} + +func (rsc *systemSyslogHost) Create( + ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse, +) { + var plan systemSyslogHostData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + if plan.Host.ValueString() == "" { + resp.Diagnostics.AddAttributeError( + path.Root("host"), + "Empty Host", + defaultResourceCouldNotCreateWithEmptyMessage(rsc, "host"), + ) + + return + } + + defaultResourceCreate( + ctx, + rsc, + func(fnCtx context.Context, junSess *junos.Session) bool { + hostExists, err := checkSystemSyslogHostExists(fnCtx, plan.Host.ValueString(), junSess) + if err != nil { + resp.Diagnostics.AddError(tfdiag.PreCheckErrSummary, err.Error()) + + return false + } + if hostExists { + resp.Diagnostics.AddError( + tfdiag.DuplicateConfigErrSummary, + defaultResourceAlreadyExistsMessage(rsc, plan.Host), + ) + + return false + } + + return true + }, + func(fnCtx context.Context, junSess *junos.Session) bool { + hostExists, err := checkSystemSyslogHostExists(fnCtx, plan.Host.ValueString(), junSess) + if err != nil { + resp.Diagnostics.AddError(tfdiag.PostCheckErrSummary, err.Error()) + + return false + } + if !hostExists { + resp.Diagnostics.AddError( + tfdiag.NotFoundErrSummary, + defaultResourceDoesNotExistsAfterCommitMessage(rsc, plan.Host), + ) + + return false + } + + return true + }, + &plan, + resp, + ) +} + +func (rsc *systemSyslogHost) Read( + ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse, +) { + var state, data systemSyslogHostData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + var _ resourceDataReadFrom1String = &data + defaultResourceRead( + ctx, + rsc, + []string{ + state.Host.ValueString(), + }, + &data, + nil, + resp, + ) +} + +func (rsc *systemSyslogHost) Update( + ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse, +) { + var plan, state systemSyslogHostData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceUpdate( + ctx, + rsc, + &state, + &plan, + resp, + ) +} + +func (rsc *systemSyslogHost) Delete( + ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse, +) { + var state systemSyslogHostData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceDelete( + ctx, + rsc, + &state, + resp, + ) +} + +func (rsc *systemSyslogHost) ImportState( + ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse, +) { + var data systemSyslogHostData + + var _ resourceDataReadFrom1String = &data + defaultResourceImportState( + ctx, + rsc, + &data, + req, + resp, + defaultResourceImportDontFindIDStrMessage(rsc, req.ID, "host"), + ) +} + +func checkSystemSyslogHostExists( + _ context.Context, host string, junSess *junos.Session, +) ( + bool, error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "system syslog host " + host + junos.PipeDisplaySet) + if err != nil { + return false, err + } + if showConfig == junos.EmptyW { + return false, nil + } + + return true, nil +} + +func (rscData *systemSyslogHostData) fillID() { + rscData.ID = types.StringValue(rscData.Host.ValueString()) +} + +func (rscData *systemSyslogHostData) nullID() bool { + return rscData.ID.IsNull() +} + +func (rscData *systemSyslogHostData) set( + _ context.Context, junSess *junos.Session, +) ( + path.Path, error, +) { + configSet := make([]string, 0) + setPrefix := "set system syslog host " + rscData.Host.ValueString() + " " + + if rscData.AllowDuplicates.ValueBool() { + configSet = append(configSet, setPrefix+"allow-duplicates") + } + if rscData.ExcludeHostname.ValueBool() { + configSet = append(configSet, setPrefix+"exclude-hostname") + } + if rscData.ExplicitPriority.ValueBool() { + configSet = append(configSet, setPrefix+"explicit-priority") + } + if v := rscData.FacilityOverride.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"facility-override "+v) + } + if v := rscData.LogPrefix.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"log-prefix \""+v+"\"") + } + if v := rscData.Match.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"match \""+v+"\"") + } + for _, v := range rscData.MatchStrings { + configSet = append(configSet, setPrefix+"match-strings \""+v.ValueString()+"\"") + } + if !rscData.Port.IsNull() { + configSet = append(configSet, setPrefix+"port "+ + utils.ConvI64toa(rscData.Port.ValueInt64())) + } + if v := rscData.SourceAddress.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"source-address "+v) + } + if v := rscData.AnySeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"any "+v) + } + if v := rscData.AuthorizationSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"authorization "+v) + } + if v := rscData.ChangelogSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"change-log "+v) + } + if v := rscData.ConflictlogSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"conflict-log "+v) + } + if v := rscData.DaemonSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"daemon "+v) + } + if v := rscData.DfcSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"dfc "+v) + } + if v := rscData.ExternalSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"external "+v) + } + if v := rscData.FirewallSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"firewall "+v) + } + if v := rscData.FtpSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"ftp "+v) + } + if v := rscData.InteractivecommandsSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"interactive-commands "+v) + } + if v := rscData.KernelSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"kernel "+v) + } + if v := rscData.NtpSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"ntp "+v) + } + if v := rscData.PfeSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"pfe "+v) + } + if v := rscData.SecuritySeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"security "+v) + } + if v := rscData.UserSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"user "+v) + } + if rscData.StructuredData != nil { + configSet = append(configSet, setPrefix+"structured-data") + if rscData.StructuredData.Brief.ValueBool() { + configSet = append(configSet, setPrefix+"structured-data brief") + } + } + + return path.Empty(), junSess.ConfigSet(configSet) +} + +func (rscData *systemSyslogHostData) read( + _ context.Context, host string, junSess *junos.Session, +) ( + err error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "system syslog host " + host + junos.PipeDisplaySetRelative) + if err != nil { + return err + } + if showConfig != junos.EmptyW { + rscData.Host = types.StringValue(host) + rscData.fillID() + for _, item := range strings.Split(showConfig, "\n") { + if strings.Contains(item, junos.XMLStartTagConfigOut) { + continue + } + if strings.Contains(item, junos.XMLEndTagConfigOut) { + break + } + itemTrim := strings.TrimPrefix(item, junos.SetLS) + switch { + case itemTrim == "allow-duplicates": + rscData.AllowDuplicates = types.BoolValue(true) + case itemTrim == "exclude-hostname": + rscData.ExcludeHostname = types.BoolValue(true) + case itemTrim == "explicit-priority": + rscData.ExplicitPriority = types.BoolValue(true) + case balt.CutPrefixInString(&itemTrim, "facility-override "): + rscData.FacilityOverride = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "log-prefix "): + rscData.LogPrefix = types.StringValue(strings.Trim(itemTrim, "\"")) + case balt.CutPrefixInString(&itemTrim, "match "): + rscData.Match = types.StringValue(strings.Trim(itemTrim, "\"")) + case balt.CutPrefixInString(&itemTrim, "match-strings "): + rscData.MatchStrings = append(rscData.MatchStrings, + types.StringValue(strings.Trim(itemTrim, "\""))) + case balt.CutPrefixInString(&itemTrim, "port "): + rscData.Port, err = tfdata.ConvAtoi64Value(itemTrim) + if err != nil { + return err + } + case balt.CutPrefixInString(&itemTrim, "source-address "): + rscData.SourceAddress = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "any "): + rscData.AnySeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "authorization "): + rscData.AuthorizationSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "change-log "): + rscData.ChangelogSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "conflict-log "): + rscData.ConflictlogSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "daemon "): + rscData.DaemonSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "dfc "): + rscData.DfcSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "external "): + rscData.ExternalSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "firewall "): + rscData.FirewallSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "ftp "): + rscData.FtpSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "interactive-commands "): + rscData.InteractivecommandsSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "kernel "): + rscData.KernelSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "ntp "): + rscData.NtpSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "pfe "): + rscData.PfeSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "security "): + rscData.SecuritySeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "user "): + rscData.UserSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "structured-data"): + if rscData.StructuredData == nil { + rscData.StructuredData = &systemSyslogHostBlockStructuredData{} + } + if itemTrim == " brief" { + rscData.StructuredData.Brief = types.BoolValue(true) + } + } + } + } + + return nil +} + +func (rscData *systemSyslogHostData) del( + _ context.Context, junSess *junos.Session, +) error { + configSet := []string{ + "delete system syslog host " + rscData.Host.ValueString(), + } + + return junSess.ConfigSet(configSet) +} diff --git a/internal/providersdk/resource_system_syslog_host_test.go b/internal/providerfwk/resource_system_syslog_host_test.go similarity index 63% rename from internal/providersdk/resource_system_syslog_host_test.go rename to internal/providerfwk/resource_system_syslog_host_test.go index f50c7ac6..78275f3a 100644 --- a/internal/providersdk/resource_system_syslog_host_test.go +++ b/internal/providerfwk/resource_system_syslog_host_test.go @@ -1,9 +1,10 @@ -package providersdk_test +package providerfwk_test import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestAccResourceSystemSyslogHost_basic(t *testing.T) { @@ -12,7 +13,7 @@ func TestAccResourceSystemSyslogHost_basic(t *testing.T) { ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccResourceSystemSyslogHostConfigCreate(), + ConfigDirectory: config.TestStepDirectory(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("junos_system_syslog_host.testacc_syslogHost", "host", "192.0.2.1"), @@ -21,21 +22,17 @@ func TestAccResourceSystemSyslogHost_basic(t *testing.T) { ), }, { - Config: testAccResourceSystemSyslogHostConfigUpdate(), + ConfigDirectory: config.TestStepDirectory(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("junos_system_syslog_host.testacc_syslogHost", - "structured_data.#", "1"), - resource.TestCheckResourceAttr("junos_system_syslog_host.testacc_syslogHost", - "structured_data.0.brief", "true"), + "structured_data.brief", "true"), ), }, { - Config: testAccResourceSystemSyslogHostConfigUpdate2(), + ConfigDirectory: config.TestStepDirectory(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("junos_system_syslog_host.testacc_syslogHost", - "structured_data.#", "1"), - resource.TestCheckResourceAttr("junos_system_syslog_host.testacc_syslogHost", - "structured_data.0.brief", "false"), + resource.TestCheckResourceAttrSet("junos_system_syslog_host.testacc_syslogHost", + "structured_data.%"), resource.TestCheckResourceAttr("junos_system_syslog_host.testacc_syslogHost", "source_address", "192.0.2.2"), resource.TestCheckResourceAttr("junos_system_syslog_host.testacc_syslogHost", @@ -94,55 +91,3 @@ func TestAccResourceSystemSyslogHost_basic(t *testing.T) { }, }) } - -func testAccResourceSystemSyslogHostConfigCreate() string { - return ` -resource "junos_system_syslog_host" "testacc_syslogHost" { - host = "192.0.2.1" - port = 514 -} -` -} - -func testAccResourceSystemSyslogHostConfigUpdate() string { - return ` -resource "junos_system_syslog_host" "testacc_syslogHost" { - host = "192.0.2.1" - structured_data { - brief = true - } -} -` -} - -func testAccResourceSystemSyslogHostConfigUpdate2() string { - return ` -resource "junos_system_syslog_host" "testacc_syslogHost" { - host = "192.0.2.1" - port = 514 - allow_duplicates = true - exclude_hostname = true - explicit_priority = true - facility_override = "local3" - log_prefix = "prefix" - match = "match testacc" - match_strings = ["match testacc"] - any_severity = "emergency" - changelog_severity = "critical" - conflictlog_severity = "error" - daemon_severity = "warning" - dfc_severity = "alert" - external_severity = "any" - firewall_severity = "info" - ftp_severity = "none" - interactivecommands_severity = "notice" - kernel_severity = "emergency" - ntp_severity = "emergency" - pfe_severity = "emergency" - security_severity = "emergency" - user_severity = "emergency" - structured_data {} - source_address = "192.0.2.2" -} -` -} diff --git a/internal/providerfwk/testdata/TestAccResourceSystemSyslogHost_basic/1/main.tf b/internal/providerfwk/testdata/TestAccResourceSystemSyslogHost_basic/1/main.tf new file mode 100644 index 00000000..df0c46f6 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSystemSyslogHost_basic/1/main.tf @@ -0,0 +1,4 @@ +resource "junos_system_syslog_host" "testacc_syslogHost" { + host = "192.0.2.1" + port = 514 +} diff --git a/internal/providerfwk/testdata/TestAccResourceSystemSyslogHost_basic/2/main.tf b/internal/providerfwk/testdata/TestAccResourceSystemSyslogHost_basic/2/main.tf new file mode 100644 index 00000000..117c2837 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSystemSyslogHost_basic/2/main.tf @@ -0,0 +1,6 @@ +resource "junos_system_syslog_host" "testacc_syslogHost" { + host = "192.0.2.1" + structured_data { + brief = true + } +} diff --git a/internal/providerfwk/testdata/TestAccResourceSystemSyslogHost_basic/3/main.tf b/internal/providerfwk/testdata/TestAccResourceSystemSyslogHost_basic/3/main.tf new file mode 100644 index 00000000..ae5f97cd --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSystemSyslogHost_basic/3/main.tf @@ -0,0 +1,27 @@ +resource "junos_system_syslog_host" "testacc_syslogHost" { + host = "192.0.2.1" + port = 514 + allow_duplicates = true + exclude_hostname = true + explicit_priority = true + facility_override = "local3" + log_prefix = "prefix" + match = "match testacc" + match_strings = ["match testacc"] + any_severity = "emergency" + changelog_severity = "critical" + conflictlog_severity = "error" + daemon_severity = "warning" + dfc_severity = "alert" + external_severity = "any" + firewall_severity = "info" + ftp_severity = "none" + interactivecommands_severity = "notice" + kernel_severity = "emergency" + ntp_severity = "emergency" + pfe_severity = "emergency" + security_severity = "emergency" + user_severity = "emergency" + structured_data {} + source_address = "192.0.2.2" +} diff --git a/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic/1/main.tf b/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic/1/main.tf new file mode 100644 index 00000000..f065ca68 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic/1/main.tf @@ -0,0 +1,27 @@ +resource "junos_system_syslog_host" "testacc_v0to1_syslogHost" { + host = "192.0.2.2" + port = 514 + allow_duplicates = true + exclude_hostname = true + explicit_priority = true + facility_override = "local3" + log_prefix = "prefix" + match = "match testacc" + match_strings = ["match testacc"] + any_severity = "emergency" + changelog_severity = "critical" + conflictlog_severity = "error" + daemon_severity = "warning" + dfc_severity = "alert" + external_severity = "any" + firewall_severity = "info" + ftp_severity = "none" + interactivecommands_severity = "notice" + kernel_severity = "emergency" + ntp_severity = "emergency" + pfe_severity = "emergency" + security_severity = "emergency" + user_severity = "emergency" + structured_data {} + source_address = "192.0.2.2" +} diff --git a/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic/1/provider.tf b/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic/1/provider.tf new file mode 100644 index 00000000..713fa309 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic/1/provider.tf @@ -0,0 +1,10 @@ +terraform { + required_providers { + junos = { + source = "registry.terraform.io/jeremmfr/junos" + version = "1.33.0" + } + } +} + +provider "junos" {} diff --git a/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic/2/main.tf b/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic/2/main.tf new file mode 120000 index 00000000..7a6c4026 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic/2/main.tf @@ -0,0 +1 @@ +../1/main.tf \ No newline at end of file diff --git a/internal/providerfwk/upgradestate_system_syslog_host.go b/internal/providerfwk/upgradestate_system_syslog_host.go new file mode 100644 index 00000000..dcb7a946 --- /dev/null +++ b/internal/providerfwk/upgradestate_system_syslog_host.go @@ -0,0 +1,188 @@ +package providerfwk + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func (rsc *systemSyslogHost) UpgradeState(_ context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ + 0: { + PriorSchema: &schema.Schema{ + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + }, + "host": schema.StringAttribute{ + Required: true, + }, + "allow_duplicates": schema.BoolAttribute{ + Optional: true, + }, + "exclude_hostname": schema.BoolAttribute{ + Optional: true, + }, + "explicit_priority": schema.BoolAttribute{ + Optional: true, + }, + "facility_override": schema.StringAttribute{ + Optional: true, + }, + "log_prefix": schema.StringAttribute{ + Optional: true, + }, + "match": schema.StringAttribute{ + Optional: true, + }, + "match_strings": schema.ListAttribute{ + ElementType: types.StringType, + Optional: true, + }, + "port": schema.Int64Attribute{ + Optional: true, + }, + "source_address": schema.StringAttribute{ + Optional: true, + }, + "any_severity": schema.StringAttribute{ + Optional: true, + }, + "authorization_severity": schema.StringAttribute{ + Optional: true, + }, + "changelog_severity": schema.StringAttribute{ + Optional: true, + }, + "conflictlog_severity": schema.StringAttribute{ + Optional: true, + }, + "daemon_severity": schema.StringAttribute{ + Optional: true, + }, + "dfc_severity": schema.StringAttribute{ + Optional: true, + }, + "external_severity": schema.StringAttribute{ + Optional: true, + }, + "firewall_severity": schema.StringAttribute{ + Optional: true, + }, + "ftp_severity": schema.StringAttribute{ + Optional: true, + }, + "interactivecommands_severity": schema.StringAttribute{ + Optional: true, + }, + "kernel_severity": schema.StringAttribute{ + Optional: true, + }, + "ntp_severity": schema.StringAttribute{ + Optional: true, + }, + "pfe_severity": schema.StringAttribute{ + Optional: true, + }, + "security_severity": schema.StringAttribute{ + Optional: true, + }, + "user_severity": schema.StringAttribute{ + Optional: true, + }, + }, + Blocks: map[string]schema.Block{ + "structured_data": schema.ListNestedBlock{ + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "brief": schema.BoolAttribute{ + Optional: true, + }, + }, + }, + }, + }, + }, + StateUpgrader: upgradeSystemSyslogHostV0toV1, + }, + } +} + +func upgradeSystemSyslogHostV0toV1( + ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse, +) { + type modelV0 struct { + AllowDuplicates types.Bool `tfsdk:"allow_duplicates"` + ExcludeHostname types.Bool `tfsdk:"exclude_hostname"` + ExplicitPriority types.Bool `tfsdk:"explicit_priority"` + ID types.String `tfsdk:"id"` + Host types.String `tfsdk:"host"` + FacilityOverride types.String `tfsdk:"facility_override"` + LogPrefix types.String `tfsdk:"log_prefix"` + Match types.String `tfsdk:"match"` + MatchStrings []types.String `tfsdk:"match_strings"` + Port types.Int64 `tfsdk:"port"` + SourceAddress types.String `tfsdk:"source_address"` + AnySeverity types.String `tfsdk:"any_severity"` + AuthorizationSeverity types.String `tfsdk:"authorization_severity"` + ChangelogSeverity types.String `tfsdk:"changelog_severity"` + ConflictlogSeverity types.String `tfsdk:"conflictlog_severity"` + DaemonSeverity types.String `tfsdk:"daemon_severity"` + DfcSeverity types.String `tfsdk:"dfc_severity"` + ExternalSeverity types.String `tfsdk:"external_severity"` + FirewallSeverity types.String `tfsdk:"firewall_severity"` + FtpSeverity types.String `tfsdk:"ftp_severity"` + InteractivecommandsSeverity types.String `tfsdk:"interactivecommands_severity"` + KernelSeverity types.String `tfsdk:"kernel_severity"` + NtpSeverity types.String `tfsdk:"ntp_severity"` + PfeSeverity types.String `tfsdk:"pfe_severity"` + SecuritySeverity types.String `tfsdk:"security_severity"` + UserSeverity types.String `tfsdk:"user_severity"` + StructuredData []struct { + Brief types.Bool `tfsdk:"brief"` + } `tfsdk:"structured_data"` + } + + var dataV0 modelV0 + resp.Diagnostics.Append(req.State.Get(ctx, &dataV0)...) + if resp.Diagnostics.HasError() { + return + } + + var dataV1 systemSyslogHostData + dataV1.ID = dataV0.ID + dataV1.Host = dataV0.Host + dataV1.AllowDuplicates = dataV0.AllowDuplicates + dataV1.ExcludeHostname = dataV0.ExcludeHostname + dataV1.ExplicitPriority = dataV0.ExplicitPriority + dataV1.FacilityOverride = dataV0.FacilityOverride + dataV1.LogPrefix = dataV0.LogPrefix + dataV1.Match = dataV0.Match + dataV1.MatchStrings = dataV0.MatchStrings + dataV1.Port = dataV0.Port + dataV1.SourceAddress = dataV0.SourceAddress + dataV1.AnySeverity = dataV0.AnySeverity + dataV1.AuthorizationSeverity = dataV0.AuthorizationSeverity + dataV1.ChangelogSeverity = dataV0.ChangelogSeverity + dataV1.ConflictlogSeverity = dataV0.ConflictlogSeverity + dataV1.DaemonSeverity = dataV0.DaemonSeverity + dataV1.DfcSeverity = dataV0.DfcSeverity + dataV1.ExternalSeverity = dataV0.ExternalSeverity + dataV1.FirewallSeverity = dataV0.FirewallSeverity + dataV1.FtpSeverity = dataV0.FtpSeverity + dataV1.InteractivecommandsSeverity = dataV0.InteractivecommandsSeverity + dataV1.KernelSeverity = dataV0.KernelSeverity + dataV1.NtpSeverity = dataV0.NtpSeverity + dataV1.PfeSeverity = dataV0.PfeSeverity + dataV1.SecuritySeverity = dataV0.SecuritySeverity + dataV1.UserSeverity = dataV0.UserSeverity + if len(dataV0.StructuredData) > 0 { + dataV1.StructuredData = &systemSyslogHostBlockStructuredData{ + Brief: dataV0.StructuredData[0].Brief, + } + } + + resp.Diagnostics.Append(resp.State.Set(ctx, dataV1)...) +} diff --git a/internal/providerfwk/upgradestate_system_syslog_host_test.go b/internal/providerfwk/upgradestate_system_syslog_host_test.go new file mode 100644 index 00000000..a05eca56 --- /dev/null +++ b/internal/providerfwk/upgradestate_system_syslog_host_test.go @@ -0,0 +1,29 @@ +package providerfwk_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/plancheck" +) + +// export TESTACC_INTERFACE= for choose interface available else it's ge-0/0/3. +func TestAccUpgradeStateResourceSystemSyslogHost_V0toV1_basic(t *testing.T) { + resource.Test(t, resource.TestCase{ + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestStepDirectory(), + }, + { + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + ConfigDirectory: config.TestStepDirectory(), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + }, + }) +} diff --git a/internal/providersdk/func_common.go b/internal/providersdk/func_common.go index d3261afa..ba6f2174 100644 --- a/internal/providersdk/func_common.go +++ b/internal/providersdk/func_common.go @@ -146,26 +146,6 @@ func validateNameObjectJunos(exclude []string, length int, format formatName) sc } } -func validateAddress() schema.SchemaValidateDiagFunc { - return func(i interface{}, path cty.Path) diag.Diagnostics { - var diags diag.Diagnostics - v := i.(string) - - f := func(r rune) bool { - return (r < 'a' || r > 'z') && (r < '0' || r > '9') && r != '-' && r != '.' - } - if strings.IndexFunc(v, f) != -1 { - diags = append(diags, diag.Diagnostic{ - Severity: diag.Error, - Summary: fmt.Sprintf("%s invalid address (bad character)", v), - AttributePath: path, - }) - } - - return diags - } -} - func sortSetOfString(list []interface{}) []string { s := make([]string, len(list)) for k, e := range list { diff --git a/internal/providersdk/provider.go b/internal/providersdk/provider.go index bb190ce2..3657ec1c 100644 --- a/internal/providersdk/provider.go +++ b/internal/providersdk/provider.go @@ -228,7 +228,6 @@ func Provider() *schema.Provider { "junos_system_root_authentication": resourceSystemRootAuthentication(), "junos_system_services_dhcp_localserver_group": resourceSystemServicesDhcpLocalServerGroup(), "junos_system_syslog_file": resourceSystemSyslogFile(), - "junos_system_syslog_host": resourceSystemSyslogHost(), "junos_vlan": resourceVlan(), "junos_vstp": resourceVstp(), "junos_vstp_interface": resourceVstpInterface(), diff --git a/internal/providersdk/resource_system_syslog_host.go b/internal/providersdk/resource_system_syslog_host.go deleted file mode 100644 index 2459d3de..00000000 --- a/internal/providersdk/resource_system_syslog_host.go +++ /dev/null @@ -1,661 +0,0 @@ -package providersdk - -import ( - "context" - "fmt" - "strconv" - "strings" - - "github.com/jeremmfr/terraform-provider-junos/internal/junos" - - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - balt "github.com/jeremmfr/go-utils/basicalter" -) - -type syslogHostOptions struct { - allowDuplicates bool - excludeHostname bool - explicitPriority bool - port int - host string - facilityOverride string - logPrefix string - match string - sourceAddress string - anySeverity string - authorizationSeverity string - changelogSeverity string - conflictlogSeverity string - daemonSeverity string - dfcSeverity string - externalSeverity string - firewallSeverity string - ftpSeverity string - interactivecommandsSeverity string - kernelSeverity string - ntpSeverity string - pfeSeverity string - securitySeverity string - userSeverity string - matchStrings []string - structuredData []map[string]interface{} -} - -func resourceSystemSyslogHost() *schema.Resource { - return &schema.Resource{ - CreateWithoutTimeout: resourceSystemSyslogHostCreate, - ReadWithoutTimeout: resourceSystemSyslogHostRead, - UpdateWithoutTimeout: resourceSystemSyslogHostUpdate, - DeleteWithoutTimeout: resourceSystemSyslogHostDelete, - Importer: &schema.ResourceImporter{ - StateContext: resourceSystemSyslogHostImport, - }, - Schema: map[string]*schema.Schema{ - "host": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateDiagFunc: validateAddress(), - }, - "allow_duplicates": { - Type: schema.TypeBool, - Optional: true, - }, - "exclude_hostname": { - Type: schema.TypeBool, - Optional: true, - }, - "explicit_priority": { - Type: schema.TypeBool, - Optional: true, - }, - "facility_override": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(junos.SyslogFacilities(), false), - }, - "log_prefix": { - Type: schema.TypeString, - Optional: true, - ValidateDiagFunc: validateNameObjectJunos([]string{}, 32, formatDefault), - }, - "match": { - Type: schema.TypeString, - Optional: true, - }, - "match_strings": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "port": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(1, 65535), - }, - "source_address": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.IsIPAddress, - }, - "structured_data": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "brief": { - Type: schema.TypeBool, - Optional: true, - }, - }, - }, - }, - "any_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "authorization_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "changelog_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "conflictlog_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "daemon_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "dfc_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "external_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "firewall_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "ftp_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "interactivecommands_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "kernel_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "ntp_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "pfe_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "security_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "user_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - }, - } -} - -func resourceSystemSyslogHostCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - clt := m.(*junos.Client) - if clt.FakeCreateSetFile() { - junSess := clt.NewSessionWithoutNetconf(ctx) - if err := setSystemSyslogHost(d, junSess); err != nil { - return diag.FromErr(err) - } - d.SetId(d.Get("host").(string)) - - return nil - } - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return diag.FromErr(err) - } - defer junSess.Close() - if err := junSess.ConfigLock(ctx); err != nil { - return diag.FromErr(err) - } - var diagWarns diag.Diagnostics - syslogHostExists, err := checkSystemSyslogHostExists(d.Get("host").(string), junSess) - if err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - if syslogHostExists { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(fmt.Errorf("system syslog host %v already exists", d.Get("host").(string)))...) - } - - if err := setSystemSyslogHost(d, junSess); err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - warns, err := junSess.CommitConf(ctx, "create resource junos_system_syslog_host") - appendDiagWarns(&diagWarns, warns) - if err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - syslogHostExists, err = checkSystemSyslogHostExists(d.Get("host").(string), junSess) - if err != nil { - return append(diagWarns, diag.FromErr(err)...) - } - if syslogHostExists { - d.SetId(d.Get("host").(string)) - } else { - return append(diagWarns, diag.FromErr(fmt.Errorf("system syslog host %v not exists after commit "+ - "=> check your config", d.Get("host").(string)))...) - } - - return append(diagWarns, resourceSystemSyslogHostReadWJunSess(d, junSess)...) -} - -func resourceSystemSyslogHostRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - clt := m.(*junos.Client) - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return diag.FromErr(err) - } - defer junSess.Close() - - return resourceSystemSyslogHostReadWJunSess(d, junSess) -} - -func resourceSystemSyslogHostReadWJunSess(d *schema.ResourceData, junSess *junos.Session, -) diag.Diagnostics { - junos.MutexLock() - syslogHostOptions, err := readSystemSyslogHost(d.Get("host").(string), junSess) - junos.MutexUnlock() - if err != nil { - return diag.FromErr(err) - } - if syslogHostOptions.host == "" { - d.SetId("") - } else { - fillSystemSyslogHostData(d, syslogHostOptions) - } - - return nil -} - -func resourceSystemSyslogHostUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - d.Partial(true) - clt := m.(*junos.Client) - if clt.FakeUpdateAlso() { - junSess := clt.NewSessionWithoutNetconf(ctx) - if err := delSystemSyslogHost(d.Get("host").(string), junSess); err != nil { - return diag.FromErr(err) - } - if err := setSystemSyslogHost(d, junSess); err != nil { - return diag.FromErr(err) - } - d.Partial(false) - - return nil - } - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return diag.FromErr(err) - } - defer junSess.Close() - if err := junSess.ConfigLock(ctx); err != nil { - return diag.FromErr(err) - } - var diagWarns diag.Diagnostics - if err := delSystemSyslogHost(d.Get("host").(string), junSess); err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - if err := setSystemSyslogHost(d, junSess); err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - warns, err := junSess.CommitConf(ctx, "update resource junos_system_syslog_host") - appendDiagWarns(&diagWarns, warns) - if err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - d.Partial(false) - - return append(diagWarns, resourceSystemSyslogHostReadWJunSess(d, junSess)...) -} - -func resourceSystemSyslogHostDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - clt := m.(*junos.Client) - if clt.FakeDeleteAlso() { - junSess := clt.NewSessionWithoutNetconf(ctx) - if err := delSystemSyslogHost(d.Get("host").(string), junSess); err != nil { - return diag.FromErr(err) - } - - return nil - } - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return diag.FromErr(err) - } - defer junSess.Close() - if err := junSess.ConfigLock(ctx); err != nil { - return diag.FromErr(err) - } - var diagWarns diag.Diagnostics - if err := delSystemSyslogHost(d.Get("host").(string), junSess); err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - warns, err := junSess.CommitConf(ctx, "delete resource junos_system_syslog_host") - appendDiagWarns(&diagWarns, warns) - if err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - - return diagWarns -} - -func resourceSystemSyslogHostImport(ctx context.Context, d *schema.ResourceData, m interface{}, -) ([]*schema.ResourceData, error) { - clt := m.(*junos.Client) - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return nil, err - } - defer junSess.Close() - result := make([]*schema.ResourceData, 1) - - syslogHostExists, err := checkSystemSyslogHostExists(d.Id(), junSess) - if err != nil { - return nil, err - } - if !syslogHostExists { - return nil, fmt.Errorf("don't find system syslog host with id '%v' (id must be )", d.Id()) - } - syslogHostOptions, err := readSystemSyslogHost(d.Id(), junSess) - if err != nil { - return nil, err - } - fillSystemSyslogHostData(d, syslogHostOptions) - - result[0] = d - - return result, nil -} - -func checkSystemSyslogHostExists(host string, junSess *junos.Session) (bool, error) { - showConfig, err := junSess.Command(junos.CmdShowConfig + "system syslog host " + host + junos.PipeDisplaySet) - if err != nil { - return false, err - } - if showConfig == junos.EmptyW { - return false, nil - } - - return true, nil -} - -func setSystemSyslogHost(d *schema.ResourceData, junSess *junos.Session) error { - setPrefix := "set system syslog host " + d.Get("host").(string) - configSet := make([]string, 0) - - if d.Get("allow_duplicates").(bool) { - configSet = append(configSet, setPrefix+" allow-duplicates") - } - if d.Get("exclude_hostname").(bool) { - configSet = append(configSet, setPrefix+" exclude-hostname") - } - if d.Get("explicit_priority").(bool) { - configSet = append(configSet, setPrefix+" explicit-priority") - } - if d.Get("facility_override").(string) != "" { - configSet = append(configSet, setPrefix+" facility-override "+d.Get("facility_override").(string)) - } - if d.Get("log_prefix").(string) != "" { - configSet = append(configSet, setPrefix+" log-prefix "+d.Get("log_prefix").(string)) - } - if d.Get("match").(string) != "" { - configSet = append(configSet, setPrefix+" match \""+d.Get("match").(string)+"\"") - } - for _, v := range d.Get("match_strings").([]interface{}) { - configSet = append(configSet, setPrefix+" match-strings \""+v.(string)+"\"") - } - if d.Get("port").(int) != 0 { - configSet = append(configSet, setPrefix+" port "+strconv.Itoa(d.Get("port").(int))) - } - if d.Get("source_address").(string) != "" { - configSet = append(configSet, setPrefix+" source-address "+d.Get("source_address").(string)) - } - for _, v := range d.Get("structured_data").([]interface{}) { - configSet = append(configSet, setPrefix+" structured-data") - if v != nil { - ma := v.(map[string]interface{}) - if ma["brief"].(bool) { - configSet = append(configSet, setPrefix+" structured-data brief") - } - } - } - if d.Get("any_severity").(string) != "" { - configSet = append(configSet, setPrefix+" any "+d.Get("any_severity").(string)) - } - if d.Get("authorization_severity").(string) != "" { - configSet = append(configSet, setPrefix+" authorization "+d.Get("authorization_severity").(string)) - } - if d.Get("changelog_severity").(string) != "" { - configSet = append(configSet, setPrefix+" change-log "+d.Get("changelog_severity").(string)) - } - if d.Get("conflictlog_severity").(string) != "" { - configSet = append(configSet, setPrefix+" conflict-log "+d.Get("conflictlog_severity").(string)) - } - if d.Get("daemon_severity").(string) != "" { - configSet = append(configSet, setPrefix+" daemon "+d.Get("daemon_severity").(string)) - } - if d.Get("dfc_severity").(string) != "" { - configSet = append(configSet, setPrefix+" dfc "+d.Get("dfc_severity").(string)) - } - if d.Get("external_severity").(string) != "" { - configSet = append(configSet, setPrefix+" external "+d.Get("external_severity").(string)) - } - if d.Get("firewall_severity").(string) != "" { - configSet = append(configSet, setPrefix+" firewall "+d.Get("firewall_severity").(string)) - } - if d.Get("ftp_severity").(string) != "" { - configSet = append(configSet, setPrefix+" ftp "+d.Get("ftp_severity").(string)) - } - if d.Get("interactivecommands_severity").(string) != "" { - configSet = append(configSet, setPrefix+" interactive-commands "+d.Get("interactivecommands_severity").(string)) - } - if d.Get("kernel_severity").(string) != "" { - configSet = append(configSet, setPrefix+" kernel "+d.Get("kernel_severity").(string)) - } - if d.Get("ntp_severity").(string) != "" { - configSet = append(configSet, setPrefix+" ntp "+d.Get("ntp_severity").(string)) - } - if d.Get("pfe_severity").(string) != "" { - configSet = append(configSet, setPrefix+" pfe "+d.Get("pfe_severity").(string)) - } - if d.Get("security_severity").(string) != "" { - configSet = append(configSet, setPrefix+" security "+d.Get("security_severity").(string)) - } - if d.Get("user_severity").(string) != "" { - configSet = append(configSet, setPrefix+" user "+d.Get("user_severity").(string)) - } - - return junSess.ConfigSet(configSet) -} - -func readSystemSyslogHost(host string, junSess *junos.Session, -) (confRead syslogHostOptions, err error) { - showConfig, err := junSess.Command(junos.CmdShowConfig + "system syslog host " + host + junos.PipeDisplaySetRelative) - if err != nil { - return confRead, err - } - if showConfig != junos.EmptyW { - confRead.host = host - for _, item := range strings.Split(showConfig, "\n") { - if strings.Contains(item, junos.XMLStartTagConfigOut) { - continue - } - if strings.Contains(item, junos.XMLEndTagConfigOut) { - break - } - itemTrim := strings.TrimPrefix(item, junos.SetLS) - switch { - case itemTrim == "allow-duplicates": - confRead.allowDuplicates = true - case itemTrim == "exclude-hostname": - confRead.excludeHostname = true - case itemTrim == "explicit-priority": - confRead.explicitPriority = true - case balt.CutPrefixInString(&itemTrim, "facility-override "): - confRead.facilityOverride = itemTrim - case balt.CutPrefixInString(&itemTrim, "log-prefix "): - confRead.logPrefix = itemTrim - case balt.CutPrefixInString(&itemTrim, "match "): - confRead.match = strings.Trim(itemTrim, "\"") - case balt.CutPrefixInString(&itemTrim, "match-strings "): - confRead.matchStrings = append(confRead.matchStrings, strings.Trim(itemTrim, "\"")) - case balt.CutPrefixInString(&itemTrim, "port "): - confRead.port, err = strconv.Atoi(itemTrim) - if err != nil { - return confRead, fmt.Errorf(failedConvAtoiError, itemTrim, err) - } - case balt.CutPrefixInString(&itemTrim, "source-address "): - confRead.sourceAddress = itemTrim - case balt.CutPrefixInString(&itemTrim, "structured-data"): - if len(confRead.structuredData) == 0 { - confRead.structuredData = append(confRead.structuredData, map[string]interface{}{ - "brief": false, - }) - } - if itemTrim == " brief" { - confRead.structuredData[0]["brief"] = true - } - case balt.CutPrefixInString(&itemTrim, "any "): - confRead.anySeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "authorization "): - confRead.authorizationSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "change-log "): - confRead.changelogSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "conflict-log "): - confRead.conflictlogSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "daemon "): - confRead.daemonSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "dfc "): - confRead.dfcSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "external "): - confRead.externalSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "firewall "): - confRead.firewallSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "ftp "): - confRead.ftpSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "interactive-commands "): - confRead.interactivecommandsSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "kernel "): - confRead.kernelSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "ntp "): - confRead.ntpSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "pfe "): - confRead.pfeSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "security "): - confRead.securitySeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "user "): - confRead.userSeverity = itemTrim - } - } - } - - return confRead, nil -} - -func delSystemSyslogHost(host string, junSess *junos.Session) error { - configSet := make([]string, 0, 1) - configSet = append(configSet, "delete system syslog host "+host) - - return junSess.ConfigSet(configSet) -} - -func fillSystemSyslogHostData(d *schema.ResourceData, syslogHostOptions syslogHostOptions) { - if tfErr := d.Set("host", syslogHostOptions.host); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("allow_duplicates", syslogHostOptions.allowDuplicates); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("exclude_hostname", syslogHostOptions.excludeHostname); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("explicit_priority", syslogHostOptions.explicitPriority); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("facility_override", syslogHostOptions.facilityOverride); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("log_prefix", syslogHostOptions.logPrefix); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("match", syslogHostOptions.match); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("match_strings", syslogHostOptions.matchStrings); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("port", syslogHostOptions.port); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("source_address", syslogHostOptions.sourceAddress); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("structured_data", syslogHostOptions.structuredData); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("any_severity", syslogHostOptions.anySeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("authorization_severity", syslogHostOptions.authorizationSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("changelog_severity", syslogHostOptions.changelogSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("conflictlog_severity", syslogHostOptions.conflictlogSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("daemon_severity", syslogHostOptions.daemonSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("dfc_severity", syslogHostOptions.dfcSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("external_severity", syslogHostOptions.externalSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("firewall_severity", syslogHostOptions.firewallSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("ftp_severity", syslogHostOptions.ftpSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("interactivecommands_severity", syslogHostOptions.interactivecommandsSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("kernel_severity", syslogHostOptions.kernelSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("ntp_severity", syslogHostOptions.ntpSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("pfe_severity", syslogHostOptions.pfeSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("security_severity", syslogHostOptions.securitySeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("user_severity", syslogHostOptions.userSeverity); tfErr != nil { - panic(tfErr) - } -} From 9ad74337f2d903a66e4810fe104086b1b851291d Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Sat, 16 Dec 2023 18:54:51 +0100 Subject: [PATCH 39/43] r/system_syslog_file: use new provider via framework fix reading 'archive size' when value is a multiple of 1024 (k,m,g) --- .changes/issue-593.md | 9 + docs/resources/security.md | 2 +- docs/resources/system_syslog_file.md | 26 +- internal/providerfwk/provider.go | 1 + internal/providerfwk/resource_security.go | 2 +- .../resource_system_syslog_file.go | 956 ++++++++++++++++++ .../resource_system_syslog_file_test.go | 99 ++ .../1/main.tf | 26 + .../2/main.tf | 25 + .../3/main.tf | 33 + .../1/main.tf | 34 + .../1/provider.tf | 10 + .../2/main.tf | 1 + .../upgradestate_system_syslog_file.go | 247 +++++ .../upgradestate_system_syslog_file_test.go | 29 + internal/providersdk/func_common.go | 7 - internal/providersdk/provider.go | 1 - .../resource_security_log_stream.go | 2 +- .../resource_system_syslog_file.go | 780 -------------- .../resource_system_syslog_file_test.go | 213 ---- 20 files changed, 1486 insertions(+), 1017 deletions(-) create mode 100644 internal/providerfwk/resource_system_syslog_file.go create mode 100644 internal/providerfwk/resource_system_syslog_file_test.go create mode 100644 internal/providerfwk/testdata/TestAccResourceSystemSyslogFile_basic/1/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceSystemSyslogFile_basic/2/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceSystemSyslogFile_basic/3/main.tf create mode 100644 internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic/1/main.tf create mode 100644 internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic/1/provider.tf create mode 120000 internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic/2/main.tf create mode 100644 internal/providerfwk/upgradestate_system_syslog_file.go create mode 100644 internal/providerfwk/upgradestate_system_syslog_file_test.go delete mode 100644 internal/providersdk/resource_system_syslog_file.go delete mode 100644 internal/providersdk/resource_system_syslog_file_test.go diff --git a/.changes/issue-593.md b/.changes/issue-593.md index b14283f0..bfc38db9 100644 --- a/.changes/issue-593.md +++ b/.changes/issue-593.md @@ -3,7 +3,16 @@ FEATURES: ENHANCEMENTS: +* **resource/junos_system_syslog_file**: resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) + some of config errors are now sent during Plan instead of during Apply + optional boolean attributes doesn't accept value *false* + optional string attributes doesn't accept *empty* value + the resource schema has been upgraded to have one-blocks in single mode instead of list * **resource/junos_system_syslog_host**: resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) optional boolean attributes doesn't accept value *false* optional string attributes doesn't accept *empty* value the resource schema has been upgraded to have one-blocks in single mode instead of list + +BUG FIXES: + +* **resource/junos_system_syslog_file**: fix reading `archive size` when value is a multiple of 1024 (k,m,g) diff --git a/docs/resources/security.md b/docs/resources/security.md index e8be1dae..bbe46a82 100644 --- a/docs/resources/security.md +++ b/docs/resources/security.md @@ -302,7 +302,7 @@ The following arguments are supported: - **automatic_interval** (Optional, Number) Automatic interval (1..336 hours). - **automatic_start_time** (Optional, String) - Automatic start time `YYYY-MM-DD.HH:MM:SS`. + Automatic start time (YYYY-MM-DD.HH:MM:SS). - **install_ignore_version_check** (Optional, Boolean) Skip version check when attack database gets installed. - **proxy_profile** (Optional, String) diff --git a/docs/resources/system_syslog_file.md b/docs/resources/system_syslog_file.md index 63b7d6dd..a9c54bcc 100644 --- a/docs/resources/system_syslog_file.md +++ b/docs/resources/system_syslog_file.md @@ -78,20 +78,8 @@ The following arguments are supported: - **no_binary_data** (Optional, Boolean) Don't mark file as if it contains binary data. Conflict with `binary_data`. -- **world_readable** (Optional, Boolean) - Allow any user to read the log file. - Conflict with `no_world_readable`. -- **no_world_readable** (Optional, Boolean) - Don't allow any user to read the log file. - Conflict with `world_readable`. - **files** (Optional, Number) - Number of files to be archived (1..1000) -- **size** (Optional, Number) - Size of files to be archived (65536..1073741824 bytes) -- **start_time** (Optional, String) - Start time for file transmission (yyyy-mm-dd.hh:mm) -- **transfer_interval** (Optional, Number) - Frequency at which to transfer files to archive sites (5..2880 minutes) + Number of files to be archived (1..1000). - **sites** (Optional, Block List) For each url, configure an archive site (first declaration is primary URL, failover for others). - **url** (Required, String) @@ -100,6 +88,18 @@ The following arguments are supported: Password for login into the archive site. - **routing_instance** (Optional, String) Routing instance. +- **size** (Optional, Number) + Size of files to be archived (65536..1073741824 bytes). +- **start_time** (Optional, String) + Start time for file transmission (YYYY-MM-DD.HH:MM:SS). +- **transfer_interval** (Optional, Number) + Frequency at which to transfer files to archive sites (5..2880 minutes). +- **world_readable** (Optional, Boolean) + Allow any user to read the log file. + Conflict with `no_world_readable`. +- **no_world_readable** (Optional, Boolean) + Don't allow any user to read the log file. + Conflict with `world_readable`. **WARNING** All severities need to be `alert`, `any`, `critical`, `emergency`, `error`, `info`, `none`, `notice` or `warning`. diff --git a/internal/providerfwk/provider.go b/internal/providerfwk/provider.go index 4e6e88b5..7486db6e 100644 --- a/internal/providerfwk/provider.go +++ b/internal/providerfwk/provider.go @@ -279,6 +279,7 @@ func (p *junosProvider) Resources(_ context.Context) []func() resource.Resource newStaticRouteResource, newSwitchOptionsResource, newSystemResource, + newSystemSyslogFileResource, newSystemSyslogHostResource, } } diff --git a/internal/providerfwk/resource_security.go b/internal/providerfwk/resource_security.go index daa1c90c..4b2c71b4 100644 --- a/internal/providerfwk/resource_security.go +++ b/internal/providerfwk/resource_security.go @@ -629,7 +629,7 @@ func (rsc *security) Schema( }, "automatic_start_time": schema.StringAttribute{ Optional: true, - Description: "Automatic start time `YYYY-MM-DD.HH:MM:SS`.", + Description: "Automatic start time (YYYY-MM-DD.HH:MM:SS).", Validators: []validator.String{ stringvalidator.RegexMatches( regexp.MustCompile(`^\d{4}\-\d\d?\-\d\d?\.\d{2}:\d{2}:\d{2}$`), diff --git a/internal/providerfwk/resource_system_syslog_file.go b/internal/providerfwk/resource_system_syslog_file.go new file mode 100644 index 00000000..4634e7fc --- /dev/null +++ b/internal/providerfwk/resource_system_syslog_file.go @@ -0,0 +1,956 @@ +package providerfwk + +import ( + "context" + "fmt" + "regexp" + "strings" + + "github.com/jeremmfr/terraform-provider-junos/internal/junos" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdata" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdiag" + "github.com/jeremmfr/terraform-provider-junos/internal/tfplanmodifier" + "github.com/jeremmfr/terraform-provider-junos/internal/tfvalidator" + "github.com/jeremmfr/terraform-provider-junos/internal/utils" + + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + balt "github.com/jeremmfr/go-utils/basicalter" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ resource.Resource = &systemSyslogFile{} + _ resource.ResourceWithConfigure = &systemSyslogFile{} + _ resource.ResourceWithValidateConfig = &systemSyslogFile{} + _ resource.ResourceWithImportState = &systemSyslogFile{} + _ resource.ResourceWithUpgradeState = &systemSyslogFile{} +) + +type systemSyslogFile struct { + client *junos.Client +} + +func newSystemSyslogFileResource() resource.Resource { + return &systemSyslogFile{} +} + +func (rsc *systemSyslogFile) typeName() string { + return providerName + "_system_syslog_file" +} + +func (rsc *systemSyslogFile) junosName() string { + return "system syslog file" +} + +func (rsc *systemSyslogFile) junosClient() *junos.Client { + return rsc.client +} + +func (rsc *systemSyslogFile) Metadata( + _ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse, +) { + resp.TypeName = rsc.typeName() +} + +func (rsc *systemSyslogFile) Configure( + ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse, +) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + client, ok := req.ProviderData.(*junos.Client) + if !ok { + unexpectedResourceConfigureType(ctx, req, resp) + + return + } + rsc.client = client +} + +func (rsc *systemSyslogFile) Schema( + _ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse, +) { + resp.Schema = schema.Schema{ + Version: 1, + Description: defaultResourceSchemaDescription(rsc), + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "An identifier for the resource with format ``.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "filename": schema.StringAttribute{ + Required: true, + Description: "Name of file in which to log data.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 250), + tfvalidator.StringDoubleQuoteExclusion(), + tfvalidator.StringSpaceExclusion(), + tfvalidator.StringRuneExclusion('/', '%'), + }, + }, + "allow_duplicates": schema.BoolAttribute{ + Optional: true, + Description: "Do not suppress the repeated message.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "explicit_priority": schema.BoolAttribute{ + Optional: true, + Description: "Include priority and facility in messages.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "match": schema.StringAttribute{ + Optional: true, + Description: "Regular expression for lines to be logged.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + tfvalidator.StringDoubleQuoteExclusion(), + }, + }, + "match_strings": schema.ListAttribute{ + ElementType: types.StringType, + Optional: true, + Description: "Matching string(s) for lines to be logged.", + Validators: []validator.List{ + listvalidator.SizeAtLeast(1), + listvalidator.ValueStringsAre( + stringvalidator.LengthAtLeast(1), + tfvalidator.StringDoubleQuoteExclusion(), + ), + }, + }, + "any_severity": schema.StringAttribute{ + Optional: true, + Description: "All facilities sseverity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "authorization_severity": schema.StringAttribute{ + Optional: true, + Description: "Authorization system severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "changelog_severity": schema.StringAttribute{ + Optional: true, + Description: "Configuration change log severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "conflictlog_severity": schema.StringAttribute{ + Optional: true, + Description: "Configuration conflict log severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "daemon_severity": schema.StringAttribute{ + Optional: true, + Description: "Various system processes severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "dfc_severity": schema.StringAttribute{ + Optional: true, + Description: "Dynamic flow capture severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "external_severity": schema.StringAttribute{ + Optional: true, + Description: "Local external applications severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "firewall_severity": schema.StringAttribute{ + Optional: true, + Description: "Firewall filtering system severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "ftp_severity": schema.StringAttribute{ + Optional: true, + Description: "FTP process severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "interactivecommands_severity": schema.StringAttribute{ + Optional: true, + Description: "Commands executed by the UI severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "kernel_severity": schema.StringAttribute{ + Optional: true, + Description: "Kernel severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "ntp_severity": schema.StringAttribute{ + Optional: true, + Description: "NTP process severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "pfe_severity": schema.StringAttribute{ + Optional: true, + Description: "Packet Forwarding Engine severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "security_severity": schema.StringAttribute{ + Optional: true, + Description: "Security related severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "user_severity": schema.StringAttribute{ + Optional: true, + Description: "User processes severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + }, + Blocks: map[string]schema.Block{ + "archive": schema.SingleNestedBlock{ + Description: "Define parameters for archiving log messages.", + Attributes: map[string]schema.Attribute{ + "binary_data": schema.BoolAttribute{ + Optional: true, + Description: "Mark file as if it contains binary data.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "no_binary_data": schema.BoolAttribute{ + Optional: true, + Description: "Don't mark file as if it contains binary data.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "files": schema.Int64Attribute{ + Optional: true, + Description: "Number of files to be archived.", + Validators: []validator.Int64{ + int64validator.Between(1, 1000), + }, + }, + "size": schema.Int64Attribute{ + Optional: true, + Description: "Size of files to be archived (bytes).", + Validators: []validator.Int64{ + int64validator.Between(65536, 1073741824), + }, + }, + "start_time": schema.StringAttribute{ + Optional: true, + Description: "Start time for file transmission (YYYY-MM-DD.HH:MM:SS).", + Validators: []validator.String{ + stringvalidator.RegexMatches( + regexp.MustCompile(`^\d{4}\-\d\d?\-\d\d?\.\d{2}:\d{2}:\d{2}$`), + "must be in the format 'YYYY-MM-DD.HH:MM:SS'", + ), + }, + }, + "transfer_interval": schema.Int64Attribute{ + Optional: true, + Description: "Frequency at which to transfer files to archive sites (minutes).", + Validators: []validator.Int64{ + int64validator.Between(5, 2880), + }, + }, + "world_readable": schema.BoolAttribute{ + Optional: true, + Description: "Allow any user to read the log file.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "no_world_readable": schema.BoolAttribute{ + Optional: true, + Description: "Don't allow any user to read the log file.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + }, + Blocks: map[string]schema.Block{ + "sites": schema.ListNestedBlock{ + Description: "For each url, configure an archive site.", + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "url": schema.StringAttribute{ + Required: true, + Description: "Primary or failover URLs to receive archive files.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + tfvalidator.StringDoubleQuoteExclusion(), + }, + }, + "password": schema.StringAttribute{ + Optional: true, + Sensitive: true, + Description: "Password for login into the archive site.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + tfvalidator.StringDoubleQuoteExclusion(), + }, + }, + "routing_instance": schema.StringAttribute{ + Optional: true, + Description: "Routing instance.", + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 63), + tfvalidator.StringFormat(tfvalidator.DefaultFormat), + }, + }, + }, + }, + }, + }, + PlanModifiers: []planmodifier.Object{ + tfplanmodifier.BlockRemoveNull(), + }, + }, + "structured_data": schema.SingleNestedBlock{ + Description: "Log system message in structured format.", + Attributes: map[string]schema.Attribute{ + "brief": schema.BoolAttribute{ + Optional: true, + Description: "Omit English-language text from end of logged message.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + }, + PlanModifiers: []planmodifier.Object{ + tfplanmodifier.BlockRemoveNull(), + }, + }, + }, + } +} + +type systemSyslogFileData struct { + AllowDuplicates types.Bool `tfsdk:"allow_duplicates"` + ExplicitPriority types.Bool `tfsdk:"explicit_priority"` + ID types.String `tfsdk:"id"` + Filename types.String `tfsdk:"filename"` + Match types.String `tfsdk:"match"` + MatchStrings []types.String `tfsdk:"match_strings"` + AnySeverity types.String `tfsdk:"any_severity"` + AuthorizationSeverity types.String `tfsdk:"authorization_severity"` + ChangelogSeverity types.String `tfsdk:"changelog_severity"` + ConflictlogSeverity types.String `tfsdk:"conflictlog_severity"` + DaemonSeverity types.String `tfsdk:"daemon_severity"` + DfcSeverity types.String `tfsdk:"dfc_severity"` + ExternalSeverity types.String `tfsdk:"external_severity"` + FirewallSeverity types.String `tfsdk:"firewall_severity"` + FtpSeverity types.String `tfsdk:"ftp_severity"` + InteractivecommandsSeverity types.String `tfsdk:"interactivecommands_severity"` + KernelSeverity types.String `tfsdk:"kernel_severity"` + NtpSeverity types.String `tfsdk:"ntp_severity"` + PfeSeverity types.String `tfsdk:"pfe_severity"` + SecuritySeverity types.String `tfsdk:"security_severity"` + UserSeverity types.String `tfsdk:"user_severity"` + Archive *systemSyslogFileBlockArchive `tfsdk:"archive"` + StructuredData *systemSyslogFileBlockStructuredData `tfsdk:"structured_data"` +} + +type systemSyslogFileConfig struct { + AllowDuplicates types.Bool `tfsdk:"allow_duplicates"` + ExplicitPriority types.Bool `tfsdk:"explicit_priority"` + ID types.String `tfsdk:"id"` + Filename types.String `tfsdk:"filename"` + Match types.String `tfsdk:"match"` + MatchStrings types.List `tfsdk:"match_strings"` + AnySeverity types.String `tfsdk:"any_severity"` + AuthorizationSeverity types.String `tfsdk:"authorization_severity"` + ChangelogSeverity types.String `tfsdk:"changelog_severity"` + ConflictlogSeverity types.String `tfsdk:"conflictlog_severity"` + DaemonSeverity types.String `tfsdk:"daemon_severity"` + DfcSeverity types.String `tfsdk:"dfc_severity"` + ExternalSeverity types.String `tfsdk:"external_severity"` + FirewallSeverity types.String `tfsdk:"firewall_severity"` + FtpSeverity types.String `tfsdk:"ftp_severity"` + InteractivecommandsSeverity types.String `tfsdk:"interactivecommands_severity"` + KernelSeverity types.String `tfsdk:"kernel_severity"` + NtpSeverity types.String `tfsdk:"ntp_severity"` + PfeSeverity types.String `tfsdk:"pfe_severity"` + SecuritySeverity types.String `tfsdk:"security_severity"` + UserSeverity types.String `tfsdk:"user_severity"` + Archive *systemSyslogFileBlockArchiveConfig `tfsdk:"archive"` + StructuredData *systemSyslogFileBlockStructuredData `tfsdk:"structured_data"` +} + +type systemSyslogFileBlockArchive struct { + BinaryData types.Bool `tfsdk:"binary_data"` + NoBinaryData types.Bool `tfsdk:"no_binary_data"` + WorldReadable types.Bool `tfsdk:"world_readable"` + NoWorldReadable types.Bool `tfsdk:"no_world_readable"` + Files types.Int64 `tfsdk:"files"` + Size types.Int64 `tfsdk:"size"` + StartTime types.String `tfsdk:"start_time"` + TransferInterval types.Int64 `tfsdk:"transfer_interval"` + Sites []systemSyslogFileBlockArchiveBlockSites `tfsdk:"sites"` +} + +type systemSyslogFileBlockArchiveConfig struct { + BinaryData types.Bool `tfsdk:"binary_data"` + NoBinaryData types.Bool `tfsdk:"no_binary_data"` + WorldReadable types.Bool `tfsdk:"world_readable"` + NoWorldReadable types.Bool `tfsdk:"no_world_readable"` + Files types.Int64 `tfsdk:"files"` + Size types.Int64 `tfsdk:"size"` + StartTime types.String `tfsdk:"start_time"` + TransferInterval types.Int64 `tfsdk:"transfer_interval"` + Sites types.List `tfsdk:"sites"` +} + +type systemSyslogFileBlockArchiveBlockSites struct { + URL types.String `tfsdk:"url"` + Password types.String `tfsdk:"password"` + RoutingInstance types.String `tfsdk:"routing_instance"` +} + +type systemSyslogFileBlockStructuredData struct { + Brief types.Bool `tfsdk:"brief"` +} + +func (rsc *systemSyslogFile) ValidateConfig( + ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse, +) { + var config systemSyslogFileConfig + resp.Diagnostics.Append(req.Config.Get(ctx, &config)...) + if resp.Diagnostics.HasError() { + return + } + + if config.Archive != nil { + if !config.Archive.BinaryData.IsNull() && + !config.Archive.NoBinaryData.IsNull() { + resp.Diagnostics.AddAttributeError( + path.Root("archive").AtName("binary_data"), + tfdiag.ConflictConfigErrSummary, + "binary_data and no_binary_data cannot be configured together"+ + " in archive block", + ) + } + if !config.Archive.WorldReadable.IsNull() && + !config.Archive.NoWorldReadable.IsNull() { + resp.Diagnostics.AddAttributeError( + path.Root("archive").AtName("world_readable"), + tfdiag.ConflictConfigErrSummary, + "world_readable and no_world_readable cannot be configured together"+ + " in archive block", + ) + } + if config.Archive.Sites.IsNull() { + if !config.Archive.StartTime.IsNull() { + resp.Diagnostics.AddAttributeError( + path.Root("archive").AtName("start_time"), + tfdiag.MissingConfigErrSummary, + "sites must be specified with start_time in archive block", + ) + } + if !config.Archive.TransferInterval.IsNull() { + resp.Diagnostics.AddAttributeError( + path.Root("archive").AtName("transfer_interval"), + tfdiag.MissingConfigErrSummary, + "sites must be specified with transfer_interval in archive block", + ) + } + } else if !config.Archive.Sites.IsUnknown() { + var configSites []systemSyslogFileBlockArchiveBlockSites + asDiags := config.Archive.Sites.ElementsAs(ctx, &configSites, false) + if asDiags.HasError() { + resp.Diagnostics.Append(asDiags...) + + return + } + + sitesURL := make(map[string]struct{}) + for i, blockSites := range configSites { + if blockSites.URL.IsUnknown() { + continue + } + url := blockSites.URL.ValueString() + if _, ok := sitesURL[url]; ok { + resp.Diagnostics.AddAttributeError( + path.Root("archive").AtName("sites").AtListIndex(i).AtName("url"), + tfdiag.DuplicateConfigErrSummary, + fmt.Sprintf("multiple sites blocks with the same url %q in archive block", url), + ) + } else { + sitesURL[url] = struct{}{} + } + } + } + } +} + +func (rsc *systemSyslogFile) Create( + ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse, +) { + var plan systemSyslogFileData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + if plan.Filename.ValueString() == "" { + resp.Diagnostics.AddAttributeError( + path.Root("filename"), + "Empty Filename", + defaultResourceCouldNotCreateWithEmptyMessage(rsc, "filename"), + ) + + return + } + + defaultResourceCreate( + ctx, + rsc, + func(fnCtx context.Context, junSess *junos.Session) bool { + fileExists, err := checkSystemSyslogFileExists(fnCtx, plan.Filename.ValueString(), junSess) + if err != nil { + resp.Diagnostics.AddError(tfdiag.PreCheckErrSummary, err.Error()) + + return false + } + if fileExists { + resp.Diagnostics.AddError( + tfdiag.DuplicateConfigErrSummary, + defaultResourceAlreadyExistsMessage(rsc, plan.Filename), + ) + + return false + } + + return true + }, + func(fnCtx context.Context, junSess *junos.Session) bool { + fileExists, err := checkSystemSyslogFileExists(fnCtx, plan.Filename.ValueString(), junSess) + if err != nil { + resp.Diagnostics.AddError(tfdiag.PostCheckErrSummary, err.Error()) + + return false + } + if !fileExists { + resp.Diagnostics.AddError( + tfdiag.NotFoundErrSummary, + defaultResourceDoesNotExistsAfterCommitMessage(rsc, plan.Filename), + ) + + return false + } + + return true + }, + &plan, + resp, + ) +} + +func (rsc *systemSyslogFile) Read( + ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse, +) { + var state, data systemSyslogFileData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + var _ resourceDataReadFrom1String = &data + defaultResourceRead( + ctx, + rsc, + []string{ + state.Filename.ValueString(), + }, + &data, + nil, + resp, + ) +} + +func (rsc *systemSyslogFile) Update( + ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse, +) { + var plan, state systemSyslogFileData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceUpdate( + ctx, + rsc, + &state, + &plan, + resp, + ) +} + +func (rsc *systemSyslogFile) Delete( + ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse, +) { + var state systemSyslogFileData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceDelete( + ctx, + rsc, + &state, + resp, + ) +} + +func (rsc *systemSyslogFile) ImportState( + ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse, +) { + var data systemSyslogFileData + + var _ resourceDataReadFrom1String = &data + defaultResourceImportState( + ctx, + rsc, + &data, + req, + resp, + defaultResourceImportDontFindIDStrMessage(rsc, req.ID, "filename"), + ) +} + +func checkSystemSyslogFileExists( + _ context.Context, filename string, junSess *junos.Session, +) ( + bool, error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "system syslog file \"" + filename + "\"" + junos.PipeDisplaySet) + if err != nil { + return false, err + } + if showConfig == junos.EmptyW { + return false, nil + } + + return true, nil +} + +func (rscData *systemSyslogFileData) fillID() { + rscData.ID = types.StringValue(rscData.Filename.ValueString()) +} + +func (rscData *systemSyslogFileData) nullID() bool { + return rscData.ID.IsNull() +} + +func (rscData *systemSyslogFileData) set( + _ context.Context, junSess *junos.Session, +) ( + path.Path, error, +) { + configSet := make([]string, 0) + setPrefix := "set system syslog file \"" + rscData.Filename.ValueString() + "\" " + + if rscData.AllowDuplicates.ValueBool() { + configSet = append(configSet, setPrefix+"allow-duplicates") + } + if rscData.ExplicitPriority.ValueBool() { + configSet = append(configSet, setPrefix+"explicit-priority") + } + if v := rscData.Match.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"match \""+v+"\"") + } + for _, v := range rscData.MatchStrings { + configSet = append(configSet, setPrefix+"match-strings \""+v.ValueString()+"\"") + } + if v := rscData.AnySeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"any "+v) + } + if v := rscData.AuthorizationSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"authorization "+v) + } + if v := rscData.ChangelogSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"change-log "+v) + } + if v := rscData.ConflictlogSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"conflict-log "+v) + } + if v := rscData.DaemonSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"daemon "+v) + } + if v := rscData.DfcSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"dfc "+v) + } + if v := rscData.ExternalSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"external "+v) + } + if v := rscData.FirewallSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"firewall "+v) + } + if v := rscData.FtpSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"ftp "+v) + } + if v := rscData.InteractivecommandsSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"interactive-commands "+v) + } + if v := rscData.KernelSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"kernel "+v) + } + if v := rscData.NtpSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"ntp "+v) + } + if v := rscData.PfeSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"pfe "+v) + } + if v := rscData.SecuritySeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"security "+v) + } + if v := rscData.UserSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"user "+v) + } + if rscData.Archive != nil { + configSet = append(configSet, setPrefix+"archive") + + if rscData.Archive.BinaryData.ValueBool() { + configSet = append(configSet, setPrefix+"archive binary-data") + } + if rscData.Archive.NoBinaryData.ValueBool() { + configSet = append(configSet, setPrefix+"archive no-binary-data") + } + if !rscData.Archive.Files.IsNull() { + configSet = append(configSet, setPrefix+"archive files "+ + utils.ConvI64toa(rscData.Archive.Files.ValueInt64())) + } + if !rscData.Archive.Size.IsNull() { + configSet = append(configSet, setPrefix+"archive size "+ + utils.ConvI64toa(rscData.Archive.Size.ValueInt64())) + } + if v := rscData.Archive.StartTime.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"archive start-time "+v) + } + if !rscData.Archive.TransferInterval.IsNull() { + configSet = append(configSet, setPrefix+"archive transfer-interval "+ + utils.ConvI64toa(rscData.Archive.TransferInterval.ValueInt64())) + } + if rscData.Archive.WorldReadable.ValueBool() { + configSet = append(configSet, setPrefix+"archive world-readable") + } + if rscData.Archive.NoWorldReadable.ValueBool() { + configSet = append(configSet, setPrefix+"archive no-world-readable") + } + sitesURL := make(map[string]struct{}) + for i, blockSites := range rscData.Archive.Sites { + url := blockSites.URL.ValueString() + if _, ok := sitesURL[url]; ok { + return path.Root("archive").AtName("sites").AtListIndex(i).AtName("url"), + fmt.Errorf("multiple sites blocks with the same url %q in archive block", + url) + } + sitesURL[url] = struct{}{} + + setPrefixArchiveSites := setPrefix + "archive archive-sites \"" + url + "\"" + configSet = append(configSet, setPrefixArchiveSites) + if v := blockSites.Password.ValueString(); v != "" { + configSet = append(configSet, setPrefixArchiveSites+" password \""+v+"\"") + } + if v := blockSites.RoutingInstance.ValueString(); v != "" { + configSet = append(configSet, setPrefixArchiveSites+" routing-instance "+v) + } + } + } + if rscData.StructuredData != nil { + configSet = append(configSet, setPrefix+"structured-data") + if rscData.StructuredData.Brief.ValueBool() { + configSet = append(configSet, setPrefix+"structured-data brief") + } + } + + return path.Empty(), junSess.ConfigSet(configSet) +} + +func (rscData *systemSyslogFileData) read( + _ context.Context, filename string, junSess *junos.Session, +) ( + err error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "system syslog file \"" + filename + "\"" + junos.PipeDisplaySetRelative) + if err != nil { + return err + } + if showConfig != junos.EmptyW { + rscData.Filename = types.StringValue(filename) + rscData.fillID() + for _, item := range strings.Split(showConfig, "\n") { + if strings.Contains(item, junos.XMLStartTagConfigOut) { + continue + } + if strings.Contains(item, junos.XMLEndTagConfigOut) { + break + } + itemTrim := strings.TrimPrefix(item, junos.SetLS) + switch { + case itemTrim == "allow-duplicates": + rscData.AllowDuplicates = types.BoolValue(true) + case itemTrim == "explicit-priority": + rscData.ExplicitPriority = types.BoolValue(true) + case balt.CutPrefixInString(&itemTrim, "match "): + rscData.Match = types.StringValue(strings.Trim(itemTrim, "\"")) + case balt.CutPrefixInString(&itemTrim, "match-strings "): + rscData.MatchStrings = append(rscData.MatchStrings, + types.StringValue(strings.Trim(itemTrim, "\""))) + case balt.CutPrefixInString(&itemTrim, "any "): + rscData.AnySeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "authorization "): + rscData.AuthorizationSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "change-log "): + rscData.ChangelogSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "conflict-log "): + rscData.ConflictlogSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "daemon "): + rscData.DaemonSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "dfc "): + rscData.DfcSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "external "): + rscData.ExternalSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "firewall "): + rscData.FirewallSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "ftp "): + rscData.FtpSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "interactive-commands "): + rscData.InteractivecommandsSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "kernel "): + rscData.KernelSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "ntp "): + rscData.NtpSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "pfe "): + rscData.PfeSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "security "): + rscData.SecuritySeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "user "): + rscData.UserSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "archive"): + if rscData.Archive == nil { + rscData.Archive = &systemSyslogFileBlockArchive{} + } + switch { + case itemTrim == " binary-data": + rscData.Archive.BinaryData = types.BoolValue(true) + case itemTrim == " no-binary-data": + rscData.Archive.NoBinaryData = types.BoolValue(true) + case balt.CutPrefixInString(&itemTrim, " files "): + rscData.Archive.Files, err = tfdata.ConvAtoi64Value(itemTrim) + if err != nil { + return err + } + case balt.CutPrefixInString(&itemTrim, " size "): + switch { + case balt.CutSuffixInString(&itemTrim, "k"): + rscData.Archive.Size, err = tfdata.ConvAtoi64Value(itemTrim) + rscData.Archive.Size = types.Int64Value(rscData.Archive.Size.ValueInt64() * 1024) + case balt.CutSuffixInString(&itemTrim, "m"): + rscData.Archive.Size, err = tfdata.ConvAtoi64Value(itemTrim) + rscData.Archive.Size = types.Int64Value(rscData.Archive.Size.ValueInt64() * 1024 * 1024) + case balt.CutSuffixInString(&itemTrim, "g"): + rscData.Archive.Size, err = tfdata.ConvAtoi64Value(itemTrim) + rscData.Archive.Size = types.Int64Value(rscData.Archive.Size.ValueInt64() * 1024 * 1024 * 1024) + default: + rscData.Archive.Size, err = tfdata.ConvAtoi64Value(itemTrim) + } + if err != nil { + return err + } + case balt.CutPrefixInString(&itemTrim, " transfer-interval "): + rscData.Archive.TransferInterval, err = tfdata.ConvAtoi64Value(itemTrim) + if err != nil { + return err + } + case balt.CutPrefixInString(&itemTrim, " start-time "): + rscData.Archive.StartTime = types.StringValue(strings.Split(strings.Trim(itemTrim, "\""), " ")[0]) + case itemTrim == " world-readable": + rscData.Archive.WorldReadable = types.BoolValue(true) + case itemTrim == " no-world-readable": + rscData.Archive.NoWorldReadable = types.BoolValue(true) + case balt.CutPrefixInString(&itemTrim, " archive-sites "): + url := tfdata.FirstElementOfJunosLine(itemTrim) + var sites systemSyslogFileBlockArchiveBlockSites + rscData.Archive.Sites, sites = tfdata.ExtractBlockWithTFTypesString( + rscData.Archive.Sites, "URL", strings.Trim(url, "\""), + ) + sites.URL = types.StringValue(strings.Trim(url, "\"")) + balt.CutPrefixInString(&itemTrim, url+" ") + switch { + case balt.CutPrefixInString(&itemTrim, "password "): + sites.Password, err = tfdata.JunosDecode(strings.Trim(itemTrim, "\""), "password") + if err != nil { + return err + } + case balt.CutPrefixInString(&itemTrim, "routing-instance "): + sites.RoutingInstance = types.StringValue(itemTrim) + } + rscData.Archive.Sites = append(rscData.Archive.Sites, sites) + } + case balt.CutPrefixInString(&itemTrim, "structured-data"): + if rscData.StructuredData == nil { + rscData.StructuredData = &systemSyslogFileBlockStructuredData{} + } + if itemTrim == " brief" { + rscData.StructuredData.Brief = types.BoolValue(true) + } + } + } + } + + return nil +} + +func (rscData *systemSyslogFileData) del( + _ context.Context, junSess *junos.Session, +) error { + configSet := []string{ + "delete system syslog file \"" + rscData.Filename.ValueString() + "\"", + } + + return junSess.ConfigSet(configSet) +} diff --git a/internal/providerfwk/resource_system_syslog_file_test.go b/internal/providerfwk/resource_system_syslog_file_test.go new file mode 100644 index 00000000..9fc56d1e --- /dev/null +++ b/internal/providerfwk/resource_system_syslog_file_test.go @@ -0,0 +1,99 @@ +package providerfwk_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccResourceSystemSyslogFile_basic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestStepDirectory(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "filename", "testacc"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "allow_duplicates", "true"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "explicit_priority", "true"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "match", "match testacc"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "match_strings.#", "1"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "match_strings.0", "match testacc"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "any_severity", "emergency"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "changelog_severity", "critical"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "conflictlog_severity", "error"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "daemon_severity", "warning"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "dfc_severity", "alert"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "external_severity", "any"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "firewall_severity", "info"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "ftp_severity", "none"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "interactivecommands_severity", "notice"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "kernel_severity", "emergency"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "ntp_severity", "emergency"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "pfe_severity", "emergency"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "security_severity", "emergency"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "user_severity", "emergency"), + ), + }, + { + ConfigDirectory: config.TestStepDirectory(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("junos_system_syslog_file.testacc_syslogFile", + "structured_data.%"), + resource.TestCheckResourceAttrSet("junos_system_syslog_file.testacc_syslogFile", + "archive.%"), + ), + }, + { + ConfigDirectory: config.TestStepDirectory(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "structured_data.brief", "true"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "archive.binary_data", "true"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "archive.world_readable", "true"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "archive.size", "1073741823"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "archive.files", "5"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "archive.transfer_interval", "5"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "archive.sites.#", "1"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "archive.sites.0.url", "192.0.2.1"), + resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", + "archive.sites.0.password", "password"), + ), + }, + { + ResourceName: "junos_system_syslog_file.testacc_syslogFile", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/internal/providerfwk/testdata/TestAccResourceSystemSyslogFile_basic/1/main.tf b/internal/providerfwk/testdata/TestAccResourceSystemSyslogFile_basic/1/main.tf new file mode 100644 index 00000000..ae141714 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSystemSyslogFile_basic/1/main.tf @@ -0,0 +1,26 @@ +resource "junos_system_syslog_file" "testacc_syslogFile" { + filename = "testacc" + allow_duplicates = true + explicit_priority = true + match = "match testacc" + match_strings = ["match testacc"] + any_severity = "emergency" + changelog_severity = "critical" + conflictlog_severity = "error" + daemon_severity = "warning" + dfc_severity = "alert" + external_severity = "any" + firewall_severity = "info" + ftp_severity = "none" + interactivecommands_severity = "notice" + kernel_severity = "emergency" + ntp_severity = "emergency" + pfe_severity = "emergency" + security_severity = "emergency" + user_severity = "emergency" +} + +resource "junos_system_syslog_file" "testacc_syslogFile2" { + filename = "test_acc.2" + any_severity = "emergency" +} diff --git a/internal/providerfwk/testdata/TestAccResourceSystemSyslogFile_basic/2/main.tf b/internal/providerfwk/testdata/TestAccResourceSystemSyslogFile_basic/2/main.tf new file mode 100644 index 00000000..b7e0bb71 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSystemSyslogFile_basic/2/main.tf @@ -0,0 +1,25 @@ +resource "junos_system_syslog_file" "testacc_syslogFile" { + filename = "testacc" + allow_duplicates = true + match = "match testacc" + any_severity = "emergency" + changelog_severity = "critical" + conflictlog_severity = "error" + daemon_severity = "warning" + dfc_severity = "alert" + external_severity = "any" + firewall_severity = "info" + ftp_severity = "none" + interactivecommands_severity = "notice" + kernel_severity = "error" + ntp_severity = "error" + pfe_severity = "error" + security_severity = "error" + user_severity = "error" + structured_data {} + archive {} +} +resource "junos_system_syslog_file" "testacc_syslogFile2" { + filename = "test_acc.2" + explicit_priority = true +} diff --git a/internal/providerfwk/testdata/TestAccResourceSystemSyslogFile_basic/3/main.tf b/internal/providerfwk/testdata/TestAccResourceSystemSyslogFile_basic/3/main.tf new file mode 100644 index 00000000..fde72ae4 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSystemSyslogFile_basic/3/main.tf @@ -0,0 +1,33 @@ +resource "junos_system_syslog_file" "testacc_syslogFile" { + filename = "testacc" + allow_duplicates = true + match = "match testacc" + any_severity = "emergency" + changelog_severity = "critical" + conflictlog_severity = "error" + daemon_severity = "warning" + dfc_severity = "alert" + external_severity = "any" + firewall_severity = "info" + ftp_severity = "none" + interactivecommands_severity = "notice" + kernel_severity = "error" + ntp_severity = "error" + pfe_severity = "error" + security_severity = "error" + user_severity = "error" + structured_data { + brief = true + } + archive { + binary_data = true + world_readable = true + size = 1073741823 + files = 5 + transfer_interval = 5 + sites { + url = "192.0.2.1" + password = "password" + } + } +} diff --git a/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic/1/main.tf b/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic/1/main.tf new file mode 100644 index 00000000..3e85e03e --- /dev/null +++ b/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic/1/main.tf @@ -0,0 +1,34 @@ + +resource "junos_system_syslog_file" "testacc_syslogFile" { + filename = "testacc_syslogFile" + allow_duplicates = true + match = "match testacc" + any_severity = "emergency" + changelog_severity = "critical" + conflictlog_severity = "error" + daemon_severity = "warning" + dfc_severity = "alert" + external_severity = "any" + firewall_severity = "info" + ftp_severity = "none" + interactivecommands_severity = "notice" + kernel_severity = "error" + ntp_severity = "error" + pfe_severity = "error" + security_severity = "error" + user_severity = "error" + structured_data { + brief = true + } + archive { + binary_data = true + world_readable = true + size = 1073741823 + files = 5 + transfer_interval = 5 + sites { + url = "example.com" + password = "password" + } + } +} diff --git a/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic/1/provider.tf b/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic/1/provider.tf new file mode 100644 index 00000000..713fa309 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic/1/provider.tf @@ -0,0 +1,10 @@ +terraform { + required_providers { + junos = { + source = "registry.terraform.io/jeremmfr/junos" + version = "1.33.0" + } + } +} + +provider "junos" {} diff --git a/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic/2/main.tf b/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic/2/main.tf new file mode 120000 index 00000000..7a6c4026 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic/2/main.tf @@ -0,0 +1 @@ +../1/main.tf \ No newline at end of file diff --git a/internal/providerfwk/upgradestate_system_syslog_file.go b/internal/providerfwk/upgradestate_system_syslog_file.go new file mode 100644 index 00000000..85e8d3ba --- /dev/null +++ b/internal/providerfwk/upgradestate_system_syslog_file.go @@ -0,0 +1,247 @@ +package providerfwk + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func (rsc *systemSyslogFile) UpgradeState(_ context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ + 0: { + PriorSchema: &schema.Schema{ + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + }, + "filename": schema.StringAttribute{ + Required: true, + }, + "allow_duplicates": schema.BoolAttribute{ + Optional: true, + }, + "explicit_priority": schema.BoolAttribute{ + Optional: true, + }, + "match": schema.StringAttribute{ + Optional: true, + }, + "match_strings": schema.ListAttribute{ + ElementType: types.StringType, + Optional: true, + }, + "any_severity": schema.StringAttribute{ + Optional: true, + }, + "authorization_severity": schema.StringAttribute{ + Optional: true, + }, + "changelog_severity": schema.StringAttribute{ + Optional: true, + }, + "conflictlog_severity": schema.StringAttribute{ + Optional: true, + }, + "daemon_severity": schema.StringAttribute{ + Optional: true, + }, + "dfc_severity": schema.StringAttribute{ + Optional: true, + }, + "external_severity": schema.StringAttribute{ + Optional: true, + }, + "firewall_severity": schema.StringAttribute{ + Optional: true, + }, + "ftp_severity": schema.StringAttribute{ + Optional: true, + }, + "interactivecommands_severity": schema.StringAttribute{ + Optional: true, + }, + "kernel_severity": schema.StringAttribute{ + Optional: true, + }, + "ntp_severity": schema.StringAttribute{ + Optional: true, + }, + "pfe_severity": schema.StringAttribute{ + Optional: true, + }, + "security_severity": schema.StringAttribute{ + Optional: true, + }, + "user_severity": schema.StringAttribute{ + Optional: true, + }, + }, + Blocks: map[string]schema.Block{ + "archive": schema.ListNestedBlock{ + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "binary_data": schema.BoolAttribute{ + Optional: true, + }, + "no_binary_data": schema.BoolAttribute{ + Optional: true, + }, + "files": schema.Int64Attribute{ + Optional: true, + }, + "size": schema.Int64Attribute{ + Optional: true, + }, + "start_time": schema.StringAttribute{ + Optional: true, + }, + "transfer_interval": schema.Int64Attribute{ + Optional: true, + }, + "world_readable": schema.BoolAttribute{ + Optional: true, + }, + "no_world_readable": schema.BoolAttribute{ + Optional: true, + }, + }, + Blocks: map[string]schema.Block{ + "sites": schema.ListNestedBlock{ + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "url": schema.StringAttribute{ + Required: true, + }, + "password": schema.StringAttribute{ + Optional: true, + Sensitive: true, + }, + "routing_instance": schema.StringAttribute{ + Optional: true, + }, + }, + }, + }, + }, + }, + }, + "structured_data": schema.ListNestedBlock{ + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "brief": schema.BoolAttribute{ + Optional: true, + }, + }, + }, + }, + }, + }, + StateUpgrader: upgradeSystemSyslogFileV0toV1, + }, + } +} + +func upgradeSystemSyslogFileV0toV1( + ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse, +) { + type modelV0 struct { + AllowDuplicates types.Bool `tfsdk:"allow_duplicates"` + ExplicitPriority types.Bool `tfsdk:"explicit_priority"` + ID types.String `tfsdk:"id"` + Filename types.String `tfsdk:"filename"` + Match types.String `tfsdk:"match"` + MatchStrings []types.String `tfsdk:"match_strings"` + AnySeverity types.String `tfsdk:"any_severity"` + AuthorizationSeverity types.String `tfsdk:"authorization_severity"` + ChangelogSeverity types.String `tfsdk:"changelog_severity"` + ConflictlogSeverity types.String `tfsdk:"conflictlog_severity"` + DaemonSeverity types.String `tfsdk:"daemon_severity"` + DfcSeverity types.String `tfsdk:"dfc_severity"` + ExternalSeverity types.String `tfsdk:"external_severity"` + FirewallSeverity types.String `tfsdk:"firewall_severity"` + FtpSeverity types.String `tfsdk:"ftp_severity"` + InteractivecommandsSeverity types.String `tfsdk:"interactivecommands_severity"` + KernelSeverity types.String `tfsdk:"kernel_severity"` + NtpSeverity types.String `tfsdk:"ntp_severity"` + PfeSeverity types.String `tfsdk:"pfe_severity"` + SecuritySeverity types.String `tfsdk:"security_severity"` + UserSeverity types.String `tfsdk:"user_severity"` + Archive []struct { + BinaryData types.Bool `tfsdk:"binary_data"` + NoBinaryData types.Bool `tfsdk:"no_binary_data"` + WorldReadable types.Bool `tfsdk:"world_readable"` + NoWorldReadable types.Bool `tfsdk:"no_world_readable"` + Files types.Int64 `tfsdk:"files"` + Size types.Int64 `tfsdk:"size"` + StartTime types.String `tfsdk:"start_time"` + TransferInterval types.Int64 `tfsdk:"transfer_interval"` + Sites []struct { + URL types.String `tfsdk:"url"` + Password types.String `tfsdk:"password"` + RoutingInstance types.String `tfsdk:"routing_instance"` + } `tfsdk:"sites"` + } `tfsdk:"archive"` + StructuredData []struct { + Brief types.Bool `tfsdk:"brief"` + } `tfsdk:"structured_data"` + } + + var dataV0 modelV0 + resp.Diagnostics.Append(req.State.Get(ctx, &dataV0)...) + if resp.Diagnostics.HasError() { + return + } + + var dataV1 systemSyslogFileData + dataV1.ID = dataV0.ID + dataV1.Filename = dataV0.Filename + dataV1.AllowDuplicates = dataV0.AllowDuplicates + dataV1.ExplicitPriority = dataV0.ExplicitPriority + dataV1.Match = dataV0.Match + dataV1.MatchStrings = dataV0.MatchStrings + dataV1.AnySeverity = dataV0.AnySeverity + dataV1.AuthorizationSeverity = dataV0.AuthorizationSeverity + dataV1.ChangelogSeverity = dataV0.ChangelogSeverity + dataV1.ConflictlogSeverity = dataV0.ConflictlogSeverity + dataV1.DaemonSeverity = dataV0.DaemonSeverity + dataV1.DfcSeverity = dataV0.DfcSeverity + dataV1.ExternalSeverity = dataV0.ExternalSeverity + dataV1.FirewallSeverity = dataV0.FirewallSeverity + dataV1.FtpSeverity = dataV0.FtpSeverity + dataV1.InteractivecommandsSeverity = dataV0.InteractivecommandsSeverity + dataV1.KernelSeverity = dataV0.KernelSeverity + dataV1.NtpSeverity = dataV0.NtpSeverity + dataV1.PfeSeverity = dataV0.PfeSeverity + dataV1.SecuritySeverity = dataV0.SecuritySeverity + dataV1.UserSeverity = dataV0.UserSeverity + if len(dataV0.Archive) > 0 { + dataV1.Archive = &systemSyslogFileBlockArchive{ + BinaryData: dataV0.Archive[0].BinaryData, + NoBinaryData: dataV0.Archive[0].NoBinaryData, + WorldReadable: dataV0.Archive[0].WorldReadable, + NoWorldReadable: dataV0.Archive[0].NoWorldReadable, + Files: dataV0.Archive[0].Files, + Size: dataV0.Archive[0].Size, + StartTime: dataV0.Archive[0].StartTime, + TransferInterval: dataV0.Archive[0].TransferInterval, + } + for _, block := range dataV0.Archive[0].Sites { + dataV1.Archive.Sites = append(dataV1.Archive.Sites, + systemSyslogFileBlockArchiveBlockSites{ + URL: block.URL, + Password: block.Password, + RoutingInstance: block.RoutingInstance, + }, + ) + } + } + if len(dataV0.StructuredData) > 0 { + dataV1.StructuredData = &systemSyslogFileBlockStructuredData{ + Brief: dataV0.StructuredData[0].Brief, + } + } + + resp.Diagnostics.Append(resp.State.Set(ctx, dataV1)...) +} diff --git a/internal/providerfwk/upgradestate_system_syslog_file_test.go b/internal/providerfwk/upgradestate_system_syslog_file_test.go new file mode 100644 index 00000000..83c48295 --- /dev/null +++ b/internal/providerfwk/upgradestate_system_syslog_file_test.go @@ -0,0 +1,29 @@ +package providerfwk_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/plancheck" +) + +// export TESTACC_INTERFACE= for choose interface available else it's ge-0/0/3. +func TestAccUpgradeStateResourceSystemSyslogFile_V0toV1_basic(t *testing.T) { + resource.Test(t, resource.TestCase{ + Steps: []resource.TestStep{ + { + ConfigDirectory: config.TestStepDirectory(), + }, + { + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + ConfigDirectory: config.TestStepDirectory(), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + }, + }) +} diff --git a/internal/providersdk/func_common.go b/internal/providersdk/func_common.go index ba6f2174..000ce429 100644 --- a/internal/providersdk/func_common.go +++ b/internal/providersdk/func_common.go @@ -199,13 +199,6 @@ func copyAndRemoveItemMapList2( return list } -func listOfSyslogSeverity() []string { - return []string{ - "alert", "any", "critical", - "emergency", "error", "info", "none", "notice", "warning", - } -} - func validateIsIPv6Address(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(string) if !ok { diff --git a/internal/providersdk/provider.go b/internal/providersdk/provider.go index 3657ec1c..d93b64c0 100644 --- a/internal/providersdk/provider.go +++ b/internal/providersdk/provider.go @@ -227,7 +227,6 @@ func Provider() *schema.Provider { "junos_system_radius_server": resourceSystemRadiusServer(), "junos_system_root_authentication": resourceSystemRootAuthentication(), "junos_system_services_dhcp_localserver_group": resourceSystemServicesDhcpLocalServerGroup(), - "junos_system_syslog_file": resourceSystemSyslogFile(), "junos_vlan": resourceVlan(), "junos_vstp": resourceVstp(), "junos_vstp_interface": resourceVstpInterface(), diff --git a/internal/providersdk/resource_security_log_stream.go b/internal/providersdk/resource_security_log_stream.go index 4dee241c..a0fa87f4 100644 --- a/internal/providersdk/resource_security_log_stream.go +++ b/internal/providersdk/resource_security_log_stream.go @@ -119,7 +119,7 @@ func resourceSecurityLogStream() *schema.Resource { "severity": { Type: schema.TypeString, Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), + ValidateFunc: validation.StringInSlice(junos.SyslogSeverity(), false), }, }, } diff --git a/internal/providersdk/resource_system_syslog_file.go b/internal/providersdk/resource_system_syslog_file.go deleted file mode 100644 index c1fb47a7..00000000 --- a/internal/providersdk/resource_system_syslog_file.go +++ /dev/null @@ -1,780 +0,0 @@ -package providersdk - -import ( - "context" - "fmt" - "strconv" - "strings" - - "github.com/jeremmfr/terraform-provider-junos/internal/junos" - - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - balt "github.com/jeremmfr/go-utils/basicalter" - bchk "github.com/jeremmfr/go-utils/basiccheck" - jdecode "github.com/jeremmfr/junosdecode" -) - -type syslogFileOptions struct { - allowDuplicates bool - explicitPriority bool - filename string - match string - anySeverity string - authorizationSeverity string - changelogSeverity string - conflictlogSeverity string - daemonSeverity string - dfcSeverity string - externalSeverity string - firewallSeverity string - ftpSeverity string - interactivecommandsSeverity string - kernelSeverity string - ntpSeverity string - pfeSeverity string - securitySeverity string - userSeverity string - matchStrings []string - archive []map[string]interface{} - structuredData []map[string]interface{} -} - -func resourceSystemSyslogFile() *schema.Resource { - return &schema.Resource{ - CreateWithoutTimeout: resourceSystemSyslogFileCreate, - ReadWithoutTimeout: resourceSystemSyslogFileRead, - UpdateWithoutTimeout: resourceSystemSyslogFileUpdate, - DeleteWithoutTimeout: resourceSystemSyslogFileDelete, - Importer: &schema.ResourceImporter{ - StateContext: resourceSystemSyslogFileImport, - }, - Schema: map[string]*schema.Schema{ - "filename": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateDiagFunc: validateNameObjectJunos([]string{}, 64, formatDefault), - }, - "allow_duplicates": { - Type: schema.TypeBool, - Optional: true, - }, - "explicit_priority": { - Type: schema.TypeBool, - Optional: true, - }, - "match": { - Type: schema.TypeString, - Optional: true, - }, - "match_strings": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "structured_data": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "brief": { - Type: schema.TypeBool, - Optional: true, - }, - }, - }, - }, - "any_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "authorization_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "changelog_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "conflictlog_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "daemon_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "dfc_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "external_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "firewall_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "ftp_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "interactivecommands_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "kernel_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "ntp_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "pfe_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "security_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "user_severity": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(listOfSyslogSeverity(), false), - }, - "archive": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "sites": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "url": { - Type: schema.TypeString, - Required: true, - }, - "password": { - Type: schema.TypeString, - Optional: true, - Sensitive: true, - }, - "routing_instance": { - Type: schema.TypeString, - Optional: true, - }, - }, - }, - }, - "binary_data": { - Type: schema.TypeBool, - Optional: true, - ConflictsWith: []string{"archive.0.no_binary_data"}, - }, - "no_binary_data": { - Type: schema.TypeBool, - Optional: true, - ConflictsWith: []string{"archive.0.binary_data"}, - }, - "world_readable": { - Type: schema.TypeBool, - Optional: true, - ConflictsWith: []string{"archive.0.no_world_readable"}, - }, - "no_world_readable": { - Type: schema.TypeBool, - Optional: true, - ConflictsWith: []string{"archive.0.world_readable"}, - }, - "files": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(1, 1000), - }, - "size": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(65536, 1073741824), - }, - "start_time": { - Type: schema.TypeString, - Optional: true, - }, - "transfer_interval": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(5, 2880), - }, - }, - }, - }, - }, - } -} - -func resourceSystemSyslogFileCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - clt := m.(*junos.Client) - if clt.FakeCreateSetFile() { - junSess := clt.NewSessionWithoutNetconf(ctx) - if err := setSystemSyslogFile(d, junSess); err != nil { - return diag.FromErr(err) - } - d.SetId(d.Get("filename").(string)) - - return nil - } - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return diag.FromErr(err) - } - defer junSess.Close() - if err := junSess.ConfigLock(ctx); err != nil { - return diag.FromErr(err) - } - var diagWarns diag.Diagnostics - syslogFileExists, err := checkSystemSyslogFileExists(d.Get("filename").(string), junSess) - if err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - if syslogFileExists { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, - diag.FromErr(fmt.Errorf("system syslog file %v already exists", d.Get("filename").(string)))...) - } - - if err := setSystemSyslogFile(d, junSess); err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - warns, err := junSess.CommitConf(ctx, "create resource junos_system_syslog_file") - appendDiagWarns(&diagWarns, warns) - if err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - syslogFileExists, err = checkSystemSyslogFileExists(d.Get("filename").(string), junSess) - if err != nil { - return append(diagWarns, diag.FromErr(err)...) - } - if syslogFileExists { - d.SetId(d.Get("filename").(string)) - } else { - return append(diagWarns, diag.FromErr(fmt.Errorf("system syslog file %v not exists after commit "+ - "=> check your config", d.Get("filename").(string)))...) - } - - return append(diagWarns, resourceSystemSyslogFileReadWJunSess(d, junSess)...) -} - -func resourceSystemSyslogFileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - clt := m.(*junos.Client) - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return diag.FromErr(err) - } - defer junSess.Close() - - return resourceSystemSyslogFileReadWJunSess(d, junSess) -} - -func resourceSystemSyslogFileReadWJunSess(d *schema.ResourceData, junSess *junos.Session, -) diag.Diagnostics { - junos.MutexLock() - syslogFileOptions, err := readSystemSyslogFile(d.Get("filename").(string), junSess) - junos.MutexUnlock() - if err != nil { - return diag.FromErr(err) - } - if syslogFileOptions.filename == "" { - d.SetId("") - } else { - fillSystemSyslogFileData(d, syslogFileOptions) - } - - return nil -} - -func resourceSystemSyslogFileUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - d.Partial(true) - clt := m.(*junos.Client) - if clt.FakeUpdateAlso() { - junSess := clt.NewSessionWithoutNetconf(ctx) - if err := delSystemSyslogFile(d.Get("filename").(string), junSess); err != nil { - return diag.FromErr(err) - } - if err := setSystemSyslogFile(d, junSess); err != nil { - return diag.FromErr(err) - } - d.Partial(false) - - return nil - } - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return diag.FromErr(err) - } - defer junSess.Close() - if err := junSess.ConfigLock(ctx); err != nil { - return diag.FromErr(err) - } - var diagWarns diag.Diagnostics - if err := delSystemSyslogFile(d.Get("filename").(string), junSess); err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - if err := setSystemSyslogFile(d, junSess); err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - warns, err := junSess.CommitConf(ctx, "update resource junos_system_syslog_file") - appendDiagWarns(&diagWarns, warns) - if err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - d.Partial(false) - - return append(diagWarns, resourceSystemSyslogFileReadWJunSess(d, junSess)...) -} - -func resourceSystemSyslogFileDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - clt := m.(*junos.Client) - if clt.FakeDeleteAlso() { - junSess := clt.NewSessionWithoutNetconf(ctx) - if err := delSystemSyslogFile(d.Get("filename").(string), junSess); err != nil { - return diag.FromErr(err) - } - - return nil - } - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return diag.FromErr(err) - } - defer junSess.Close() - if err := junSess.ConfigLock(ctx); err != nil { - return diag.FromErr(err) - } - var diagWarns diag.Diagnostics - if err := delSystemSyslogFile(d.Get("filename").(string), junSess); err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - warns, err := junSess.CommitConf(ctx, "delete resource junos_system_syslog_file") - appendDiagWarns(&diagWarns, warns) - if err != nil { - appendDiagWarns(&diagWarns, junSess.ConfigClear()) - - return append(diagWarns, diag.FromErr(err)...) - } - - return diagWarns -} - -func resourceSystemSyslogFileImport(ctx context.Context, d *schema.ResourceData, m interface{}, -) ([]*schema.ResourceData, error) { - clt := m.(*junos.Client) - junSess, err := clt.StartNewSession(ctx) - if err != nil { - return nil, err - } - defer junSess.Close() - result := make([]*schema.ResourceData, 1) - - syslogFileExists, err := checkSystemSyslogFileExists(d.Id(), junSess) - if err != nil { - return nil, err - } - if !syslogFileExists { - return nil, fmt.Errorf("don't find system syslog file with id '%v' (id must be )", d.Id()) - } - syslogFileOptions, err := readSystemSyslogFile(d.Id(), junSess) - if err != nil { - return nil, err - } - fillSystemSyslogFileData(d, syslogFileOptions) - - result[0] = d - - return result, nil -} - -func checkSystemSyslogFileExists(filename string, junSess *junos.Session) (bool, error) { - showConfig, err := junSess.Command(junos.CmdShowConfig + "system syslog file " + filename + junos.PipeDisplaySet) - if err != nil { - return false, err - } - if showConfig == junos.EmptyW { - return false, nil - } - - return true, nil -} - -func setSystemSyslogFile(d *schema.ResourceData, junSess *junos.Session) error { - setPrefix := "set system syslog file " + d.Get("filename").(string) - configSet := make([]string, 0) - - if d.Get("allow_duplicates").(bool) { - configSet = append(configSet, setPrefix+" allow-duplicates") - } - if d.Get("explicit_priority").(bool) { - configSet = append(configSet, setPrefix+" explicit-priority") - } - if d.Get("match").(string) != "" { - configSet = append(configSet, setPrefix+" match \""+d.Get("match").(string)+"\"") - } - for _, v := range d.Get("match_strings").([]interface{}) { - configSet = append(configSet, setPrefix+" match-strings \""+v.(string)+"\"") - } - for _, v := range d.Get("structured_data").([]interface{}) { - configSet = append(configSet, setPrefix+" structured-data") - if v != nil { - ma := v.(map[string]interface{}) - if ma["brief"].(bool) { - configSet = append(configSet, setPrefix+" structured-data brief") - } - } - } - if d.Get("any_severity").(string) != "" { - configSet = append(configSet, setPrefix+" any "+d.Get("any_severity").(string)) - } - if d.Get("authorization_severity").(string) != "" { - configSet = append(configSet, setPrefix+" authorization "+d.Get("authorization_severity").(string)) - } - if d.Get("changelog_severity").(string) != "" { - configSet = append(configSet, setPrefix+" change-log "+d.Get("changelog_severity").(string)) - } - if d.Get("conflictlog_severity").(string) != "" { - configSet = append(configSet, setPrefix+" conflict-log "+d.Get("conflictlog_severity").(string)) - } - if d.Get("daemon_severity").(string) != "" { - configSet = append(configSet, setPrefix+" daemon "+d.Get("daemon_severity").(string)) - } - if d.Get("dfc_severity").(string) != "" { - configSet = append(configSet, setPrefix+" dfc "+d.Get("dfc_severity").(string)) - } - if d.Get("external_severity").(string) != "" { - configSet = append(configSet, setPrefix+" external "+d.Get("external_severity").(string)) - } - if d.Get("firewall_severity").(string) != "" { - configSet = append(configSet, setPrefix+" firewall "+d.Get("firewall_severity").(string)) - } - if d.Get("ftp_severity").(string) != "" { - configSet = append(configSet, setPrefix+" ftp "+d.Get("ftp_severity").(string)) - } - if d.Get("interactivecommands_severity").(string) != "" { - configSet = append(configSet, setPrefix+" interactive-commands "+d.Get("interactivecommands_severity").(string)) - } - if d.Get("kernel_severity").(string) != "" { - configSet = append(configSet, setPrefix+" kernel "+d.Get("kernel_severity").(string)) - } - if d.Get("ntp_severity").(string) != "" { - configSet = append(configSet, setPrefix+" ntp "+d.Get("ntp_severity").(string)) - } - if d.Get("pfe_severity").(string) != "" { - configSet = append(configSet, setPrefix+" pfe "+d.Get("pfe_severity").(string)) - } - if d.Get("security_severity").(string) != "" { - configSet = append(configSet, setPrefix+" security "+d.Get("security_severity").(string)) - } - if d.Get("user_severity").(string) != "" { - configSet = append(configSet, setPrefix+" user "+d.Get("user_severity").(string)) - } - for _, v := range d.Get("archive").([]interface{}) { - setPrefixArchive := setPrefix + " archive" - configSet = append(configSet, setPrefixArchive) - if v != nil { - archive := v.(map[string]interface{}) - sitesURLList := make([]string, 0) - for _, v2 := range archive["sites"].([]interface{}) { - sites := v2.(map[string]interface{}) - if bchk.InSlice(sites["url"].(string), sitesURLList) { - return fmt.Errorf("multiple blocks sites with the same url %s", sites["url"].(string)) - } - sitesURLList = append(sitesURLList, sites["url"].(string)) - setPrefixArchiveSite := setPrefixArchive + " archive-sites " + sites["url"].(string) - configSet = append(configSet, setPrefixArchiveSite) - if sites["password"].(string) != "" { - configSet = append(configSet, setPrefixArchiveSite+" password \""+ - sites["password"].(string)+"\"") - } - if sites["routing_instance"].(string) != "" { - configSet = append(configSet, setPrefixArchiveSite+" routing-instance "+ - sites["routing_instance"].(string)) - } - } - if archive["binary_data"].(bool) { - configSet = append(configSet, setPrefixArchive+" binary-data") - } - if archive["no_binary_data"].(bool) { - configSet = append(configSet, setPrefixArchive+" no-binary-data") - } - if archive["world_readable"].(bool) { - configSet = append(configSet, setPrefixArchive+" world-readable") - } - if archive["no_world_readable"].(bool) { - configSet = append(configSet, setPrefixArchive+" no-world-readable") - } - if archive["files"].(int) != 0 { - configSet = append(configSet, setPrefixArchive+" files "+ - strconv.Itoa(archive["files"].(int))) - } - if archive["size"].(int) != 0 { - configSet = append(configSet, setPrefixArchive+" size "+ - strconv.Itoa(archive["size"].(int))) - } - if archive["start_time"].(string) != "" { - configSet = append(configSet, setPrefixArchive+" start-time "+ - archive["start_time"].(string)) - } - if archive["transfer_interval"].(int) != 0 { - configSet = append(configSet, setPrefixArchive+" transfer-interval "+ - strconv.Itoa(archive["transfer_interval"].(int))) - } - } - } - - return junSess.ConfigSet(configSet) -} - -func readSystemSyslogFile(filename string, junSess *junos.Session, -) (confRead syslogFileOptions, err error) { - showConfig, err := junSess.Command(junos.CmdShowConfig + - "system syslog file " + filename + junos.PipeDisplaySetRelative) - if err != nil { - return confRead, err - } - if showConfig != junos.EmptyW { - confRead.filename = filename - for _, item := range strings.Split(showConfig, "\n") { - if strings.Contains(item, junos.XMLStartTagConfigOut) { - continue - } - if strings.Contains(item, junos.XMLEndTagConfigOut) { - break - } - itemTrim := strings.TrimPrefix(item, junos.SetLS) - switch { - case itemTrim == "allow-duplicates": - confRead.allowDuplicates = true - case itemTrim == "explicit-priority": - confRead.explicitPriority = true - case balt.CutPrefixInString(&itemTrim, "match "): - confRead.match = strings.Trim(itemTrim, "\"") - case balt.CutPrefixInString(&itemTrim, "match-strings "): - confRead.matchStrings = append(confRead.matchStrings, strings.Trim(itemTrim, "\"")) - case balt.CutPrefixInString(&itemTrim, "structured-data"): - if len(confRead.structuredData) == 0 { - confRead.structuredData = append(confRead.structuredData, map[string]interface{}{ - "brief": false, - }) - } - if itemTrim == " brief" { - confRead.structuredData[0]["brief"] = true - } - case balt.CutPrefixInString(&itemTrim, "any "): - confRead.anySeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "authorization "): - confRead.authorizationSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "change-log "): - confRead.changelogSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "conflict-log "): - confRead.conflictlogSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "daemon "): - confRead.daemonSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "dfc "): - confRead.dfcSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "external "): - confRead.externalSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "firewall "): - confRead.firewallSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "ftp "): - confRead.ftpSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "interactive-commands "): - confRead.interactivecommandsSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "kernel "): - confRead.kernelSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "ntp "): - confRead.ntpSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "pfe "): - confRead.pfeSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "security "): - confRead.securitySeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "user "): - confRead.userSeverity = itemTrim - case balt.CutPrefixInString(&itemTrim, "archive"): - if len(confRead.archive) == 0 { - confRead.archive = append(confRead.archive, map[string]interface{}{ - "sites": make([]map[string]interface{}, 0), - "binary_data": false, - "no_binary_data": false, - "world_readable": false, - "no_world_readable": false, - "files": 0, - "size": 0, - "transfer_interval": 0, - "start_time": "", - }) - } - switch { - case itemTrim == " binary-data": - confRead.archive[0]["binary_data"] = true - case itemTrim == " no-binary-data": - confRead.archive[0]["no_binary_data"] = true - case itemTrim == " world-readable": - confRead.archive[0]["world_readable"] = true - case itemTrim == " no-world-readable": - confRead.archive[0]["no_world_readable"] = true - case balt.CutPrefixInString(&itemTrim, " files "): - confRead.archive[0]["files"], err = strconv.Atoi(itemTrim) - if err != nil { - return confRead, fmt.Errorf(failedConvAtoiError, itemTrim, err) - } - case balt.CutPrefixInString(&itemTrim, " size "): - confRead.archive[0]["size"], err = strconv.Atoi(itemTrim) - if err != nil { - return confRead, fmt.Errorf(failedConvAtoiError, itemTrim, err) - } - case balt.CutPrefixInString(&itemTrim, " transfer-interval "): - confRead.archive[0]["transfer_interval"], err = strconv.Atoi(itemTrim) - if err != nil { - return confRead, fmt.Errorf(failedConvAtoiError, itemTrim, err) - } - case balt.CutPrefixInString(&itemTrim, " start-time "): - confRead.archive[0]["start_time"] = strings.Split(strings.Trim(itemTrim, "\""), " ")[0] - case balt.CutPrefixInString(&itemTrim, " archive-sites "): - itemTrimFields := strings.Split(itemTrim, " ") - sitesOptions := map[string]interface{}{ - "url": itemTrimFields[0], - "password": "", - "routing_instance": "", - } - confRead.archive[0]["sites"] = copyAndRemoveItemMapList("url", sitesOptions, - confRead.archive[0]["sites"].([]map[string]interface{})) - balt.CutPrefixInString(&itemTrim, itemTrimFields[0]+" ") - switch { - case balt.CutPrefixInString(&itemTrim, "password "): - sitesOptions["password"], err = jdecode.Decode(strings.Trim(itemTrim, "\"")) - if err != nil { - return confRead, fmt.Errorf("decoding password: %w", err) - } - case balt.CutPrefixInString(&itemTrim, "routing-instance "): - sitesOptions["routing_instance"] = itemTrim - } - confRead.archive[0]["sites"] = append(confRead.archive[0]["sites"].([]map[string]interface{}), sitesOptions) - } - } - } - } - - return confRead, nil -} - -func delSystemSyslogFile(filename string, junSess *junos.Session) error { - configSet := make([]string, 0, 1) - configSet = append(configSet, "delete system syslog file "+filename) - - return junSess.ConfigSet(configSet) -} - -func fillSystemSyslogFileData(d *schema.ResourceData, syslogFileOptions syslogFileOptions) { - if tfErr := d.Set("filename", syslogFileOptions.filename); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("allow_duplicates", syslogFileOptions.allowDuplicates); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("explicit_priority", syslogFileOptions.explicitPriority); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("match", syslogFileOptions.match); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("match_strings", syslogFileOptions.matchStrings); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("structured_data", syslogFileOptions.structuredData); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("any_severity", syslogFileOptions.anySeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("authorization_severity", syslogFileOptions.authorizationSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("changelog_severity", syslogFileOptions.changelogSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("conflictlog_severity", syslogFileOptions.conflictlogSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("daemon_severity", syslogFileOptions.daemonSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("dfc_severity", syslogFileOptions.dfcSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("external_severity", syslogFileOptions.externalSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("firewall_severity", syslogFileOptions.firewallSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("ftp_severity", syslogFileOptions.ftpSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("interactivecommands_severity", syslogFileOptions.interactivecommandsSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("kernel_severity", syslogFileOptions.kernelSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("ntp_severity", syslogFileOptions.ntpSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("pfe_severity", syslogFileOptions.pfeSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("security_severity", syslogFileOptions.securitySeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("user_severity", syslogFileOptions.userSeverity); tfErr != nil { - panic(tfErr) - } - if tfErr := d.Set("archive", syslogFileOptions.archive); tfErr != nil { - panic(tfErr) - } -} diff --git a/internal/providersdk/resource_system_syslog_file_test.go b/internal/providersdk/resource_system_syslog_file_test.go deleted file mode 100644 index 29b89cfa..00000000 --- a/internal/providersdk/resource_system_syslog_file_test.go +++ /dev/null @@ -1,213 +0,0 @@ -package providersdk_test - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestAccResourceSystemSyslogFile_basic(t *testing.T) { - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - Config: testAccResourceSystemSyslogFileConfigCreate(), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "filename", "testacc"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "structured_data.#", "0"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "allow_duplicates", "true"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "explicit_priority", "true"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "match", "match testacc"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "match_strings.#", "1"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "match_strings.0", "match testacc"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "any_severity", "emergency"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "changelog_severity", "critical"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "conflictlog_severity", "error"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "daemon_severity", "warning"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "dfc_severity", "alert"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "external_severity", "any"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "firewall_severity", "info"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "ftp_severity", "none"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "interactivecommands_severity", "notice"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "kernel_severity", "emergency"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "ntp_severity", "emergency"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "pfe_severity", "emergency"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "security_severity", "emergency"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "user_severity", "emergency"), - ), - }, - { - Config: testAccResourceSystemSyslogFileConfigUpdate(), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "structured_data.#", "1"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "structured_data.0.brief", "false"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.#", "1"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.0.sites.#", "0"), - ), - }, - { - Config: testAccResourceSystemSyslogFileConfigUpdate2(), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "structured_data.#", "1"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "structured_data.0.brief", "true"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.#", "1"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.0.binary_data", "true"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.0.world_readable", "true"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.0.size", "1073741823"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.0.files", "5"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.0.transfer_interval", "5"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.0.sites.#", "2"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.0.sites.0.url", "example.fr"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.0.sites.1.url", "example.com"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.0.sites.1.password", "password"), - resource.TestCheckResourceAttr("junos_system_syslog_file.testacc_syslogFile", - "archive.0.sites.1.routing_instance", "testacc_syslogFile"), - ), - }, - { - ResourceName: "junos_system_syslog_file.testacc_syslogFile", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccResourceSystemSyslogFileConfigCreate() string { - return ` -resource "junos_system_syslog_file" "testacc_syslogFile" { - filename = "testacc" - allow_duplicates = true - explicit_priority = true - match = "match testacc" - match_strings = ["match testacc"] - any_severity = "emergency" - changelog_severity = "critical" - conflictlog_severity = "error" - daemon_severity = "warning" - dfc_severity = "alert" - external_severity = "any" - firewall_severity = "info" - ftp_severity = "none" - interactivecommands_severity = "notice" - kernel_severity = "emergency" - ntp_severity = "emergency" - pfe_severity = "emergency" - security_severity = "emergency" - user_severity = "emergency" -} -` -} - -func testAccResourceSystemSyslogFileConfigUpdate() string { - return ` -resource "junos_system_syslog_file" "testacc_syslogFile" { - filename = "testacc" - allow_duplicates = true - match = "match testacc" - any_severity = "emergency" - changelog_severity = "critical" - conflictlog_severity = "error" - daemon_severity = "warning" - dfc_severity = "alert" - external_severity = "any" - firewall_severity = "info" - ftp_severity = "none" - interactivecommands_severity = "notice" - kernel_severity = "error" - ntp_severity = "error" - pfe_severity = "error" - security_severity = "error" - user_severity = "error" - structured_data {} - archive {} -} -resource "junos_system_syslog_file" "testacc_syslogFile2" { - filename = "testacc2" - explicit_priority = true -} -` -} - -func testAccResourceSystemSyslogFileConfigUpdate2() string { - return ` -resource "junos_routing_instance" "testacc_syslogFile" { - name = "testacc_syslogFile" -} -resource "junos_system_syslog_file" "testacc_syslogFile" { - filename = "testacc" - allow_duplicates = true - match = "match testacc" - any_severity = "emergency" - changelog_severity = "critical" - conflictlog_severity = "error" - daemon_severity = "warning" - dfc_severity = "alert" - external_severity = "any" - firewall_severity = "info" - ftp_severity = "none" - interactivecommands_severity = "notice" - kernel_severity = "error" - ntp_severity = "error" - pfe_severity = "error" - security_severity = "error" - user_severity = "error" - structured_data { - brief = true - } - archive { - binary_data = true - world_readable = true - size = 1073741823 - files = 5 - transfer_interval = 5 - sites { - url = "example.fr" - } - sites { - url = "example.com" - password = "password" - routing_instance = junos_routing_instance.testacc_syslogFile.name - } - } -} -` -} From feb61f40ffb4b1a8bb0db118ed6286a6bb031f16 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Sat, 16 Dec 2023 20:36:26 +0100 Subject: [PATCH 40/43] add junos_system_syslog_user resource Fix #593 --- .changes/issue-593.md | 2 + docs/resources/system_syslog_user.md | 82 +++ internal/providerfwk/provider.go | 1 + .../resource_system_syslog_user.go | 559 ++++++++++++++++++ .../resource_system_syslog_user_test.go | 64 ++ .../1/main.tf | 50 ++ .../1/provider.tf | 1 + .../2/main.tf | 26 + 8 files changed, 785 insertions(+) create mode 100644 docs/resources/system_syslog_user.md create mode 100644 internal/providerfwk/resource_system_syslog_user.go create mode 100644 internal/providerfwk/resource_system_syslog_user_test.go create mode 100644 internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/main.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/provider.tf create mode 100644 internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/2/main.tf diff --git a/.changes/issue-593.md b/.changes/issue-593.md index bfc38db9..9c725e84 100644 --- a/.changes/issue-593.md +++ b/.changes/issue-593.md @@ -1,6 +1,8 @@ FEATURES: +* add `junos_system_syslog_user` resource (Fix [#593](https://github.com/jeremmfr/terraform-provider-junos/issues/593)) + ENHANCEMENTS: * **resource/junos_system_syslog_file**: resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) diff --git a/docs/resources/system_syslog_user.md b/docs/resources/system_syslog_user.md new file mode 100644 index 00000000..dd1f5167 --- /dev/null +++ b/docs/resources/system_syslog_user.md @@ -0,0 +1,82 @@ +--- +page_title: "Junos: junos_system_syslog_user" +--- + +# junos_system_syslog_user + +Configure a system syslog user. + +## Example Usage + +```hcl +# Add a system syslog user +resource "junos_system_syslog_user" "all" { + username = "*" + any_severity = "emergency" +} +resource "junos_system_syslog_user" "demo_syslog_user" { + username = "admin" + kernel_severity = "any" +} +``` + +## Argument Reference + +The following arguments are supported: + +- **username** (Required, String, Forces new resource) + Name of user to notify (or `*` for all). +- **allow_duplicates** (Optional, Boolean) + Do not suppress the repeated message. +- **match** (Optional, String) + Regular expression for lines to be logged. +- **match_strings** (Optional, List of String) + Matching string(s) for lines to be logged. +- **any_severity** (Optional, String) + All facilities severity. +- **authorization_severity** (Optional, String) + Authorization system severity. +- **changelog_severity** (Optional, String) + Configuration change log severity. +- **conflictlog_severity** (Optional, String) + Configuration conflict log severity. +- **daemon_severity** (Optional, String) + Various system processes severity. +- **dfc_severity** (Optional, String) + Dynamic flow capture severity. +- **external_severity** (Optional, String) + Local external applications severity. +- **firewall_severity** (Optional, String) + Firewall filtering system severity. +- **ftp_severity** (Optional, String) + FTP process severity. +- **interactivecommands_severity** (Optional, String) + Commands executed by the UI severity. +- **kernel_severity** (Optional, String) + Kernel severity. +- **ntp_severity** (Optional, String) + NTP process severity. +- **pfe_severity** (Optional, String) + Packet Forwarding Engine severity. +- **security_severity** (Optional, String) + Security related severity. +- **user_severity** (Optional, String) + User processes severity. + +**WARNING** All severities need to be +`alert`, `any`, `critical`, `emergency`, `error`, `info`, `none`, `notice` or `warning`. + +## Attributes Reference + +The following attributes are exported: + +- **id** (String) + An identifier for the resource with format ``. + +## Import + +Junos system syslog host can be imported using an id made up of ``, e.g. + +```shell +$ terraform import junos_system_syslog_user.demo_syslog_user admin +``` diff --git a/internal/providerfwk/provider.go b/internal/providerfwk/provider.go index 7486db6e..95183328 100644 --- a/internal/providerfwk/provider.go +++ b/internal/providerfwk/provider.go @@ -281,6 +281,7 @@ func (p *junosProvider) Resources(_ context.Context) []func() resource.Resource newSystemResource, newSystemSyslogFileResource, newSystemSyslogHostResource, + newSystemSyslogUserResource, } } diff --git a/internal/providerfwk/resource_system_syslog_user.go b/internal/providerfwk/resource_system_syslog_user.go new file mode 100644 index 00000000..81cc68a8 --- /dev/null +++ b/internal/providerfwk/resource_system_syslog_user.go @@ -0,0 +1,559 @@ +package providerfwk + +import ( + "context" + "strings" + + "github.com/jeremmfr/terraform-provider-junos/internal/junos" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdiag" + "github.com/jeremmfr/terraform-provider-junos/internal/tfvalidator" + + "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + balt "github.com/jeremmfr/go-utils/basicalter" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ resource.Resource = &systemSyslogUser{} + _ resource.ResourceWithConfigure = &systemSyslogUser{} + _ resource.ResourceWithImportState = &systemSyslogUser{} +) + +type systemSyslogUser struct { + client *junos.Client +} + +func newSystemSyslogUserResource() resource.Resource { + return &systemSyslogUser{} +} + +func (rsc *systemSyslogUser) typeName() string { + return providerName + "_system_syslog_user" +} + +func (rsc *systemSyslogUser) junosName() string { + return "system syslog user" +} + +func (rsc *systemSyslogUser) junosClient() *junos.Client { + return rsc.client +} + +func (rsc *systemSyslogUser) Metadata( + _ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse, +) { + resp.TypeName = rsc.typeName() +} + +func (rsc *systemSyslogUser) Configure( + ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse, +) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + client, ok := req.ProviderData.(*junos.Client) + if !ok { + unexpectedResourceConfigureType(ctx, req, resp) + + return + } + rsc.client = client +} + +func (rsc *systemSyslogUser) Schema( + _ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse, +) { + resp.Schema = schema.Schema{ + Description: defaultResourceSchemaDescription(rsc), + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "An identifier for the resource with format ``.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "username": schema.StringAttribute{ + Required: true, + Description: "Name of user to notify (or `*` for all).", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 250), + stringvalidator.Any( + tfvalidator.StringFormat(tfvalidator.DefaultFormat), + stringvalidator.OneOf("*"), + ), + }, + }, + "allow_duplicates": schema.BoolAttribute{ + Optional: true, + Description: "Do not suppress the repeated message.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "match": schema.StringAttribute{ + Optional: true, + Description: "Regular expression for lines to be logged.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + tfvalidator.StringDoubleQuoteExclusion(), + }, + }, + "match_strings": schema.ListAttribute{ + ElementType: types.StringType, + Optional: true, + Description: "Matching string(s) for lines to be logged.", + Validators: []validator.List{ + listvalidator.SizeAtLeast(1), + listvalidator.ValueStringsAre( + stringvalidator.LengthAtLeast(1), + tfvalidator.StringDoubleQuoteExclusion(), + ), + }, + }, + "any_severity": schema.StringAttribute{ + Optional: true, + Description: "All facilities sseverity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "authorization_severity": schema.StringAttribute{ + Optional: true, + Description: "Authorization system severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "changelog_severity": schema.StringAttribute{ + Optional: true, + Description: "Configuration change log severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "conflictlog_severity": schema.StringAttribute{ + Optional: true, + Description: "Configuration conflict log severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "daemon_severity": schema.StringAttribute{ + Optional: true, + Description: "Various system processes severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "dfc_severity": schema.StringAttribute{ + Optional: true, + Description: "Dynamic flow capture severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "external_severity": schema.StringAttribute{ + Optional: true, + Description: "Local external applications severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "firewall_severity": schema.StringAttribute{ + Optional: true, + Description: "Firewall filtering system severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "ftp_severity": schema.StringAttribute{ + Optional: true, + Description: "FTP process severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "interactivecommands_severity": schema.StringAttribute{ + Optional: true, + Description: "Commands executed by the UI severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "kernel_severity": schema.StringAttribute{ + Optional: true, + Description: "Kernel severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "ntp_severity": schema.StringAttribute{ + Optional: true, + Description: "NTP process severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "pfe_severity": schema.StringAttribute{ + Optional: true, + Description: "Packet Forwarding Engine severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "security_severity": schema.StringAttribute{ + Optional: true, + Description: "Security related severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "user_severity": schema.StringAttribute{ + Optional: true, + Description: "User processes severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + }, + } +} + +type systemSyslogUserData struct { + AllowDuplicates types.Bool `tfsdk:"allow_duplicates"` + ID types.String `tfsdk:"id"` + Username types.String `tfsdk:"username"` + Match types.String `tfsdk:"match"` + MatchStrings []types.String `tfsdk:"match_strings"` + AnySeverity types.String `tfsdk:"any_severity"` + AuthorizationSeverity types.String `tfsdk:"authorization_severity"` + ChangelogSeverity types.String `tfsdk:"changelog_severity"` + ConflictlogSeverity types.String `tfsdk:"conflictlog_severity"` + DaemonSeverity types.String `tfsdk:"daemon_severity"` + DfcSeverity types.String `tfsdk:"dfc_severity"` + ExternalSeverity types.String `tfsdk:"external_severity"` + FirewallSeverity types.String `tfsdk:"firewall_severity"` + FtpSeverity types.String `tfsdk:"ftp_severity"` + InteractivecommandsSeverity types.String `tfsdk:"interactivecommands_severity"` + KernelSeverity types.String `tfsdk:"kernel_severity"` + NtpSeverity types.String `tfsdk:"ntp_severity"` + PfeSeverity types.String `tfsdk:"pfe_severity"` + SecuritySeverity types.String `tfsdk:"security_severity"` + UserSeverity types.String `tfsdk:"user_severity"` +} + +func (rsc *systemSyslogUser) Create( + ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse, +) { + var plan systemSyslogUserData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + if plan.Username.ValueString() == "" { + resp.Diagnostics.AddAttributeError( + path.Root("username"), + "Empty Username", + defaultResourceCouldNotCreateWithEmptyMessage(rsc, "username"), + ) + + return + } + + defaultResourceCreate( + ctx, + rsc, + func(fnCtx context.Context, junSess *junos.Session) bool { + userExists, err := checkSystemSyslogUserExists(fnCtx, plan.Username.ValueString(), junSess) + if err != nil { + resp.Diagnostics.AddError(tfdiag.PreCheckErrSummary, err.Error()) + + return false + } + if userExists { + resp.Diagnostics.AddError( + tfdiag.DuplicateConfigErrSummary, + defaultResourceAlreadyExistsMessage(rsc, plan.Username), + ) + + return false + } + + return true + }, + func(fnCtx context.Context, junSess *junos.Session) bool { + userExists, err := checkSystemSyslogUserExists(fnCtx, plan.Username.ValueString(), junSess) + if err != nil { + resp.Diagnostics.AddError(tfdiag.PostCheckErrSummary, err.Error()) + + return false + } + if !userExists { + resp.Diagnostics.AddError( + tfdiag.NotFoundErrSummary, + defaultResourceDoesNotExistsAfterCommitMessage(rsc, plan.Username), + ) + + return false + } + + return true + }, + &plan, + resp, + ) +} + +func (rsc *systemSyslogUser) Read( + ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse, +) { + var state, data systemSyslogUserData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + var _ resourceDataReadFrom1String = &data + defaultResourceRead( + ctx, + rsc, + []string{ + state.Username.ValueString(), + }, + &data, + nil, + resp, + ) +} + +func (rsc *systemSyslogUser) Update( + ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse, +) { + var plan, state systemSyslogUserData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceUpdate( + ctx, + rsc, + &state, + &plan, + resp, + ) +} + +func (rsc *systemSyslogUser) Delete( + ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse, +) { + var state systemSyslogUserData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceDelete( + ctx, + rsc, + &state, + resp, + ) +} + +func (rsc *systemSyslogUser) ImportState( + ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse, +) { + var data systemSyslogUserData + + var _ resourceDataReadFrom1String = &data + defaultResourceImportState( + ctx, + rsc, + &data, + req, + resp, + defaultResourceImportDontFindIDStrMessage(rsc, req.ID, "username"), + ) +} + +func checkSystemSyslogUserExists( + _ context.Context, username string, junSess *junos.Session, +) ( + bool, error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "system syslog user " + username + junos.PipeDisplaySet) + if err != nil { + return false, err + } + if showConfig == junos.EmptyW { + return false, nil + } + + return true, nil +} + +func (rscData *systemSyslogUserData) fillID() { + rscData.ID = types.StringValue(rscData.Username.ValueString()) +} + +func (rscData *systemSyslogUserData) nullID() bool { + return rscData.ID.IsNull() +} + +func (rscData *systemSyslogUserData) set( + _ context.Context, junSess *junos.Session, +) ( + path.Path, error, +) { + configSet := make([]string, 0) + setPrefix := "set system syslog user " + rscData.Username.ValueString() + " " + + if rscData.AllowDuplicates.ValueBool() { + configSet = append(configSet, setPrefix+"allow-duplicates") + } + if v := rscData.Match.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"match \""+v+"\"") + } + for _, v := range rscData.MatchStrings { + configSet = append(configSet, setPrefix+"match-strings \""+v.ValueString()+"\"") + } + if v := rscData.AnySeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"any "+v) + } + if v := rscData.AuthorizationSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"authorization "+v) + } + if v := rscData.ChangelogSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"change-log "+v) + } + if v := rscData.ConflictlogSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"conflict-log "+v) + } + if v := rscData.DaemonSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"daemon "+v) + } + if v := rscData.DfcSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"dfc "+v) + } + if v := rscData.ExternalSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"external "+v) + } + if v := rscData.FirewallSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"firewall "+v) + } + if v := rscData.FtpSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"ftp "+v) + } + if v := rscData.InteractivecommandsSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"interactive-commands "+v) + } + if v := rscData.KernelSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"kernel "+v) + } + if v := rscData.NtpSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"ntp "+v) + } + if v := rscData.PfeSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"pfe "+v) + } + if v := rscData.SecuritySeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"security "+v) + } + if v := rscData.UserSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"user "+v) + } + + return path.Empty(), junSess.ConfigSet(configSet) +} + +func (rscData *systemSyslogUserData) read( + _ context.Context, username string, junSess *junos.Session, +) ( + err error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "system syslog user " + username + junos.PipeDisplaySetRelative) + if err != nil { + return err + } + if showConfig != junos.EmptyW { + rscData.Username = types.StringValue(username) + rscData.fillID() + for _, item := range strings.Split(showConfig, "\n") { + if strings.Contains(item, junos.XMLStartTagConfigOut) { + continue + } + if strings.Contains(item, junos.XMLEndTagConfigOut) { + break + } + itemTrim := strings.TrimPrefix(item, junos.SetLS) + switch { + case itemTrim == "allow-duplicates": + rscData.AllowDuplicates = types.BoolValue(true) + case balt.CutPrefixInString(&itemTrim, "match "): + rscData.Match = types.StringValue(strings.Trim(itemTrim, "\"")) + case balt.CutPrefixInString(&itemTrim, "match-strings "): + rscData.MatchStrings = append(rscData.MatchStrings, + types.StringValue(strings.Trim(itemTrim, "\""))) + case balt.CutPrefixInString(&itemTrim, "any "): + rscData.AnySeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "authorization "): + rscData.AuthorizationSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "change-log "): + rscData.ChangelogSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "conflict-log "): + rscData.ConflictlogSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "daemon "): + rscData.DaemonSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "dfc "): + rscData.DfcSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "external "): + rscData.ExternalSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "firewall "): + rscData.FirewallSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "ftp "): + rscData.FtpSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "interactive-commands "): + rscData.InteractivecommandsSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "kernel "): + rscData.KernelSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "ntp "): + rscData.NtpSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "pfe "): + rscData.PfeSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "security "): + rscData.SecuritySeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "user "): + rscData.UserSeverity = types.StringValue(itemTrim) + } + } + } + + return nil +} + +func (rscData *systemSyslogUserData) del( + _ context.Context, junSess *junos.Session, +) error { + configSet := []string{ + "delete system syslog user " + rscData.Username.ValueString(), + } + + return junSess.ConfigSet(configSet) +} diff --git a/internal/providerfwk/resource_system_syslog_user_test.go b/internal/providerfwk/resource_system_syslog_user_test.go new file mode 100644 index 00000000..0106992e --- /dev/null +++ b/internal/providerfwk/resource_system_syslog_user_test.go @@ -0,0 +1,64 @@ +package providerfwk_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccResourceSystemSyslogUser_basic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + ConfigDirectory: config.TestStepDirectory(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "allow_duplicates", "true"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "match", "match testacc"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "any_severity", "emergency"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "changelog_severity", "critical"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "conflictlog_severity", "error"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "daemon_severity", "warning"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "dfc_severity", "alert"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "external_severity", "any"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "firewall_severity", "info"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "ftp_severity", "none"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "interactivecommands_severity", "notice"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "kernel_severity", "error"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "ntp_severity", "error"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "pfe_severity", "error"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "security_severity", "error"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "user_severity", "error"), + ), + }, + { + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + ConfigDirectory: config.TestStepDirectory(), + }, + { + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + ResourceName: "junos_system_syslog_user.testacc_syslogUser", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/main.tf b/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/main.tf new file mode 100644 index 00000000..556d1786 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/main.tf @@ -0,0 +1,50 @@ +resource "junos_system_syslog_user" "testacc_syslogUser" { + username = "testacc" + + allow_duplicates = true + match = "match testacc" + any_severity = "emergency" + changelog_severity = "critical" + conflictlog_severity = "error" + daemon_severity = "warning" + dfc_severity = "alert" + external_severity = "any" + firewall_severity = "info" + ftp_severity = "none" + interactivecommands_severity = "notice" + kernel_severity = "error" + ntp_severity = "error" + pfe_severity = "error" + security_severity = "error" + user_severity = "error" +} + +resource "local_file" "clear_user_all" { + content = "delete system syslog user *" + filename = "/tmp/testacc/terraform-provider-junos/ResourceSystemSyslogUser_basic_clear_user_all.txt" +} + +resource "junos_null_commit_file" "clear_user_all" { + filename = local_file.clear_user_all.filename +} + +resource "junos_system_syslog_user" "testacc_syslogUserAll" { + depends_on = [junos_null_commit_file.clear_user_all] + + username = "*" + + any_severity = "emergency" + changelog_severity = "emergency" + conflictlog_severity = "emergency" + daemon_severity = "emergency" + dfc_severity = "emergency" + external_severity = "emergency" + firewall_severity = "emergency" + ftp_severity = "emergency" + interactivecommands_severity = "emergency" + kernel_severity = "emergency" + ntp_severity = "emergency" + pfe_severity = "emergency" + security_severity = "emergency" + user_severity = "emergency" +} diff --git a/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/provider.tf b/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/provider.tf new file mode 100644 index 00000000..8e7fc8ee --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/provider.tf @@ -0,0 +1 @@ +provider "local" {} diff --git a/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/2/main.tf b/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/2/main.tf new file mode 100644 index 00000000..ae3f6f45 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/2/main.tf @@ -0,0 +1,26 @@ +resource "junos_system_syslog_user" "testacc_syslogUser" { + username = "testacc" + + match = "testacc" + match_strings = ["testacc"] + any_severity = "emergency" + changelog_severity = "emergency" + conflictlog_severity = "emergency" + daemon_severity = "emergency" + dfc_severity = "emergency" + external_severity = "emergency" + firewall_severity = "emergency" + ftp_severity = "emergency" + interactivecommands_severity = "error" + kernel_severity = "emergency" + ntp_severity = "emergency" + pfe_severity = "emergency" + security_severity = "emergency" + user_severity = "emergency" +} + +resource "junos_system_syslog_user" "testacc_syslogUserAll" { + username = "*" + + any_severity = "emergency" +} From b7694e9cf31ed9284adf0d2ff17f74410236c876 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Dec 2023 00:04:55 +0000 Subject: [PATCH 41/43] deps: bump golang.org/x/crypto from 0.16.0 to 0.17.0 Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.16.0 to 0.17.0. - [Commits](https://github.com/golang/crypto/compare/v0.16.0...v0.17.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 244c5f41..30f5c30a 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/jeremmfr/go-netconf v0.4.14 github.com/jeremmfr/go-utils v0.11.0 github.com/jeremmfr/junosdecode v1.1.1 - golang.org/x/crypto v0.16.0 + golang.org/x/crypto v0.17.0 ) require ( diff --git a/go.sum b/go.sum index 8f7e9598..33143763 100644 --- a/go.sum +++ b/go.sum @@ -140,8 +140,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= 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= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= From 581beee680439a72f388c8f25d0ee1b4c864baf9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Dec 2023 00:26:29 +0000 Subject: [PATCH 42/43] deps: bump github.com/jeremmfr/go-netconf from 0.4.14 to 0.4.15 Bumps [github.com/jeremmfr/go-netconf](https://github.com/jeremmfr/go-netconf) from 0.4.14 to 0.4.15. - [Changelog](https://github.com/jeremmfr/go-netconf/blob/master/CHANGELOG.md) - [Commits](https://github.com/jeremmfr/go-netconf/compare/v0.4.14...v0.4.15) --- updated-dependencies: - dependency-name: github.com/jeremmfr/go-netconf dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 30f5c30a..5c70dc95 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/hashicorp/terraform-plugin-mux v0.13.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0 github.com/hashicorp/terraform-plugin-testing v1.6.0 - github.com/jeremmfr/go-netconf v0.4.14 + github.com/jeremmfr/go-netconf v0.4.15 github.com/jeremmfr/go-utils v0.11.0 github.com/jeremmfr/junosdecode v1.1.1 golang.org/x/crypto v0.17.0 diff --git a/go.sum b/go.sum index 33143763..96cc6933 100644 --- a/go.sum +++ b/go.sum @@ -30,7 +30,6 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= @@ -82,8 +81,8 @@ github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv2 github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= -github.com/jeremmfr/go-netconf v0.4.14 h1:kENaS5/8WootwGEIPUPke31sqsMbc7MpSJBbzY81t/A= -github.com/jeremmfr/go-netconf v0.4.14/go.mod h1:Le5V8n/aoOifpdJK4BmxWW0CRhJWIaUkwpcQT75Y2NE= +github.com/jeremmfr/go-netconf v0.4.15 h1:Be6g52yxn1ic96QVzhYplsq8i6vxyo1c+IsvwMpXVdo= +github.com/jeremmfr/go-netconf v0.4.15/go.mod h1:DvCOMF9k/yIwLdp6apMNL1WWJzijIua3JNTFIZucfTI= github.com/jeremmfr/go-utils v0.11.0 h1:+0Y1pXp2UJKh6Rw0QxPxe0zLv70GzyThAIEMkqKV67M= github.com/jeremmfr/go-utils v0.11.0/go.mod h1:Lkn95iSzCRviFhn2/0XmqzWGmxI+kkoqKAZqip7VUmM= github.com/jeremmfr/junosdecode v1.1.1 h1:wOFfJIwLXP9s0eQzzAhuX7a7N1mc+AWgDLYAmR7VoWg= @@ -139,7 +138,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 h1:EDuYyU/MkFXllv9QF9819VlI9a4tzGuCbhG0ExK9o1U= @@ -177,7 +175,6 @@ golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -186,8 +183,8 @@ golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= 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= @@ -197,7 +194,6 @@ golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From 0802eb5ac37d47566f689a6e8ddc6935b88c21ce Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Thu, 21 Dec 2023 09:12:42 +0100 Subject: [PATCH 43/43] Release v2.4.0 --- .changes/issue-572.md | 9 --------- .changes/issue-573.md | 5 ----- .changes/issue-574.md | 9 --------- .changes/issue-575.md | 7 ------- .changes/issue-576.md | 5 ----- .changes/issue-585.md | 8 -------- .changes/issue-593.md | 20 -------------------- .changes/issue-594.md | 4 ---- CHANGELOG.md | 41 +++++++++++++++++++++++++++++++++++++++++ 9 files changed, 41 insertions(+), 67 deletions(-) delete mode 100644 .changes/issue-572.md delete mode 100644 .changes/issue-573.md delete mode 100644 .changes/issue-574.md delete mode 100644 .changes/issue-575.md delete mode 100644 .changes/issue-576.md delete mode 100644 .changes/issue-585.md delete mode 100644 .changes/issue-593.md delete mode 100644 .changes/issue-594.md diff --git a/.changes/issue-572.md b/.changes/issue-572.md deleted file mode 100644 index ab50e0e6..00000000 --- a/.changes/issue-572.md +++ /dev/null @@ -1,9 +0,0 @@ - -ENHANCEMENTS: - -* **resource/junos_interface_physical**: add `mc_ae` block argument in `parent_ether_opts` block (Fix [#572](https://github.com/jeremmfr/terraform-provider-junos/issues/572)) -* **data-source/junos_interface_physical**: add `mc_ae` block attribute in `parent_ether_opts` block - -BUG FIXES: - -* **data-source/junos_interface_physical**: fix reading `link_speed` and `minimum_bandwidth` attributes in `parent_ether_opts` block diff --git a/.changes/issue-573.md b/.changes/issue-573.md deleted file mode 100644 index 7b8ca30e..00000000 --- a/.changes/issue-573.md +++ /dev/null @@ -1,5 +0,0 @@ - -FEATURES: - -* add `junos_iccp` resource (Partial fix [#573](https://github.com/jeremmfr/terraform-provider-junos/issues/573)) -* add `junos_iccp_peer` resource (Partial fix [#573](https://github.com/jeremmfr/terraform-provider-junos/issues/573)) diff --git a/.changes/issue-574.md b/.changes/issue-574.md deleted file mode 100644 index 19e037d8..00000000 --- a/.changes/issue-574.md +++ /dev/null @@ -1,9 +0,0 @@ - -FEATURES: - -* add **junos_forwardingoptions_storm_control_profile** resource (Partial fix [#574](https://github.com/jeremmfr/terraform-provider-junos/issues/574)) - -ENHANCEMENTS: - -* **resource/junos_interface_physical**: add `storm_control` argument (Partial fix [#574](https://github.com/jeremmfr/terraform-provider-junos/issues/574)) -* **data-source/junos_interface_physical**: add `storm_control` attribute like resource diff --git a/.changes/issue-575.md b/.changes/issue-575.md deleted file mode 100644 index a5d7ccf9..00000000 --- a/.changes/issue-575.md +++ /dev/null @@ -1,7 +0,0 @@ - -ENHANCEMENTS: - -* **resource/junos_switch_options**: - * resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) - optional string attributes doesn't accept *empty* value - * add `service_id` argument (Fix [#575](https://github.com/jeremmfr/terraform-provider-junos/issues/575)) diff --git a/.changes/issue-576.md b/.changes/issue-576.md deleted file mode 100644 index 00c1589c..00000000 --- a/.changes/issue-576.md +++ /dev/null @@ -1,5 +0,0 @@ - -FEATURES: - -* add `junos_multichassis` resource (Partial fix [#576](https://github.com/jeremmfr/terraform-provider-junos/issues/576)) -* add `junos_multichassis_protection_peer` resource (Partial fix [#576](https://github.com/jeremmfr/terraform-provider-junos/issues/576)) diff --git a/.changes/issue-585.md b/.changes/issue-585.md deleted file mode 100644 index 017bfa4b..00000000 --- a/.changes/issue-585.md +++ /dev/null @@ -1,8 +0,0 @@ - -FEATURES: - -* add `commit_confirmed` and `commit_confirmed_wait_percent` provider argument to be able use `commit confirmed` feature to commit the resource actions (Fix [#585](https://github.com/jeremmfr/terraform-provider-junos/issues/585)) - -ENHANCEMENTS: - -* display all errors when configuration commit generate multiple errors diff --git a/.changes/issue-593.md b/.changes/issue-593.md deleted file mode 100644 index 9c725e84..00000000 --- a/.changes/issue-593.md +++ /dev/null @@ -1,20 +0,0 @@ - -FEATURES: - -* add `junos_system_syslog_user` resource (Fix [#593](https://github.com/jeremmfr/terraform-provider-junos/issues/593)) - -ENHANCEMENTS: - -* **resource/junos_system_syslog_file**: resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) - some of config errors are now sent during Plan instead of during Apply - optional boolean attributes doesn't accept value *false* - optional string attributes doesn't accept *empty* value - the resource schema has been upgraded to have one-blocks in single mode instead of list -* **resource/junos_system_syslog_host**: resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) - optional boolean attributes doesn't accept value *false* - optional string attributes doesn't accept *empty* value - the resource schema has been upgraded to have one-blocks in single mode instead of list - -BUG FIXES: - -* **resource/junos_system_syslog_file**: fix reading `archive size` when value is a multiple of 1024 (k,m,g) diff --git a/.changes/issue-594.md b/.changes/issue-594.md deleted file mode 100644 index 5321df80..00000000 --- a/.changes/issue-594.md +++ /dev/null @@ -1,4 +0,0 @@ - -ENHANCEMENTS: - -* **resource/junos_system**: add `web_management_session_idle_timeout` and `web_management_session_limit` arguments in `services` block (Fix [#594](https://github.com/jeremmfr/terraform-provider-junos/issues/594)) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae0d43f0..34d116af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,47 @@ # changelog +## v2.4.0 (December 21, 2023) + +FEATURES: + +* add **junos_forwardingoptions_storm_control_profile** resource (Partial fix [#574](https://github.com/jeremmfr/terraform-provider-junos/issues/574)) +* add **junos_iccp** resource (Partial fix [#573](https://github.com/jeremmfr/terraform-provider-junos/issues/573)) +* add **junos_iccp_peer** resource (Partial fix [#573](https://github.com/jeremmfr/terraform-provider-junos/issues/573)) +* add **junos_multichassis** resource (Partial fix [#576](https://github.com/jeremmfr/terraform-provider-junos/issues/576)) +* add **junos_multichassis_protection_peer** resource (Partial fix [#576](https://github.com/jeremmfr/terraform-provider-junos/issues/576)) +* add **junos_system_syslog_user** resource (Fix [#593](https://github.com/jeremmfr/terraform-provider-junos/issues/593)) +* **provider**: add `commit_confirmed` and `commit_confirmed_wait_percent` argument to be able use `commit confirmed` feature to commit the resource actions (Fix [#585](https://github.com/jeremmfr/terraform-provider-junos/issues/585)) + +ENHANCEMENTS: + +* **resource/junos_interface_physical**: + * add `mc_ae` block argument in `parent_ether_opts` block (Fix [#572](https://github.com/jeremmfr/terraform-provider-junos/issues/572)) + * add `storm_control` argument (Partial fix [#574](https://github.com/jeremmfr/terraform-provider-junos/issues/574)) +* **data-source/junos_interface_physical**: + * add `mc_ae` block attribute in `parent_ether_opts` block like resource + * add `storm_control` attribute like resource +* **resource/junos_switch_options**: + * resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) + optional string attributes doesn't accept *empty* value + * add `service_id` argument (Fix [#575](https://github.com/jeremmfr/terraform-provider-junos/issues/575)) +* **resource/junos_system**: add `web_management_session_idle_timeout` and `web_management_session_limit` arguments in `services` block (Fix [#594](https://github.com/jeremmfr/terraform-provider-junos/issues/594)) +* **resource/junos_system_syslog_file**: resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) + some of config errors are now sent during Plan instead of during Apply + optional boolean attributes doesn't accept value *false* + optional string attributes doesn't accept *empty* value + the resource schema has been upgraded to have one-blocks in single mode instead of list +* **resource/junos_system_syslog_host**: resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) + optional boolean attributes doesn't accept value *false* + optional string attributes doesn't accept *empty* value + the resource schema has been upgraded to have one-blocks in single mode instead of list +* **provider**: display all errors when configuration commit generate multiple errors + +BUG FIXES: + +* **data-source/junos_interface_physical**: fix reading `link_speed` and `minimum_bandwidth` attributes in `parent_ether_opts` block +* **resource/junos_system_syslog_file**: fix reading `archive size` when value is a multiple of 1024 (k,m,g) + ## v2.3.3 (December 07, 2023) BUG FIXES: