-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the ability to generate a securitygroup name-prefix
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ func resourceAwsSecurityGroup() *schema.Resource { | |
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
ConflictsWith: []string{"name_prefix"}, | ||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { | ||
value := v.(string) | ||
if len(value) > 255 { | ||
|
@@ -38,6 +39,20 @@ func resourceAwsSecurityGroup() *schema.Resource { | |
}, | ||
}, | ||
|
||
"name_prefix": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { | ||
value := v.(string) | ||
if len(value) > 100 { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
stack72
Author
Contributor
|
||
errors = append(errors, fmt.Errorf( | ||
"%q cannot be longer than 100 characters, name is limited to 255", k)) | ||
} | ||
return | ||
}, | ||
}, | ||
|
||
"description": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
|
@@ -178,6 +193,8 @@ func resourceAwsSecurityGroupCreate(d *schema.ResourceData, meta interface{}) er | |
var groupName string | ||
if v, ok := d.GetOk("name"); ok { | ||
groupName = v.(string) | ||
} else if v, ok := d.GetOk("name_prefix"); ok { | ||
groupName = resource.PrefixedUniqueId(v.(string)) | ||
} else { | ||
groupName = resource.UniqueId() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@stack72 Would you please give me any hints on where this figure (
100
) came from?I was assuming we should just allow
255 - <uniqueId-length>
whereas the unique ID isn't155
characters long for sure. Maybe I'm just missing something obvious here?