Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Properties field to ApigeeOrganization #12433

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6464.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
apigee: added a `properties` field to the Apigee Organization resource
```
141 changes: 141 additions & 0 deletions google/resource_apigee_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ Valid only when 'RuntimeType' is set to CLOUD. The value can be updated only whe
Optional: true,
Description: `The display name of the Apigee organization.`,
},
"properties": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: `Properties defined in the Apigee organization profile.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"property": {
Type: schema.TypeList,
Optional: true,
Description: `List of all properties in the object.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: `Name of the property.`,
},
"value": {
Type: schema.TypeString,
Optional: true,
Description: `Value of the property.`,
},
},
},
},
},
},
},
"retention": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -177,6 +207,12 @@ func resourceApigeeOrganizationCreate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("runtime_database_encryption_key_name"); !isEmptyValue(reflect.ValueOf(runtimeDatabaseEncryptionKeyNameProp)) && (ok || !reflect.DeepEqual(v, runtimeDatabaseEncryptionKeyNameProp)) {
obj["runtimeDatabaseEncryptionKeyName"] = runtimeDatabaseEncryptionKeyNameProp
}
propertiesProp, err := expandApigeeOrganizationProperties(d.Get("properties"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("properties"); !isEmptyValue(reflect.ValueOf(propertiesProp)) && (ok || !reflect.DeepEqual(v, propertiesProp)) {
obj["properties"] = propertiesProp
}

obj, err = resourceApigeeOrganizationEncoder(d, meta, obj)
if err != nil {
Expand Down Expand Up @@ -290,6 +326,9 @@ func resourceApigeeOrganizationRead(d *schema.ResourceData, meta interface{}) er
if err := d.Set("runtime_database_encryption_key_name", flattenApigeeOrganizationRuntimeDatabaseEncryptionKeyName(res["runtimeDatabaseEncryptionKeyName"], d, config)); err != nil {
return fmt.Errorf("Error reading Organization: %s", err)
}
if err := d.Set("properties", flattenApigeeOrganizationProperties(res["properties"], d, config)); err != nil {
return fmt.Errorf("Error reading Organization: %s", err)
}

return nil
}
Expand Down Expand Up @@ -346,6 +385,12 @@ func resourceApigeeOrganizationUpdate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("runtime_database_encryption_key_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, runtimeDatabaseEncryptionKeyNameProp)) {
obj["runtimeDatabaseEncryptionKeyName"] = runtimeDatabaseEncryptionKeyNameProp
}
propertiesProp, err := expandApigeeOrganizationProperties(d.Get("properties"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("properties"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, propertiesProp)) {
obj["properties"] = propertiesProp
}

obj, err = resourceApigeeOrganizationEncoder(d, meta, obj)
if err != nil {
Expand Down Expand Up @@ -497,6 +542,46 @@ func flattenApigeeOrganizationRuntimeDatabaseEncryptionKeyName(v interface{}, d
return v
}

func flattenApigeeOrganizationProperties(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["property"] =
flattenApigeeOrganizationPropertiesProperty(original["property"], d, config)
return []interface{}{transformed}
}
func flattenApigeeOrganizationPropertiesProperty(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
}
l := v.([]interface{})
transformed := make([]interface{}, 0, len(l))
for _, raw := range l {
original := raw.(map[string]interface{})
if len(original) < 1 {
// Do not include empty json objects coming back from the api
continue
}
transformed = append(transformed, map[string]interface{}{
"name": flattenApigeeOrganizationPropertiesPropertyName(original["name"], d, config),
"value": flattenApigeeOrganizationPropertiesPropertyValue(original["value"], d, config),
})
}
return transformed
}
func flattenApigeeOrganizationPropertiesPropertyName(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenApigeeOrganizationPropertiesPropertyValue(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func expandApigeeOrganizationDisplayName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -525,6 +610,62 @@ func expandApigeeOrganizationRuntimeDatabaseEncryptionKeyName(v interface{}, d T
return v, nil
}

func expandApigeeOrganizationProperties(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedProperty, err := expandApigeeOrganizationPropertiesProperty(original["property"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedProperty); val.IsValid() && !isEmptyValue(val) {
transformed["property"] = transformedProperty
}

return transformed, nil
}

func expandApigeeOrganizationPropertiesProperty(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
for _, raw := range l {
if raw == nil {
continue
}
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedName, err := expandApigeeOrganizationPropertiesPropertyName(original["name"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedName); val.IsValid() && !isEmptyValue(val) {
transformed["name"] = transformedName
}

transformedValue, err := expandApigeeOrganizationPropertiesPropertyValue(original["value"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedValue); val.IsValid() && !isEmptyValue(val) {
transformed["value"] = transformedValue
}

req = append(req, transformed)
}
return req, nil
}

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

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

func resourceApigeeOrganizationEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
obj["name"] = d.Get("project_id").(string)
return obj, nil
Expand Down
23 changes: 23 additions & 0 deletions website/docs/r/apigee_organization.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ The following arguments are supported:
If not specified, a Google-Managed encryption key will be used.
Valid only when `RuntimeType` is CLOUD. For example: `projects/foo/locations/us/keyRings/bar/cryptoKeys/baz`.

* `properties` -
(Optional)
Properties defined in the Apigee organization profile.
Structure is [documented below](#nested_properties).

* `retention` -
(Optional)
Optional. This setting is applicable only for organizations that are soft-deleted (i.e., BillingType
Expand All @@ -186,6 +191,24 @@ The following arguments are supported:
Possible values are `DELETION_RETENTION_UNSPECIFIED` and `MINIMUM`.


<a name="nested_properties"></a>The `properties` block supports:

* `property` -
(Optional)
List of all properties in the object.
Structure is [documented below](#nested_property).


<a name="nested_property"></a>The `property` block supports:

* `name` -
(Optional)
Name of the property.

* `value` -
(Optional)
Value of the property.

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:
Expand Down