Skip to content

Commit

Permalink
New resource: azurerm_container_registry_cache_rule (#26034)
Browse files Browse the repository at this point in the history
* Add an SDK client for Cache Rules

* Synch vendor directory

* Generate parser and validator

* Verify the name of the cache rule

* Fix the vendor versions

* Fix the vendor versions

* Create and Read

* add registration and dummy test

* Adjust for the correct layout

* Fix the vendor versions

* remove unnecessary test

* feat: use container_registry_id as arg

* feat: return cacherules

* fix: formatting

* fix: test and deps

* more test fixes

* feat: improve registry ID parsing for cache resource

* feat: add docs for cache rule resource

* fix: cache rule resource docs

* fix: typo

* feat: add support for CredentialSetId

* fix: docs

* feat: add container_registry_cache_rule data source, as well as name validation on the resource

* feat: add container_registry_cache_rule data source docs

* fix: formatting

* Update internal/services/containers/client/client.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/client/client.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/client/client.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/client/client.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_data_source.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/resourceids.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_data_source.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource_test.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_data_source.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_data_source.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_data_source.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource_test.go

Co-authored-by: stephybun <steph@hashicorp.com>

* feat: update go dep files

* feat: use model struct for container_registry_cache_rule resource

* feat: validate credential set id

* Update internal/services/containers/container_registry_cache_rule_data_source.go

Co-authored-by: stephybun <steph@hashicorp.com>

* fix: vendor and formatting updates for cache_rule

* feat: use model encoding/decoding for cache rule resource

* feat: use CustomizeDiff to force rebuild and container registry update to empty

* fix: typo in resource diff logic for cache rule resource

* feat: update cache rule name regex, and add unit tests

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update website/docs/r/container_registry_cache_rule.html.markdown

Co-authored-by: stephybun <steph@hashicorp.com>

* Update website/docs/r/container_registry_cache_rule.html.markdown

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* fix: remove unused files for cache rule

* feat: remove obsolete TODO comments from cache rule resource

* fix: update go deps

* fix: linting and vendor modules

* fix: reinitialization of cache rule context

* fix: update vendor

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/containers/container_registry_cache_rule_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* fix: remove unused import

* fix: fmt

---------

Co-authored-by: Mateusz Haligowski <mhaligowski@gmail.com>
Co-authored-by: stephybun <steph@hashicorp.com>
  • Loading branch information
3 people committed May 30, 2024
1 parent 4515020 commit 8412693
Show file tree
Hide file tree
Showing 130 changed files with 6,056 additions and 3,151 deletions.
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

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

0 comments on commit 8412693

Please sign in to comment.