Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New resource: azurerm_container_registry_cache_rule #26034

Merged
merged 74 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
9a7b309
Add an SDK client for Cache Rules
mhaligowski Nov 27, 2023
f5d817b
Synch vendor directory
mhaligowski Nov 27, 2023
abb4211
Generate parser and validator
mhaligowski Nov 27, 2023
65cdac2
Verify the name of the cache rule
mhaligowski Nov 27, 2023
f122449
Fix the vendor versions
mhaligowski Nov 27, 2023
9441261
Fix the vendor versions
mhaligowski Nov 27, 2023
e30a431
Create and Read
mhaligowski Nov 27, 2023
c9066b3
add registration and dummy test
mhaligowski Nov 28, 2023
cd96b0a
Adjust for the correct layout
mhaligowski Dec 11, 2023
b382672
Fix the vendor versions
npk-amperon May 20, 2024
4d6bf92
remove unnecessary test
npk-amperon May 20, 2024
60fe246
feat: use container_registry_id as arg
npk-amperon May 20, 2024
be8ecd5
feat: return cacherules
npk-amperon May 20, 2024
8a93ba3
fix: formatting
npk-amperon May 20, 2024
876320e
fix: test and deps
npk-amperon May 20, 2024
b0718b1
more test fixes
npk-amperon May 20, 2024
6bba7a2
feat: improve registry ID parsing for cache resource
npk-amperon May 20, 2024
03e8319
feat: add docs for cache rule resource
npk-amperon May 20, 2024
b23458a
fix: cache rule resource docs
npk-amperon May 20, 2024
4ef3cf7
fix: typo
npk-amperon May 20, 2024
4cc5162
feat: add support for CredentialSetId
npk-amperon May 21, 2024
670fafa
fix: docs
npk-amperon May 21, 2024
54e09e4
feat: add container_registry_cache_rule data source, as well as name …
npk-amperon May 21, 2024
3b19cab
feat: add container_registry_cache_rule data source docs
npk-amperon May 21, 2024
254299a
fix: formatting
npk-amperon May 21, 2024
6a9980f
Update internal/services/containers/client/client.go
npk-amperon May 28, 2024
5bda934
Update internal/services/containers/client/client.go
npk-amperon May 28, 2024
04a24a2
Update internal/services/containers/client/client.go
npk-amperon May 28, 2024
838cd69
Update internal/services/containers/client/client.go
npk-amperon May 28, 2024
62b94ff
Update internal/services/containers/container_registry_cache_rule_dat…
npk-amperon May 28, 2024
eac13e8
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 28, 2024
aa880f5
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 28, 2024
81ad620
Update internal/services/containers/resourceids.go
npk-amperon May 28, 2024
d92a877
Update internal/services/containers/container_registry_cache_rule_dat…
npk-amperon May 28, 2024
c1b0667
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 28, 2024
8fe8f9e
Update internal/services/containers/container_registry_cache_rule_dat…
npk-amperon May 28, 2024
497ee73
Update internal/services/containers/container_registry_cache_rule_dat…
npk-amperon May 28, 2024
87c2f27
Update internal/services/containers/container_registry_cache_rule_dat…
npk-amperon May 28, 2024
bbb1065
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 28, 2024
080a4a5
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 28, 2024
7cf6ab3
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 28, 2024
a6f4d03
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 28, 2024
ddec6db
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 28, 2024
318ce10
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 28, 2024
9469850
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 28, 2024
251b135
feat: update go dep files
npk-amperon May 28, 2024
32c76f8
feat: use model struct for container_registry_cache_rule resource
npk-amperon May 28, 2024
02f0a2d
feat: validate credential set id
npk-amperon May 28, 2024
626a993
Update internal/services/containers/container_registry_cache_rule_dat…
npk-amperon May 28, 2024
1f54be6
fix: vendor and formatting updates for cache_rule
npk-amperon May 28, 2024
c1266b3
feat: use model encoding/decoding for cache rule resource
npk-amperon May 28, 2024
ee45bef
feat: use CustomizeDiff to force rebuild and container registry updat…
npk-amperon May 28, 2024
0172fc6
fix: typo in resource diff logic for cache rule resource
npk-amperon May 29, 2024
e5a4c8f
feat: update cache rule name regex, and add unit tests
npk-amperon May 29, 2024
1242f54
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 29, 2024
d54c215
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 29, 2024
cbc86fd
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 29, 2024
a53e585
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 29, 2024
c8001df
Update website/docs/r/container_registry_cache_rule.html.markdown
npk-amperon May 29, 2024
1ed9e84
Update website/docs/r/container_registry_cache_rule.html.markdown
npk-amperon May 29, 2024
589352f
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 29, 2024
40e7c02
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 29, 2024
b96bc19
fix: remove unused files for cache rule
npk-amperon May 29, 2024
f641de6
feat: remove obsolete TODO comments from cache rule resource
npk-amperon May 29, 2024
b4e6f88
fix: update go deps
npk-amperon May 29, 2024
3f6ae05
fix: linting and vendor modules
npk-amperon May 29, 2024
827c7d3
fix: reinitialization of cache rule context
npk-amperon May 29, 2024
0b7520e
fix: update vendor
npk-amperon May 29, 2024
69448a8
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 30, 2024
673946b
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 30, 2024
f3a0ffa
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 30, 2024
bf6bdea
Update internal/services/containers/container_registry_cache_rule_res…
npk-amperon May 30, 2024
51199ef
fix: remove unused import
npk-amperon May 30, 2024
4f0806e
fix: fmt
npk-amperon May 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
github.com/tombuildsstuff/giovanni v0.27.0
github.com/tombuildsstuff/kermit v0.20240122.1123108
golang.org/x/crypto v0.21.0
golang.org/x/tools v0.13.0
golang.org/x/tools v0.19.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -53,7 +53,7 @@ require (
github.com/hashicorp/go-plugin v1.5.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/hashicorp/hc-install v0.6.0 // indirect
github.com/hashicorp/hcl/v2 v2.18.0 // indirect
github.com/hashicorp/hcl/v2 v2.20.0 // indirect
github.com/hashicorp/hcl2 v0.0.0-20191002203319-fb75b3253c80 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.19.0 // indirect
Expand All @@ -63,7 +63,7 @@ require (
github.com/hashicorp/terraform-registry-address v0.2.2 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand All @@ -76,9 +76,9 @@ require (
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // 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.3 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sys v0.18.0 // indirect
Expand Down
26 changes: 15 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mO
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/hcl/v2 v2.20.0 h1:l++cRs/5jQOiKVvqXZm/P1ZEfVXJmvLS9WSVxkaeTb4=
github.com/hashicorp/hcl/v2 v2.20.0/go.mod h1:WmcD/Ym72MDOOx5F62Ly+leloeu6H7m0pG7VBiU6pQk=
github.com/hashicorp/hcl2 v0.0.0-20191002203319-fb75b3253c80 h1:PFfGModn55JA0oBsvFghhj0v93me+Ctr3uHC/UmFAls=
github.com/hashicorp/hcl2 v0.0.0-20191002203319-fb75b3253c80/go.mod h1:Cxv+IJLuBiEhQ7pBYGEuORa0nr4U994pE8mYLuFd7v0=
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
Expand Down Expand Up @@ -156,8 +156,9 @@ github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gav
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down Expand Up @@ -204,6 +205,8 @@ github.com/rickb777/date v1.12.5-0.20200422084442-6300e543c4d9/go.mod h1:L8WrssT
github.com/rickb777/plural v1.2.0/go.mod h1:UdpyWFCGbo3mvK3f/PfZOAOrkjzJlYN/sD46XNWJ+Es=
github.com/rickb777/plural v1.4.1 h1:5MMLcbIaapLFmvDGRT5iPk8877hpTPt8Y9cdSKRw9sU=
github.com/rickb777/plural v1.4.1/go.mod h1:kdmXUpmKBJTS0FtG/TFumd//VBWsNTD7zOw7x4umxNw=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
Expand Down Expand Up @@ -241,8 +244,8 @@ github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
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.3 h1:1JXy1XroaGrzZuG6X9dt7HL6s9AwbY+l4UNL8o5B6ho=
github.com/zclconf/go-cty v1.14.3/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-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand All @@ -258,8 +261,8 @@ golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqR
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
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.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -282,8 +285,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -330,8 +333,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand All @@ -352,6 +355,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
Expand Down
9 changes: 9 additions & 0 deletions internal/services/containers/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/containerinstance/2023-05-01/containerinstance"
containerregistry_v2019_06_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2019-06-01-preview"
containerregistry_v2021_08_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-07-01/cacherules"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2019-08-01/containerservices"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-09-02-preview/agentpools"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-09-02-preview/maintenanceconfigurations"
Expand All @@ -26,6 +27,7 @@ import (
type Client struct {
AgentPoolsClient *agentpools.AgentPoolsClient
ContainerInstanceClient *containerinstance.ContainerInstanceClient
CacheRulesClient *cacherules.CacheRulesClient
ContainerRegistryClient_v2021_08_01_preview *containerregistry_v2021_08_01_preview.Client
// v2019_06_01_preview is needed for container registry agent pools and tasks
ContainerRegistryClient_v2019_06_01_preview *containerregistry_v2019_06_01_preview.Client
Expand Down Expand Up @@ -61,6 +63,12 @@ func NewContainersClient(o *common.ClientOptions) (*Client, error) {
return nil, err
}

cacheRulesClient, err := cacherules.NewCacheRulesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Cache Rules client: %+v", err)
}
o.Configure(cacheRulesClient.Client, o.Authorizers.ResourceManager)

// AKS
fleetUpdateRunsClient, err := updateruns.NewUpdateRunsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
Expand Down Expand Up @@ -119,6 +127,7 @@ func NewContainersClient(o *common.ClientOptions) (*Client, error) {
return &Client{
AgentPoolsClient: agentPoolsClient,
ContainerInstanceClient: containerInstanceClient,
CacheRulesClient: cacheRulesClient,
ContainerRegistryClient_v2021_08_01_preview: containerRegistryClient_v2021_08_01_preview,
ContainerRegistryClient_v2019_06_01_preview: containerRegistryClient_v2019_06_01_preview,
FleetUpdateRunsClient: fleetUpdateRunsClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package containers

import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview/registries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-07-01/cacherules"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

type ContainerRegistryCacheRuleDataSource struct{}

func (ContainerRegistryCacheRuleDataSource) ResourceType() string {
return "azurerm_container_registry_cache_rule"
}

func (ContainerRegistryCacheRuleDataSource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,

Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.Containers.CacheRulesClient
subscriptionId := metadata.Client.Account.SubscriptionId

npk-amperon marked this conversation as resolved.
Show resolved Hide resolved
var state ContainerRegistryCacheRuleDataSourceModel
if err := metadata.Decode(&state); err != nil {
return err
}

registryId, err := registries.ParseRegistryID(metadata.ResourceData.Get("container_registry_id").(string))
if err != nil {
return err
}

id := cacherules.NewCacheRuleID(subscriptionId, registryId.ResourceGroupName, registryId.RegistryName, metadata.ResourceData.Get("name").(string))

resp, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}

return fmt.Errorf("retrieving %s: %+v", id, err)
}

metadata.SetID(id)
state.Name = id.CacheRuleName
state.ContainerRegistryId = registryId.ID()

if model := resp.Model; model != nil {
if props := model.Properties; props != nil {
state.SourceRepo = pointer.From(props.SourceRepository)
state.TargetRepo = pointer.From(props.TargetRepository)
state.CredentialSetId = pointer.From(props.CredentialSetResourceId)
}
}
return metadata.Encode(&state)
},
}
}

type ContainerRegistryCacheRuleDataSourceModel struct {
Name string `tfschema:"name"`
ContainerRegistryId string `tfschema:"container_registry_id"`
CredentialSetId string `tfschema:"credential_set_id"`
SourceRepo string `tfschema:"source_repo"`
TargetRepo string `tfschema:"target_repo"`
}

func (ContainerRegistryCacheRuleDataSource) ModelObject() interface{} {
return &ContainerRegistryCacheRuleDataSourceModel{}
}

func (ContainerRegistryCacheRuleDataSource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.ContainerRegistryCacheRuleName,
},
"container_registry_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: registries.ValidateRegistryID,
},
}
}

func (ContainerRegistryCacheRuleDataSource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"credential_set_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
"source_repo": {
Type: pluginsdk.TypeString,
Computed: true,
},

"target_repo": {
Type: pluginsdk.TypeString,
Computed: true,
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package containers_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
)

type ContainerRegistryCacheRuleDataSource struct{}

func TestAccDataSourceAzureRMContainerRegistryCacheRule_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_container_registry_cache_rule", "test")
r := ContainerRegistryCacheRuleDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("name").Exists(),
check.That(data.ResourceName).Key("container_registry_id").Exists(),
check.That(data.ResourceName).Key("source_repo").Exists(),
check.That(data.ResourceName).Key("target_repo").Exists(),
),
},
})
}

func (ContainerRegistryCacheRuleDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

data "azurerm_container_registry_cache_rule" "test" {
name = azurerm_container_registry_cache_rule.test.name
container_registry_id = azurerm_container_registry_cache_rule.test.container_registry_id
}
`, ContainerRegistryCacheRuleResource{}.basic(data))
}
Loading
Loading