Skip to content

Commit

Permalink
AD Domain resource added (#3735) (#484)
Browse files Browse the repository at this point in the history
* AD Domain resource added

* fmt issue fixed

* validation regex and input flag added

* made domain_name field not updatable

* validationfunc added

* validationfunc error message modified

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jul 28, 2020
1 parent 0780b64 commit 057ad4b
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
106 changes: 106 additions & 0 deletions google/activedirectory_domain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------

package google

import (
"reflect"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func GetActiveDirectoryDomainCaiObject(d TerraformResourceData, config *Config) (Asset, error) {
name, err := assetName(d, config, "//activedirectory.googleapis.com/{{name}}")
if err != nil {
return Asset{}, err
}
if obj, err := GetActiveDirectoryDomainApiObject(d, config); err == nil {
return Asset{
Name: name,
Type: "activedirectory.googleapis.com/Domain",
Resource: &AssetResource{
Version: "v1",
DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/activedirectory/v1/rest",
DiscoveryName: "Domain",
Data: obj,
},
}, nil
} else {
return Asset{}, err
}
}

func GetActiveDirectoryDomainApiObject(d TerraformResourceData, config *Config) (map[string]interface{}, error) {
obj := make(map[string]interface{})
labelsProp, err := expandActiveDirectoryDomainLabels(d.Get("labels"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
authorizedNetworksProp, err := expandActiveDirectoryDomainAuthorizedNetworks(d.Get("authorized_networks"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("authorized_networks"); !isEmptyValue(reflect.ValueOf(authorizedNetworksProp)) && (ok || !reflect.DeepEqual(v, authorizedNetworksProp)) {
obj["authorizedNetworks"] = authorizedNetworksProp
}
reservedIpRangeProp, err := expandActiveDirectoryDomainReservedIpRange(d.Get("reserved_ip_range"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("reserved_ip_range"); !isEmptyValue(reflect.ValueOf(reservedIpRangeProp)) && (ok || !reflect.DeepEqual(v, reservedIpRangeProp)) {
obj["reservedIpRange"] = reservedIpRangeProp
}
locationsProp, err := expandActiveDirectoryDomainLocations(d.Get("locations"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("locations"); !isEmptyValue(reflect.ValueOf(locationsProp)) && (ok || !reflect.DeepEqual(v, locationsProp)) {
obj["locations"] = locationsProp
}
adminProp, err := expandActiveDirectoryDomainAdmin(d.Get("admin"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("admin"); !isEmptyValue(reflect.ValueOf(adminProp)) && (ok || !reflect.DeepEqual(v, adminProp)) {
obj["admin"] = adminProp
}

return obj, nil
}

func expandActiveDirectoryDomainLabels(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}

func expandActiveDirectoryDomainAuthorizedNetworks(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
v = v.(*schema.Set).List()
return v, nil
}

func expandActiveDirectoryDomainReservedIpRange(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandActiveDirectoryDomainLocations(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandActiveDirectoryDomainAdmin(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
3 changes: 3 additions & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type Config struct {
tokenSource oauth2.TokenSource

AccessContextManagerBasePath string
ActiveDirectoryBasePath string
AppEngineBasePath string
BigQueryBasePath string
BigqueryDataTransferBasePath string
Expand Down Expand Up @@ -221,6 +222,7 @@ type Config struct {

// Generated product base paths
var AccessContextManagerDefaultBasePath = "https://accesscontextmanager.googleapis.com/v1/"
var ActiveDirectoryDefaultBasePath = "https://managedidentities.googleapis.com/v1/"
var AppEngineDefaultBasePath = "https://appengine.googleapis.com/v1/"
var BigQueryDefaultBasePath = "https://www.googleapis.com/bigquery/v2/"
var BigqueryDataTransferDefaultBasePath = "https://bigquerydatatransfer.googleapis.com/v1/"
Expand Down Expand Up @@ -764,6 +766,7 @@ func removeBasePathVersion(url string) string {
func ConfigureBasePaths(c *Config) {
// Generated Products
c.AccessContextManagerBasePath = AccessContextManagerDefaultBasePath
c.ActiveDirectoryBasePath = ActiveDirectoryDefaultBasePath
c.AppEngineBasePath = AppEngineDefaultBasePath
c.BigQueryBasePath = BigQueryDefaultBasePath
c.BigqueryDataTransferBasePath = BigqueryDataTransferDefaultBasePath
Expand Down
15 changes: 15 additions & 0 deletions google/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const (

// https://cloud.google.com/iam/docs/understanding-custom-roles#naming_the_role
IAMCustomRoleIDRegex = "^[a-zA-Z0-9_\\.]{3,64}$"

// https://cloud.google.com/managed-microsoft-ad/reference/rest/v1/projects.locations.global.domains/create#query-parameters
ADDomainNameRegex = "^[a-z][a-z0-9-]{0,14}\\.[a-z0-9-\\.]*[a-z]+[a-z0-9]*$"
)

var (
Expand Down Expand Up @@ -311,3 +314,15 @@ func validateRFC3339Date(v interface{}, k string) (warnings []string, errors []e
}
return
}

func validateADDomainName() schema.SchemaValidateFunc {
return func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)

if len(value) > 64 || !regexp.MustCompile(ADDomainNameRegex).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q (%q) doesn't match regexp %q, domain_name must be 2 to 64 with lowercase letters, digits, hyphens, dots and start with a letter", k, value, ADDomainNameRegex))
}
return
}
}

0 comments on commit 057ad4b

Please sign in to comment.