Skip to content

Commit

Permalink
Add private instance support to data_fusion_instance
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
c2thorn authored and modular-magician committed Nov 19, 2019
1 parent 261d93a commit 7950012
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 2 deletions.
117 changes: 117 additions & 0 deletions google-beta/resource_data_fusion_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,47 @@ available, such as support for streaming pipelines, higher number of concurrent
such as Compute Engine VMs.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"network_config": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Network configuration options. These are required when a private Data Fusion instance is to be created.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_allocation": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The IP range in CIDR notation to use for the managed Data Fusion instance
nodes. This range must not overlap with any other ranges used in the Data Fusion instance network.`,
},
"network": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Name of the network in the project with which the tenant project
will be peered for executing pipelines. In case of shared VPC where the network resides in another host
project the network should specified in the form of projects/{host-project-id}/global/networks/{network}`,
},
},
},
},
"options": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Description: `Map of additional options used to configure the behavior of Data Fusion instance.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"private_instance": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Description: `Specifies whether the Data Fusion instance should be private. If set to
true, all Data Fusion nodes will have private IP addresses and will not be
able to access the public internet.`,
},
"region": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -190,6 +224,18 @@ func resourceDataFusionInstanceCreate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("options"); !isEmptyValue(reflect.ValueOf(optionsProp)) && (ok || !reflect.DeepEqual(v, optionsProp)) {
obj["options"] = optionsProp
}
privateInstanceProp, err := expandDataFusionInstancePrivateInstance(d.Get("private_instance"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("private_instance"); !isEmptyValue(reflect.ValueOf(privateInstanceProp)) && (ok || !reflect.DeepEqual(v, privateInstanceProp)) {
obj["privateInstance"] = privateInstanceProp
}
networkConfigProp, err := expandDataFusionInstanceNetworkConfig(d.Get("network_config"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("network_config"); !isEmptyValue(reflect.ValueOf(networkConfigProp)) && (ok || !reflect.DeepEqual(v, networkConfigProp)) {
obj["networkConfig"] = networkConfigProp
}

url, err := replaceVars(d, config, "{{DataFusionBasePath}}projects/{{project}}/locations/{{region}}/instances?instanceId={{name}}")
if err != nil {
Expand Down Expand Up @@ -296,6 +342,12 @@ func resourceDataFusionInstanceRead(d *schema.ResourceData, meta interface{}) er
if err := d.Set("version", flattenDataFusionInstanceVersion(res["version"], d)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("private_instance", flattenDataFusionInstancePrivateInstance(res["privateInstance"], d)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("network_config", flattenDataFusionInstanceNetworkConfig(res["networkConfig"], d)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}

return nil
}
Expand Down Expand Up @@ -460,6 +512,33 @@ func flattenDataFusionInstanceVersion(v interface{}, d *schema.ResourceData) int
return v
}

func flattenDataFusionInstancePrivateInstance(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenDataFusionInstanceNetworkConfig(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["ip_allocation"] =
flattenDataFusionInstanceNetworkConfigIpAllocation(original["ipAllocation"], d)
transformed["network"] =
flattenDataFusionInstanceNetworkConfigNetwork(original["network"], d)
return []interface{}{transformed}
}
func flattenDataFusionInstanceNetworkConfigIpAllocation(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenDataFusionInstanceNetworkConfigNetwork(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func expandDataFusionInstanceName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return replaceVars(d, config, "projects/{{project}}/locations/{{region}}/instances/{{name}}")
}
Expand Down Expand Up @@ -501,3 +580,41 @@ func expandDataFusionInstanceOptions(v interface{}, d TerraformResourceData, con
}
return m, nil
}

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

func expandDataFusionInstanceNetworkConfig(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{})

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

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

return transformed, nil
}

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

func expandDataFusionInstanceNetworkConfigNetwork(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
7 changes: 6 additions & 1 deletion google-beta/resource_data_fusion_instance_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,17 @@ resource "google_data_fusion_instance" "extended_instance" {
name = "my-instance%{random_suffix}"
description = "My Data Fusion instance"
region = "us-central1"
type = "ENTERPRISE"
type = "BASIC"
enable_stackdriver_logging = true
enable_stackdriver_monitoring = true
labels = {
example_key = "example_value"
}
private_instance = true
network_config {
network = "default"
ip_allocation = "10.89.48.0/22"
}
}
`, context)
}
Expand Down
30 changes: 29 additions & 1 deletion website/docs/r/data_fusion_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,17 @@ resource "google_data_fusion_instance" "extended_instance" {
name = "my-instance"
description = "My Data Fusion instance"
region = "us-central1"
type = "ENTERPRISE"
type = "BASIC"
enable_stackdriver_logging = true
enable_stackdriver_monitoring = true
labels = {
example_key = "example_value"
}
private_instance = true
network_config {
network = "default"
ip_allocation = "10.89.48.0/22"
}
}
```

Expand Down Expand Up @@ -116,6 +121,16 @@ The following arguments are supported:
(Optional)
Map of additional options used to configure the behavior of Data Fusion instance.

* `private_instance` -
(Optional)
Specifies whether the Data Fusion instance should be private. If set to
true, all Data Fusion nodes will have private IP addresses and will not be
able to access the public internet.

* `network_config` -
(Optional)
Network configuration options. These are required when a private Data Fusion instance is to be created. Structure is documented below.

* `region` -
(Optional)
The region of the Data Fusion instance.
Expand All @@ -124,6 +139,19 @@ The following arguments are supported:
If it is not provided, the provider project is used.


The `network_config` block supports:

* `ip_allocation` -
(Required)
The IP range in CIDR notation to use for the managed Data Fusion instance
nodes. This range must not overlap with any other ranges used in the Data Fusion instance network.

* `network` -
(Required)
Name of the network in the project with which the tenant project
will be peered for executing pipelines. In case of shared VPC where the network resides in another host
project the network should specified in the form of projects/{host-project-id}/global/networks/{network}

## Attributes Reference

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

0 comments on commit 7950012

Please sign in to comment.