Skip to content

Commit

Permalink
Merge pull request #2101 from DexterPOSH/fix-shared-image-gallery-name
Browse files Browse the repository at this point in the history
Fix shared image gallery name #2081
  • Loading branch information
katbyte authored Oct 17, 2018
2 parents c8cfb41 + 18f5648 commit 6d20786
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
22 changes: 17 additions & 5 deletions azurerm/helpers/validate/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (

func SharedImageGalleryName(v interface{}, k string) (ws []string, es []error) {
value := v.(string)

r, _ := regexp.Compile("^[A-Za-z0-9._-]+$")
// Image gallery name accepts only alphanumeric, dots and underscores in the name (no dashes)
r, _ := regexp.Compile("^[A-Za-z0-9._]+$")
if !r.MatchString(value) {
es = append(es, fmt.Errorf("%s can only contain alphanumeric, full stops, underscores and dashes. Got %q.", k, value))
es = append(es, fmt.Errorf("%s can only contain alphanumeric, full stops and underscores. Got %q.", k, value))
}

length := len(value)
Expand All @@ -22,8 +22,20 @@ func SharedImageGalleryName(v interface{}, k string) (ws []string, es []error) {
}

func SharedImageName(v interface{}, k string) (ws []string, es []error) {
// same as Shared Image Gallery name, for now.
return SharedImageGalleryName(v, k)
// different from the shared image gallery name
value := v.(string)

r, _ := regexp.Compile("^[A-Za-z0-9._-]+$")
if !r.MatchString(value) {
es = append(es, fmt.Errorf("%s can only contain alphanumeric, full stops, dashes and underscores. Got %q.", k, value))
}

length := len(value)
if length >= 80 {
es = append(es, fmt.Errorf("%s can be up to 80 characters, currently %d.", k, length))
}

return
}

func SharedImageVersionName(v interface{}, k string) (ws []string, es []error) {
Expand Down
2 changes: 1 addition & 1 deletion azurerm/helpers/validate/compute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestSharedImageGalleryName(t *testing.T) {
},
{
Input: "hello-123",
ShouldError: false,
ShouldError: true,
},
{
Input: acctest.RandString(79),
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/shared_image.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resource "azurerm_resource_group" "test" {
}
resource "azurerm_shared_image_gallery" "test" {
name = "example-image-gallery"
name = "example_image_gallery"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
description = "Shared images and things."
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/shared_image_gallery.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resource "azurerm_resource_group" "test" {
}
resource "azurerm_shared_image_gallery" "test" {
name = "example-image-gallery"
name = "example_image_gallery"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
description = "Shared images and things."
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/shared_image_version.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data "azurerm_image" "existing" {
data "azurerm_shared_image" "existing" {
name = "existing-image"
gallery_name = "existing-gallery"
gallery_name = "existing_gallery"
resource_group_name = "existing-resources"
}
Expand Down

0 comments on commit 6d20786

Please sign in to comment.