Skip to content

Commit

Permalink
New Resources: Shared Image Galleries (#1987)
Browse files Browse the repository at this point in the history
* Registeringg the Image Galleries clients

* Validation for Shared Image Versions

```
$ go test -v ./azurerm/helpers/validate/
=== RUN   TestSharedImageGalleryName
=== RUN   TestSharedImageGalleryName/#00
=== RUN   TestSharedImageGalleryName/a.b.c
=== RUN   TestSharedImageGalleryName/1.2.3
=== RUN   TestSharedImageGalleryName/0.0.1
=== RUN   TestSharedImageGalleryName/hello
=== RUN   TestSharedImageGalleryName/1.2.3.4
=== RUN   TestSharedImageGalleryName/hell0-there
--- PASS: TestSharedImageGalleryName (0.00s)
    --- PASS: TestSharedImageGalleryName/#00 (0.00s)
    --- PASS: TestSharedImageGalleryName/a.b.c (0.00s)
    --- PASS: TestSharedImageGalleryName/1.2.3 (0.00s)
    --- PASS: TestSharedImageGalleryName/0.0.1 (0.00s)
    --- PASS: TestSharedImageGalleryName/hello (0.00s)
    --- PASS: TestSharedImageGalleryName/1.2.3.4 (0.00s)
    --- PASS: TestSharedImageGalleryName/hell0-there (0.00s)
=== RUN   TestIPv4Address
=== RUN   TestIPv4Address/#00
=== RUN   TestIPv4Address/0.0.0.0
=== RUN   TestIPv4Address/1.2.3.no
=== RUN   TestIPv4Address/text
=== RUN   TestIPv4Address/1.2.3.4
=== RUN   TestIPv4Address/12.34.43.21
=== RUN   TestIPv4Address/100.123.199.0
=== RUN   TestIPv4Address/255.255.255.255
--- PASS: TestIPv4Address (0.00s)
    --- PASS: TestIPv4Address/#00 (0.00s)
    --- PASS: TestIPv4Address/0.0.0.0 (0.00s)
    --- PASS: TestIPv4Address/1.2.3.no (0.00s)
    --- PASS: TestIPv4Address/text (0.00s)
    --- PASS: TestIPv4Address/1.2.3.4 (0.00s)
    --- PASS: TestIPv4Address/12.34.43.21 (0.00s)
    --- PASS: TestIPv4Address/100.123.199.0 (0.00s)
    --- PASS: TestIPv4Address/255.255.255.255 (0.00s)
=== RUN   TestIPv4AddressOrEmpty
=== RUN   TestIPv4AddressOrEmpty/#00
=== RUN   TestIPv4AddressOrEmpty/0.0.0.0
=== RUN   TestIPv4AddressOrEmpty/1.2.3.no
=== RUN   TestIPv4AddressOrEmpty/text
=== RUN   TestIPv4AddressOrEmpty/1.2.3.4
=== RUN   TestIPv4AddressOrEmpty/12.34.43.21
=== RUN   TestIPv4AddressOrEmpty/100.123.199.0
=== RUN   TestIPv4AddressOrEmpty/255.255.255.255
--- PASS: TestIPv4AddressOrEmpty (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/#00 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/0.0.0.0 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/1.2.3.no (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/text (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/1.2.3.4 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/12.34.43.21 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/100.123.199.0 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/255.255.255.255 (0.00s)
=== RUN   TestMACAddress
=== RUN   TestMACAddress/#00
=== RUN   TestMACAddress/text_d
=== RUN   TestMACAddress/12:34:no
=== RUN   TestMACAddress/123:34:56:78:90:ab
=== RUN   TestMACAddress/12:34:56:78:90:NO
=== RUN   TestMACAddress/12:34:56:78:90:ab
=== RUN   TestMACAddress/ab:cd:ef:AB:CD:EF
--- PASS: TestMACAddress (0.00s)
    --- PASS: TestMACAddress/#00 (0.00s)
    --- PASS: TestMACAddress/text_d (0.00s)
    --- PASS: TestMACAddress/12:34:no (0.00s)
    --- PASS: TestMACAddress/123:34:56:78:90:ab (0.00s)
    --- PASS: TestMACAddress/12:34:56:78:90:NO (0.00s)
    --- PASS: TestMACAddress/12:34:56:78:90:ab (0.00s)
    --- PASS: TestMACAddress/ab:cd:ef:AB:CD:EF (0.00s)
=== RUN   TestPortNumber
=== RUN   TestPortNumber/-1
=== RUN   TestPortNumber/0
=== RUN   TestPortNumber/1
=== RUN   TestPortNumber/8477
=== RUN   TestPortNumber/65535
=== RUN   TestPortNumber/65536
=== RUN   TestPortNumber/7000000
--- PASS: TestPortNumber (0.00s)
    --- PASS: TestPortNumber/-1 (0.00s)
    --- PASS: TestPortNumber/0 (0.00s)
    --- PASS: TestPortNumber/1 (0.00s)
    --- PASS: TestPortNumber/8477 (0.00s)
    --- PASS: TestPortNumber/65535 (0.00s)
    --- PASS: TestPortNumber/65536 (0.00s)
    --- PASS: TestPortNumber/7000000 (0.00s)
=== RUN   TestPortNumberOrZero
=== RUN   TestPortNumberOrZero/-1
=== RUN   TestPortNumberOrZero/0
=== RUN   TestPortNumberOrZero/1
=== RUN   TestPortNumberOrZero/8477
=== RUN   TestPortNumberOrZero/65535
=== RUN   TestPortNumberOrZero/65536
=== RUN   TestPortNumberOrZero/7000000
--- PASS: TestPortNumberOrZero (0.00s)
    --- PASS: TestPortNumberOrZero/-1 (0.00s)
    --- PASS: TestPortNumberOrZero/0 (0.00s)
    --- PASS: TestPortNumberOrZero/1 (0.00s)
    --- PASS: TestPortNumberOrZero/8477 (0.00s)
    --- PASS: TestPortNumberOrZero/65535 (0.00s)
    --- PASS: TestPortNumberOrZero/65536 (0.00s)
    --- PASS: TestPortNumberOrZero/7000000 (0.00s)
=== RUN   TestRFC3339Time
=== RUN   TestRFC3339Time/#00
=== RUN   TestRFC3339Time/this_is_not_a_date
=== RUN   TestRFC3339Time/2000-01-01
=== RUN   TestRFC3339Time/2000-01-01T01:23:45
=== RUN   TestRFC3339Time/2000-01-01T01:23:45Z
=== RUN   TestRFC3339Time/2000-01-01T01:23:45+00:00
--- PASS: TestRFC3339Time (0.00s)
    --- PASS: TestRFC3339Time/#00 (0.00s)
    --- PASS: TestRFC3339Time/this_is_not_a_date (0.00s)
    --- PASS: TestRFC3339Time/2000-01-01 (0.00s)
    --- PASS: TestRFC3339Time/2000-01-01T01:23:45 (0.00s)
    --- PASS: TestRFC3339Time/2000-01-01T01:23:45Z (0.00s)
    --- PASS: TestRFC3339Time/2000-01-01T01:23:45+00:00 (0.00s)
=== RUN   TestRfc3339DateInFutureBy
=== RUN   TestRfc3339DateInFutureBy/empty
=== RUN   TestRfc3339DateInFutureBy/not_a_time
=== RUN   TestRfc3339DateInFutureBy/now_is_not_1_hour_ahead
=== RUN   TestRfc3339DateInFutureBy/now_+_7_hours_is_not_1_hour_ahead
=== RUN   TestRfc3339DateInFutureBy/now_+_7_min_is_7_min_ahead
=== RUN   TestRfc3339DateInFutureBy/now_+_8_min_is_at_least_7_min_ahead
--- PASS: TestRfc3339DateInFutureBy (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/empty (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/not_a_time (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/now_is_not_1_hour_ahead (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/now_+_7_hours_is_not_1_hour_ahead (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/now_+_7_min_is_7_min_ahead (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/now_+_8_min_is_at_least_7_min_ahead (0.00s)
=== RUN   TestURLIsHTTPS
=== RUN   TestURLIsHTTPS/#00
=== RUN   TestURLIsHTTPS/this_is_not_a_url
=== RUN   TestURLIsHTTPS/www.example.com
=== RUN   TestURLIsHTTPS/ftp://www.example.com
=== RUN   TestURLIsHTTPS/http://www.example.com
=== RUN   TestURLIsHTTPS/https://www.example.com
--- PASS: TestURLIsHTTPS (0.00s)
    --- PASS: TestURLIsHTTPS/#00 (0.00s)
    --- PASS: TestURLIsHTTPS/this_is_not_a_url (0.00s)
    --- PASS: TestURLIsHTTPS/www.example.com (0.00s)
    --- PASS: TestURLIsHTTPS/ftp://www.example.com (0.00s)
    --- PASS: TestURLIsHTTPS/http://www.example.com (0.00s)
    --- PASS: TestURLIsHTTPS/https://www.example.com (0.00s)
=== RUN   TestURLIsHTTPOrHTTPS
=== RUN   TestURLIsHTTPOrHTTPS/#00
=== RUN   TestURLIsHTTPOrHTTPS/this_is_not_a_url
=== RUN   TestURLIsHTTPOrHTTPS/www.example.com
=== RUN   TestURLIsHTTPOrHTTPS/ftp://www.example.com
=== RUN   TestURLIsHTTPOrHTTPS/http://www.example.com
=== RUN   TestURLIsHTTPOrHTTPS/https://www.example.com
--- PASS: TestURLIsHTTPOrHTTPS (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/#00 (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/this_is_not_a_url (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/www.example.com (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/ftp://www.example.com (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/http://www.example.com (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/https://www.example.com (0.00s)
=== RUN   TestUUID
=== RUN   TestUUID/#00
=== RUN   TestUUID/hello-world
=== RUN   TestUUID/00000000-0000-111-0000-000000000000
=== RUN   TestUUID/00000000-0000-0000-0000-000000000000
--- PASS: TestUUID (0.00s)
    --- PASS: TestUUID/#00 (0.00s)
    --- PASS: TestUUID/hello-world (0.00s)
    --- PASS: TestUUID/00000000-0000-111-0000-000000000000 (0.00s)
    --- PASS: TestUUID/00000000-0000-0000-0000-000000000000 (0.00s)
=== RUN   TestUrlWithScheme
=== RUN   TestUrlWithScheme/TestUrlWithScheme
--- PASS: TestUrlWithScheme (0.00s)
    --- PASS: TestUrlWithScheme/TestUrlWithScheme (0.00s)
=== RUN   TestVirtualNetworkRule_invalidNameValidation
--- PASS: TestVirtualNetworkRule_invalidNameValidation (0.00s)
=== RUN   TestResourceAzureRMPostgreSQLVirtualNetworkRule_validNameValidation
--- PASS: TestResourceAzureRMPostgreSQLVirtualNetworkRule_validNameValidation (0.00s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate	0.620s
```

* Validation for the Shared Image Gallery Name

```
$ go test -v ./azurerm/helpers/validate/
=== RUN   TestSharedImageGalleryName
=== RUN   TestSharedImageGalleryName/#00
=== RUN   TestSharedImageGalleryName/hello
=== RUN   TestSharedImageGalleryName/hello123
=== RUN   TestSharedImageGalleryName/hello.123
=== RUN   TestSharedImageGalleryName/hello,123
=== RUN   TestSharedImageGalleryName/hello_123
=== RUN   TestSharedImageGalleryName/hello-123
=== RUN   TestSharedImageGalleryName/eg0jovd9ln1m19flbdq429qsxpfh0hhn0hqqhwyaysmq8gyylzghgmwfdvgoxyqib6a8hyq1hpnhlyx
=== RUN   TestSharedImageGalleryName/inaamas6mjs23tax4k62ace3c0cuatutqr47zutxhj26jp4ih1x7ks7bc6mtor6vqx0snj71djj1p2ze
--- PASS: TestSharedImageGalleryName (0.00s)
    --- PASS: TestSharedImageGalleryName/#00 (0.00s)
    --- PASS: TestSharedImageGalleryName/hello (0.00s)
    --- PASS: TestSharedImageGalleryName/hello123 (0.00s)
    --- PASS: TestSharedImageGalleryName/hello.123 (0.00s)
    --- PASS: TestSharedImageGalleryName/hello,123 (0.00s)
    --- PASS: TestSharedImageGalleryName/hello_123 (0.00s)
    --- PASS: TestSharedImageGalleryName/hello-123 (0.00s)
    --- PASS: TestSharedImageGalleryName/eg0jovd9ln1m19flbdq429qsxpfh0hhn0hqqhwyaysmq8gyylzghgmwfdvgoxyqib6a8hyq1hpnhlyx (0.00s)
    --- PASS: TestSharedImageGalleryName/inaamas6mjs23tax4k62ace3c0cuatutqr47zutxhj26jp4ih1x7ks7bc6mtor6vqx0snj71djj1p2ze (0.00s)
=== RUN   TestSharedImageVersionName
=== RUN   TestSharedImageVersionName/#00
=== RUN   TestSharedImageVersionName/a.b.c
=== RUN   TestSharedImageVersionName/1.2.3
=== RUN   TestSharedImageVersionName/0.0.1
=== RUN   TestSharedImageVersionName/hello
=== RUN   TestSharedImageVersionName/1.2.3.4
=== RUN   TestSharedImageVersionName/hell0-there
--- PASS: TestSharedImageVersionName (0.00s)
    --- PASS: TestSharedImageVersionName/#00 (0.00s)
    --- PASS: TestSharedImageVersionName/a.b.c (0.00s)
    --- PASS: TestSharedImageVersionName/1.2.3 (0.00s)
    --- PASS: TestSharedImageVersionName/0.0.1 (0.00s)
    --- PASS: TestSharedImageVersionName/hello (0.00s)
    --- PASS: TestSharedImageVersionName/1.2.3.4 (0.00s)
    --- PASS: TestSharedImageVersionName/hell0-there (0.00s)
=== RUN   TestIPv4Address
=== RUN   TestIPv4Address/#00
=== RUN   TestIPv4Address/0.0.0.0
=== RUN   TestIPv4Address/1.2.3.no
=== RUN   TestIPv4Address/text
=== RUN   TestIPv4Address/1.2.3.4
=== RUN   TestIPv4Address/12.34.43.21
=== RUN   TestIPv4Address/100.123.199.0
=== RUN   TestIPv4Address/255.255.255.255
--- PASS: TestIPv4Address (0.00s)
    --- PASS: TestIPv4Address/#00 (0.00s)
    --- PASS: TestIPv4Address/0.0.0.0 (0.00s)
    --- PASS: TestIPv4Address/1.2.3.no (0.00s)
    --- PASS: TestIPv4Address/text (0.00s)
    --- PASS: TestIPv4Address/1.2.3.4 (0.00s)
    --- PASS: TestIPv4Address/12.34.43.21 (0.00s)
    --- PASS: TestIPv4Address/100.123.199.0 (0.00s)
    --- PASS: TestIPv4Address/255.255.255.255 (0.00s)
=== RUN   TestIPv4AddressOrEmpty
=== RUN   TestIPv4AddressOrEmpty/#00
=== RUN   TestIPv4AddressOrEmpty/0.0.0.0
=== RUN   TestIPv4AddressOrEmpty/1.2.3.no
=== RUN   TestIPv4AddressOrEmpty/text
=== RUN   TestIPv4AddressOrEmpty/1.2.3.4
=== RUN   TestIPv4AddressOrEmpty/12.34.43.21
=== RUN   TestIPv4AddressOrEmpty/100.123.199.0
=== RUN   TestIPv4AddressOrEmpty/255.255.255.255
--- PASS: TestIPv4AddressOrEmpty (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/#00 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/0.0.0.0 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/1.2.3.no (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/text (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/1.2.3.4 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/12.34.43.21 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/100.123.199.0 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/255.255.255.255 (0.00s)
=== RUN   TestMACAddress
=== RUN   TestMACAddress/#00
=== RUN   TestMACAddress/text_d
=== RUN   TestMACAddress/12:34:no
=== RUN   TestMACAddress/123:34:56:78:90:ab
=== RUN   TestMACAddress/12:34:56:78:90:NO
=== RUN   TestMACAddress/12:34:56:78:90:ab
=== RUN   TestMACAddress/ab:cd:ef:AB:CD:EF
--- PASS: TestMACAddress (0.00s)
    --- PASS: TestMACAddress/#00 (0.00s)
    --- PASS: TestMACAddress/text_d (0.00s)
    --- PASS: TestMACAddress/12:34:no (0.00s)
    --- PASS: TestMACAddress/123:34:56:78:90:ab (0.00s)
    --- PASS: TestMACAddress/12:34:56:78:90:NO (0.00s)
    --- PASS: TestMACAddress/12:34:56:78:90:ab (0.00s)
    --- PASS: TestMACAddress/ab:cd:ef:AB:CD:EF (0.00s)
=== RUN   TestPortNumber
=== RUN   TestPortNumber/-1
=== RUN   TestPortNumber/0
=== RUN   TestPortNumber/1
=== RUN   TestPortNumber/8477
=== RUN   TestPortNumber/65535
=== RUN   TestPortNumber/65536
=== RUN   TestPortNumber/7000000
--- PASS: TestPortNumber (0.00s)
    --- PASS: TestPortNumber/-1 (0.00s)
    --- PASS: TestPortNumber/0 (0.00s)
    --- PASS: TestPortNumber/1 (0.00s)
    --- PASS: TestPortNumber/8477 (0.00s)
    --- PASS: TestPortNumber/65535 (0.00s)
    --- PASS: TestPortNumber/65536 (0.00s)
    --- PASS: TestPortNumber/7000000 (0.00s)
=== RUN   TestPortNumberOrZero
=== RUN   TestPortNumberOrZero/-1
=== RUN   TestPortNumberOrZero/0
=== RUN   TestPortNumberOrZero/1
=== RUN   TestPortNumberOrZero/8477
=== RUN   TestPortNumberOrZero/65535
=== RUN   TestPortNumberOrZero/65536
=== RUN   TestPortNumberOrZero/7000000
--- PASS: TestPortNumberOrZero (0.00s)
    --- PASS: TestPortNumberOrZero/-1 (0.00s)
    --- PASS: TestPortNumberOrZero/0 (0.00s)
    --- PASS: TestPortNumberOrZero/1 (0.00s)
    --- PASS: TestPortNumberOrZero/8477 (0.00s)
    --- PASS: TestPortNumberOrZero/65535 (0.00s)
    --- PASS: TestPortNumberOrZero/65536 (0.00s)
    --- PASS: TestPortNumberOrZero/7000000 (0.00s)
=== RUN   TestRFC3339Time
=== RUN   TestRFC3339Time/#00
=== RUN   TestRFC3339Time/this_is_not_a_date
=== RUN   TestRFC3339Time/2000-01-01
=== RUN   TestRFC3339Time/2000-01-01T01:23:45
=== RUN   TestRFC3339Time/2000-01-01T01:23:45Z
=== RUN   TestRFC3339Time/2000-01-01T01:23:45+00:00
--- PASS: TestRFC3339Time (0.00s)
    --- PASS: TestRFC3339Time/#00 (0.00s)
    --- PASS: TestRFC3339Time/this_is_not_a_date (0.00s)
    --- PASS: TestRFC3339Time/2000-01-01 (0.00s)
    --- PASS: TestRFC3339Time/2000-01-01T01:23:45 (0.00s)
    --- PASS: TestRFC3339Time/2000-01-01T01:23:45Z (0.00s)
    --- PASS: TestRFC3339Time/2000-01-01T01:23:45+00:00 (0.00s)
=== RUN   TestRfc3339DateInFutureBy
=== RUN   TestRfc3339DateInFutureBy/empty
=== RUN   TestRfc3339DateInFutureBy/not_a_time
=== RUN   TestRfc3339DateInFutureBy/now_is_not_1_hour_ahead
=== RUN   TestRfc3339DateInFutureBy/now_+_7_hours_is_not_1_hour_ahead
=== RUN   TestRfc3339DateInFutureBy/now_+_7_min_is_7_min_ahead
=== RUN   TestRfc3339DateInFutureBy/now_+_8_min_is_at_least_7_min_ahead
--- PASS: TestRfc3339DateInFutureBy (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/empty (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/not_a_time (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/now_is_not_1_hour_ahead (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/now_+_7_hours_is_not_1_hour_ahead (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/now_+_7_min_is_7_min_ahead (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/now_+_8_min_is_at_least_7_min_ahead (0.00s)
=== RUN   TestURLIsHTTPS
=== RUN   TestURLIsHTTPS/#00
=== RUN   TestURLIsHTTPS/this_is_not_a_url
=== RUN   TestURLIsHTTPS/www.example.com
=== RUN   TestURLIsHTTPS/ftp://www.example.com
=== RUN   TestURLIsHTTPS/http://www.example.com
=== RUN   TestURLIsHTTPS/https://www.example.com
--- PASS: TestURLIsHTTPS (0.00s)
    --- PASS: TestURLIsHTTPS/#00 (0.00s)
    --- PASS: TestURLIsHTTPS/this_is_not_a_url (0.00s)
    --- PASS: TestURLIsHTTPS/www.example.com (0.00s)
    --- PASS: TestURLIsHTTPS/ftp://www.example.com (0.00s)
    --- PASS: TestURLIsHTTPS/http://www.example.com (0.00s)
    --- PASS: TestURLIsHTTPS/https://www.example.com (0.00s)
=== RUN   TestURLIsHTTPOrHTTPS
=== RUN   TestURLIsHTTPOrHTTPS/#00
=== RUN   TestURLIsHTTPOrHTTPS/this_is_not_a_url
=== RUN   TestURLIsHTTPOrHTTPS/www.example.com
=== RUN   TestURLIsHTTPOrHTTPS/ftp://www.example.com
=== RUN   TestURLIsHTTPOrHTTPS/http://www.example.com
=== RUN   TestURLIsHTTPOrHTTPS/https://www.example.com
--- PASS: TestURLIsHTTPOrHTTPS (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/#00 (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/this_is_not_a_url (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/www.example.com (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/ftp://www.example.com (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/http://www.example.com (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/https://www.example.com (0.00s)
=== RUN   TestUUID
=== RUN   TestUUID/#00
=== RUN   TestUUID/hello-world
=== RUN   TestUUID/00000000-0000-111-0000-000000000000
=== RUN   TestUUID/00000000-0000-0000-0000-000000000000
--- PASS: TestUUID (0.00s)
    --- PASS: TestUUID/#00 (0.00s)
    --- PASS: TestUUID/hello-world (0.00s)
    --- PASS: TestUUID/00000000-0000-111-0000-000000000000 (0.00s)
    --- PASS: TestUUID/00000000-0000-0000-0000-000000000000 (0.00s)
=== RUN   TestUrlWithScheme
=== RUN   TestUrlWithScheme/TestUrlWithScheme
--- PASS: TestUrlWithScheme (0.00s)
    --- PASS: TestUrlWithScheme/TestUrlWithScheme (0.00s)
=== RUN   TestVirtualNetworkRule_invalidNameValidation
--- PASS: TestVirtualNetworkRule_invalidNameValidation (0.00s)
=== RUN   TestResourceAzureRMPostgreSQLVirtualNetworkRule_validNameValidation
--- PASS: TestResourceAzureRMPostgreSQLVirtualNetworkRule_validNameValidation (0.00s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate	0.619s
```

* Validation for the Shared Image name

```
$ go test -v ./azurerm/helpers/validate/
=== RUN   TestSharedImageGalleryName
=== RUN   TestSharedImageGalleryName/#00
=== RUN   TestSharedImageGalleryName/hello
=== RUN   TestSharedImageGalleryName/hello123
=== RUN   TestSharedImageGalleryName/hello.123
=== RUN   TestSharedImageGalleryName/hello,123
=== RUN   TestSharedImageGalleryName/hello_123
=== RUN   TestSharedImageGalleryName/hello-123
=== RUN   TestSharedImageGalleryName/0xfbkai7139qjtelz8ngjk6128zlyho7qgtar8tk3wcygv2iyyrych0n4wx71bgtrywu9wgpusexvjv
=== RUN   TestSharedImageGalleryName/xa0t9ibyph7ydmewrdqlm7mc2tyhibxbzne00u30d8xli4mzbvr7rozuvklaekx3il43gqienkhmb7n0
--- PASS: TestSharedImageGalleryName (0.00s)
    --- PASS: TestSharedImageGalleryName/#00 (0.00s)
    --- PASS: TestSharedImageGalleryName/hello (0.00s)
    --- PASS: TestSharedImageGalleryName/hello123 (0.00s)
    --- PASS: TestSharedImageGalleryName/hello.123 (0.00s)
    --- PASS: TestSharedImageGalleryName/hello,123 (0.00s)
    --- PASS: TestSharedImageGalleryName/hello_123 (0.00s)
    --- PASS: TestSharedImageGalleryName/hello-123 (0.00s)
    --- PASS: TestSharedImageGalleryName/0xfbkai7139qjtelz8ngjk6128zlyho7qgtar8tk3wcygv2iyyrych0n4wx71bgtrywu9wgpusexvjv (0.00s)
    --- PASS: TestSharedImageGalleryName/xa0t9ibyph7ydmewrdqlm7mc2tyhibxbzne00u30d8xli4mzbvr7rozuvklaekx3il43gqienkhmb7n0 (0.00s)
=== RUN   TestSharedImageName
=== RUN   TestSharedImageName/#00
=== RUN   TestSharedImageName/hello
=== RUN   TestSharedImageName/hello123
=== RUN   TestSharedImageName/hello.123
=== RUN   TestSharedImageName/hello,123
=== RUN   TestSharedImageName/hello_123
=== RUN   TestSharedImageName/hello-123
=== RUN   TestSharedImageName/f0pe3ko7waqqzov1prgmsa16a11aob8ajmv8vvp399aqodr4uvizrj9hocuakghol9gbyfzedk9jci7
=== RUN   TestSharedImageName/j20heqhz242rm9crh3ex6lib013gmh2yknt2bj81cv6mzissfmj0uqevrx4rrygxp0cytpmei88w9962
--- PASS: TestSharedImageName (0.00s)
    --- PASS: TestSharedImageName/#00 (0.00s)
    --- PASS: TestSharedImageName/hello (0.00s)
    --- PASS: TestSharedImageName/hello123 (0.00s)
    --- PASS: TestSharedImageName/hello.123 (0.00s)
    --- PASS: TestSharedImageName/hello,123 (0.00s)
    --- PASS: TestSharedImageName/hello_123 (0.00s)
    --- PASS: TestSharedImageName/hello-123 (0.00s)
    --- PASS: TestSharedImageName/f0pe3ko7waqqzov1prgmsa16a11aob8ajmv8vvp399aqodr4uvizrj9hocuakghol9gbyfzedk9jci7 (0.00s)
    --- PASS: TestSharedImageName/j20heqhz242rm9crh3ex6lib013gmh2yknt2bj81cv6mzissfmj0uqevrx4rrygxp0cytpmei88w9962 (0.00s)
=== RUN   TestSharedImageVersionName
=== RUN   TestSharedImageVersionName/#00
=== RUN   TestSharedImageVersionName/a.b.c
=== RUN   TestSharedImageVersionName/1.2.3
=== RUN   TestSharedImageVersionName/0.0.1
=== RUN   TestSharedImageVersionName/hello
=== RUN   TestSharedImageVersionName/1.2.3.4
=== RUN   TestSharedImageVersionName/hell0-there
--- PASS: TestSharedImageVersionName (0.00s)
    --- PASS: TestSharedImageVersionName/#00 (0.00s)
    --- PASS: TestSharedImageVersionName/a.b.c (0.00s)
    --- PASS: TestSharedImageVersionName/1.2.3 (0.00s)
    --- PASS: TestSharedImageVersionName/0.0.1 (0.00s)
    --- PASS: TestSharedImageVersionName/hello (0.00s)
    --- PASS: TestSharedImageVersionName/1.2.3.4 (0.00s)
    --- PASS: TestSharedImageVersionName/hell0-there (0.00s)
=== RUN   TestIPv4Address
=== RUN   TestIPv4Address/#00
=== RUN   TestIPv4Address/0.0.0.0
=== RUN   TestIPv4Address/1.2.3.no
=== RUN   TestIPv4Address/text
=== RUN   TestIPv4Address/1.2.3.4
=== RUN   TestIPv4Address/12.34.43.21
=== RUN   TestIPv4Address/100.123.199.0
=== RUN   TestIPv4Address/255.255.255.255
--- PASS: TestIPv4Address (0.00s)
    --- PASS: TestIPv4Address/#00 (0.00s)
    --- PASS: TestIPv4Address/0.0.0.0 (0.00s)
    --- PASS: TestIPv4Address/1.2.3.no (0.00s)
    --- PASS: TestIPv4Address/text (0.00s)
    --- PASS: TestIPv4Address/1.2.3.4 (0.00s)
    --- PASS: TestIPv4Address/12.34.43.21 (0.00s)
    --- PASS: TestIPv4Address/100.123.199.0 (0.00s)
    --- PASS: TestIPv4Address/255.255.255.255 (0.00s)
=== RUN   TestIPv4AddressOrEmpty
=== RUN   TestIPv4AddressOrEmpty/#00
=== RUN   TestIPv4AddressOrEmpty/0.0.0.0
=== RUN   TestIPv4AddressOrEmpty/1.2.3.no
=== RUN   TestIPv4AddressOrEmpty/text
=== RUN   TestIPv4AddressOrEmpty/1.2.3.4
=== RUN   TestIPv4AddressOrEmpty/12.34.43.21
=== RUN   TestIPv4AddressOrEmpty/100.123.199.0
=== RUN   TestIPv4AddressOrEmpty/255.255.255.255
--- PASS: TestIPv4AddressOrEmpty (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/#00 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/0.0.0.0 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/1.2.3.no (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/text (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/1.2.3.4 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/12.34.43.21 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/100.123.199.0 (0.00s)
    --- PASS: TestIPv4AddressOrEmpty/255.255.255.255 (0.00s)
=== RUN   TestMACAddress
=== RUN   TestMACAddress/#00
=== RUN   TestMACAddress/text_d
=== RUN   TestMACAddress/12:34:no
=== RUN   TestMACAddress/123:34:56:78:90:ab
=== RUN   TestMACAddress/12:34:56:78:90:NO
=== RUN   TestMACAddress/12:34:56:78:90:ab
=== RUN   TestMACAddress/ab:cd:ef:AB:CD:EF
--- PASS: TestMACAddress (0.00s)
    --- PASS: TestMACAddress/#00 (0.00s)
    --- PASS: TestMACAddress/text_d (0.00s)
    --- PASS: TestMACAddress/12:34:no (0.00s)
    --- PASS: TestMACAddress/123:34:56:78:90:ab (0.00s)
    --- PASS: TestMACAddress/12:34:56:78:90:NO (0.00s)
    --- PASS: TestMACAddress/12:34:56:78:90:ab (0.00s)
    --- PASS: TestMACAddress/ab:cd:ef:AB:CD:EF (0.00s)
=== RUN   TestPortNumber
=== RUN   TestPortNumber/-1
=== RUN   TestPortNumber/0
=== RUN   TestPortNumber/1
=== RUN   TestPortNumber/8477
=== RUN   TestPortNumber/65535
=== RUN   TestPortNumber/65536
=== RUN   TestPortNumber/7000000
--- PASS: TestPortNumber (0.00s)
    --- PASS: TestPortNumber/-1 (0.00s)
    --- PASS: TestPortNumber/0 (0.00s)
    --- PASS: TestPortNumber/1 (0.00s)
    --- PASS: TestPortNumber/8477 (0.00s)
    --- PASS: TestPortNumber/65535 (0.00s)
    --- PASS: TestPortNumber/65536 (0.00s)
    --- PASS: TestPortNumber/7000000 (0.00s)
=== RUN   TestPortNumberOrZero
=== RUN   TestPortNumberOrZero/-1
=== RUN   TestPortNumberOrZero/0
=== RUN   TestPortNumberOrZero/1
=== RUN   TestPortNumberOrZero/8477
=== RUN   TestPortNumberOrZero/65535
=== RUN   TestPortNumberOrZero/65536
=== RUN   TestPortNumberOrZero/7000000
--- PASS: TestPortNumberOrZero (0.00s)
    --- PASS: TestPortNumberOrZero/-1 (0.00s)
    --- PASS: TestPortNumberOrZero/0 (0.00s)
    --- PASS: TestPortNumberOrZero/1 (0.00s)
    --- PASS: TestPortNumberOrZero/8477 (0.00s)
    --- PASS: TestPortNumberOrZero/65535 (0.00s)
    --- PASS: TestPortNumberOrZero/65536 (0.00s)
    --- PASS: TestPortNumberOrZero/7000000 (0.00s)
=== RUN   TestRFC3339Time
=== RUN   TestRFC3339Time/#00
=== RUN   TestRFC3339Time/this_is_not_a_date
=== RUN   TestRFC3339Time/2000-01-01
=== RUN   TestRFC3339Time/2000-01-01T01:23:45
=== RUN   TestRFC3339Time/2000-01-01T01:23:45Z
=== RUN   TestRFC3339Time/2000-01-01T01:23:45+00:00
--- PASS: TestRFC3339Time (0.00s)
    --- PASS: TestRFC3339Time/#00 (0.00s)
    --- PASS: TestRFC3339Time/this_is_not_a_date (0.00s)
    --- PASS: TestRFC3339Time/2000-01-01 (0.00s)
    --- PASS: TestRFC3339Time/2000-01-01T01:23:45 (0.00s)
    --- PASS: TestRFC3339Time/2000-01-01T01:23:45Z (0.00s)
    --- PASS: TestRFC3339Time/2000-01-01T01:23:45+00:00 (0.00s)
=== RUN   TestRfc3339DateInFutureBy
=== RUN   TestRfc3339DateInFutureBy/empty
=== RUN   TestRfc3339DateInFutureBy/not_a_time
=== RUN   TestRfc3339DateInFutureBy/now_is_not_1_hour_ahead
=== RUN   TestRfc3339DateInFutureBy/now_+_7_hours_is_not_1_hour_ahead
=== RUN   TestRfc3339DateInFutureBy/now_+_7_min_is_7_min_ahead
=== RUN   TestRfc3339DateInFutureBy/now_+_8_min_is_at_least_7_min_ahead
--- PASS: TestRfc3339DateInFutureBy (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/empty (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/not_a_time (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/now_is_not_1_hour_ahead (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/now_+_7_hours_is_not_1_hour_ahead (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/now_+_7_min_is_7_min_ahead (0.00s)
    --- PASS: TestRfc3339DateInFutureBy/now_+_8_min_is_at_least_7_min_ahead (0.00s)
=== RUN   TestURLIsHTTPS
=== RUN   TestURLIsHTTPS/#00
=== RUN   TestURLIsHTTPS/this_is_not_a_url
=== RUN   TestURLIsHTTPS/www.example.com
=== RUN   TestURLIsHTTPS/ftp://www.example.com
=== RUN   TestURLIsHTTPS/http://www.example.com
=== RUN   TestURLIsHTTPS/https://www.example.com
--- PASS: TestURLIsHTTPS (0.00s)
    --- PASS: TestURLIsHTTPS/#00 (0.00s)
    --- PASS: TestURLIsHTTPS/this_is_not_a_url (0.00s)
    --- PASS: TestURLIsHTTPS/www.example.com (0.00s)
    --- PASS: TestURLIsHTTPS/ftp://www.example.com (0.00s)
    --- PASS: TestURLIsHTTPS/http://www.example.com (0.00s)
    --- PASS: TestURLIsHTTPS/https://www.example.com (0.00s)
=== RUN   TestURLIsHTTPOrHTTPS
=== RUN   TestURLIsHTTPOrHTTPS/#00
=== RUN   TestURLIsHTTPOrHTTPS/this_is_not_a_url
=== RUN   TestURLIsHTTPOrHTTPS/www.example.com
=== RUN   TestURLIsHTTPOrHTTPS/ftp://www.example.com
=== RUN   TestURLIsHTTPOrHTTPS/http://www.example.com
=== RUN   TestURLIsHTTPOrHTTPS/https://www.example.com
--- PASS: TestURLIsHTTPOrHTTPS (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/#00 (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/this_is_not_a_url (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/www.example.com (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/ftp://www.example.com (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/http://www.example.com (0.00s)
    --- PASS: TestURLIsHTTPOrHTTPS/https://www.example.com (0.00s)
=== RUN   TestUUID
=== RUN   TestUUID/#00
=== RUN   TestUUID/hello-world
=== RUN   TestUUID/00000000-0000-111-0000-000000000000
=== RUN   TestUUID/00000000-0000-0000-0000-000000000000
--- PASS: TestUUID (0.00s)
    --- PASS: TestUUID/#00 (0.00s)
    --- PASS: TestUUID/hello-world (0.00s)
    --- PASS: TestUUID/00000000-0000-111-0000-000000000000 (0.00s)
    --- PASS: TestUUID/00000000-0000-0000-0000-000000000000 (0.00s)
=== RUN   TestUrlWithScheme
=== RUN   TestUrlWithScheme/TestUrlWithScheme
--- PASS: TestUrlWithScheme (0.00s)
    --- PASS: TestUrlWithScheme/TestUrlWithScheme (0.00s)
=== RUN   TestVirtualNetworkRule_invalidNameValidation
--- PASS: TestVirtualNetworkRule_invalidNameValidation (0.00s)
=== RUN   TestResourceAzureRMPostgreSQLVirtualNetworkRule_validNameValidation
--- PASS: TestResourceAzureRMPostgreSQLVirtualNetworkRule_validNameValidation (0.00s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate	0.619s
```

* New Resource: `azurerm_shared_image_gallery`

* New Data Source: `azurerm_shared_image_gallery`

* New Resource: `azurerm_shared_image`

* New Data Source: `azurerm_shared_image`

* Hooking up the resources

* Adding a disclaimer about Shared Image Galleries being in Preview

* New Resource: `azurerm_shared_image_version`

* New Data Source: `azurerm_shared_image_version`

* Fixing the broken tests

* SDKv21.1: switching to use the TargetRegion field

* Fixing the data source test
  • Loading branch information
tombuildsstuff authored Oct 1, 2018
1 parent 37e9c96 commit 40b333f
Show file tree
Hide file tree
Showing 23 changed files with 2,513 additions and 12 deletions.
35 changes: 25 additions & 10 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,19 @@ type ArmClient struct {
cdnProfilesClient cdn.ProfilesClient

// Compute
availSetClient compute.AvailabilitySetsClient
diskClient compute.DisksClient
imageClient compute.ImagesClient
snapshotsClient compute.SnapshotsClient
usageOpsClient compute.UsageClient
vmExtensionImageClient compute.VirtualMachineExtensionImagesClient
vmExtensionClient compute.VirtualMachineExtensionsClient
vmScaleSetClient compute.VirtualMachineScaleSetsClient
vmImageClient compute.VirtualMachineImagesClient
vmClient compute.VirtualMachinesClient
availSetClient compute.AvailabilitySetsClient
diskClient compute.DisksClient
imageClient compute.ImagesClient
galleriesClient compute.GalleriesClient
galleryImagesClient compute.GalleryImagesClient
galleryImageVersionsClient compute.GalleryImageVersionsClient
snapshotsClient compute.SnapshotsClient
usageOpsClient compute.UsageClient
vmExtensionImageClient compute.VirtualMachineExtensionImagesClient
vmExtensionClient compute.VirtualMachineExtensionsClient
vmScaleSetClient compute.VirtualMachineScaleSetsClient
vmImageClient compute.VirtualMachineImagesClient
vmClient compute.VirtualMachinesClient

// Devices
iothubResourceClient devices.IotHubResourceClient
Expand Down Expand Up @@ -590,6 +593,18 @@ func (c *ArmClient) registerComputeClients(endpoint, subscriptionId string, auth
virtualMachinesClient := compute.NewVirtualMachinesClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&virtualMachinesClient.Client, auth)
c.vmClient = virtualMachinesClient

galleriesClient := compute.NewGalleriesClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&galleriesClient.Client, auth)
c.galleriesClient = galleriesClient

galleryImagesClient := compute.NewGalleryImagesClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&galleryImagesClient.Client, auth)
c.galleryImagesClient = galleryImagesClient

galleryImageVersionsClient := compute.NewGalleryImageVersionsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&galleryImageVersionsClient.Client, auth)
c.galleryImageVersionsClient = galleryImageVersionsClient
}

func (c *ArmClient) registerContainerInstanceClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
Expand Down
147 changes: 147 additions & 0 deletions azurerm/data_source_shared_image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package azurerm

import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-06-01/compute"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmSharedImage() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmSharedImageRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.SharedImageName,
},

"gallery_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.SharedImageGalleryName,
},

"location": locationForDataSourceSchema(),

"resource_group_name": resourceGroupNameForDataSourceSchema(),

"os_type": {
Type: schema.TypeString,
Computed: true,
},

"identifier": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"publisher": {
Type: schema.TypeString,
Computed: true,
},
"offer": {
Type: schema.TypeString,
Computed: true,
},
"sku": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"description": {
Type: schema.TypeString,
Computed: true,
},

"eula": {
Type: schema.TypeString,
Computed: true,
},

"privacy_statement_uri": {
Type: schema.TypeString,
Computed: true,
},

"release_note_uri": {
Type: schema.TypeString,
Computed: true,
},

"tags": tagsForDataSourceSchema(),
},
}
}
func dataSourceArmSharedImageRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).galleryImagesClient
ctx := meta.(*ArmClient).StopContext

name := d.Get("name").(string)
galleryName := d.Get("gallery_name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resourceGroup, galleryName, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Shared Image %q was not found in Gallery %q / Resource Group %q", name, galleryName, resourceGroup)
}

return fmt.Errorf("Error making Read request on Shared Image %q (Gallery %q / Resource Group %q): %+v", name, galleryName, resourceGroup, err)
}

d.SetId(*resp.ID)

d.Set("name", name)
d.Set("gallery_name", galleryName)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}

if props := resp.GalleryImageProperties; props != nil {
d.Set("description", props.Description)
d.Set("eula", props.Eula)
d.Set("os_type", string(props.OsType))
d.Set("privacy_statement_uri", props.PrivacyStatementURI)
d.Set("release_note_uri", props.ReleaseNoteURI)

flattenedIdentifier := flattenGalleryImageDataSourceIdentifier(props.Identifier)
if err := d.Set("identifier", flattenedIdentifier); err != nil {
return fmt.Errorf("Error setting `identifier`: %+v", err)
}
}

flattenAndSetTags(d, resp.Tags)

return nil
}

func flattenGalleryImageDataSourceIdentifier(input *compute.GalleryImageIdentifier) []interface{} {
if input == nil {
return []interface{}{}
}

result := make(map[string]interface{})

if input.Offer != nil {
result["offer"] = *input.Offer
}

if input.Publisher != nil {
result["publisher"] = *input.Publisher
}

if input.Sku != nil {
result["sku"] = *input.Sku
}

return []interface{}{result}
}
74 changes: 74 additions & 0 deletions azurerm/data_source_shared_image_gallery.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package azurerm

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmSharedImageGallery() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmSharedImageGalleryRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.SharedImageGalleryName,
},

"resource_group_name": resourceGroupNameForDataSourceSchema(),

"location": locationForDataSourceSchema(),

"description": {
Type: schema.TypeString,
Computed: true,
},

"unique_name": {
Type: schema.TypeString,
Computed: true,
},

"tags": tagsForDataSourceSchema(),
},
}
}

func dataSourceArmSharedImageGalleryRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).galleriesClient
ctx := meta.(*ArmClient).StopContext

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Shared Image Gallery %q (Resource Group %q) was not found", name, resourceGroup)
}

return fmt.Errorf("Error making Read request on Shared Image Gallery %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.SetId(*resp.ID)
d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}

if props := resp.GalleryProperties; props != nil {
d.Set("description", props.Description)
if identifier := props.Identifier; identifier != nil {
d.Set("unique_name", identifier.UniqueName)
}
}

flattenAndSetTags(d, resp.Tags)

return nil
}
76 changes: 76 additions & 0 deletions azurerm/data_source_shared_image_gallery_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package azurerm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceAzureRMSharedImageGallery_basic(t *testing.T) {
dataSourceName := "data.azurerm_shared_image_gallery.test"
rInt := acctest.RandInt()
location := testLocation()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSharedImageGalleryDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataSourceSharedImageGallery_basic(rInt, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"),
),
},
},
})
}

func TestAccDataSourceAzureRMSharedImageGallery_complete(t *testing.T) {
dataSourceName := "data.azurerm_shared_image_gallery.test"
rInt := acctest.RandInt()
location := testLocation()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSharedImageGalleryDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataSourceSharedImageGallery_complete(rInt, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "description", "Shared images and things."),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(dataSourceName, "tags.Hello", "There"),
resource.TestCheckResourceAttr(dataSourceName, "tags.World", "Example"),
),
},
},
})
}

func testAccDataSourceSharedImageGallery_basic(rInt int, location string) string {
template := testAccAzureRMSharedImageGallery_basic(rInt, location)
return fmt.Sprintf(`
%s
data "azurerm_shared_image_gallery" "test" {
name = "${azurerm_shared_image_gallery.test.name}"
resource_group_name = "${azurerm_shared_image_gallery.test.resource_group_name}"
}
`, template)
}

func testAccDataSourceSharedImageGallery_complete(rInt int, location string) string {
template := testAccAzureRMSharedImageGallery_complete(rInt, location)
return fmt.Sprintf(`
%s
data "azurerm_shared_image_gallery" "test" {
name = "${azurerm_shared_image_gallery.test.name}"
resource_group_name = "${azurerm_shared_image_gallery.test.resource_group_name}"
}
`, template)
}
Loading

0 comments on commit 40b333f

Please sign in to comment.