Skip to content

Commit

Permalink
enableRbac added in data_fusion_instance along with test (#6633) (#12992
Browse files Browse the repository at this point in the history
)

fixes #9065

Signed-off-by: Modular Magician <[email protected]>

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Nov 9, 2022
1 parent a29023d commit 4d69033
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/6633.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
datafusion: added `enable_rbac` field to `google_data_fusion_instance` resource
```
50 changes: 50 additions & 0 deletions google/resource_data_fusion_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"log"
"reflect"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -92,6 +93,11 @@ pipelines at low cost. Possible values: ["BASIC", "ENTERPRISE", "DEVELOPER"]`,
ForceNew: true,
Description: `An optional description of the instance.`,
},
"enable_rbac": {
Type: schema.TypeBool,
Optional: true,
Description: `Option to enable granular role-based access control.`,
},
"enable_stackdriver_logging": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -254,6 +260,12 @@ func resourceDataFusionInstanceCreate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("enable_stackdriver_monitoring"); !isEmptyValue(reflect.ValueOf(enableStackdriverMonitoringProp)) && (ok || !reflect.DeepEqual(v, enableStackdriverMonitoringProp)) {
obj["enableStackdriverMonitoring"] = enableStackdriverMonitoringProp
}
enableRbacProp, err := expandDataFusionInstanceEnableRbac(d.Get("enable_rbac"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("enable_rbac"); !isEmptyValue(reflect.ValueOf(enableRbacProp)) && (ok || !reflect.DeepEqual(v, enableRbacProp)) {
obj["enableRbac"] = enableRbacProp
}
labelsProp, err := expandDataFusionInstanceLabels(d.Get("labels"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -414,6 +426,9 @@ func resourceDataFusionInstanceRead(d *schema.ResourceData, meta interface{}) er
if err := d.Set("enable_stackdriver_monitoring", flattenDataFusionInstanceEnableStackdriverMonitoring(res["enableStackdriverMonitoring"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("enable_rbac", flattenDataFusionInstanceEnableRbac(res["enableRbac"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("labels", flattenDataFusionInstanceLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
Expand Down Expand Up @@ -488,6 +503,12 @@ func resourceDataFusionInstanceUpdate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("enable_stackdriver_monitoring"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableStackdriverMonitoringProp)) {
obj["enableStackdriverMonitoring"] = enableStackdriverMonitoringProp
}
enableRbacProp, err := expandDataFusionInstanceEnableRbac(d.Get("enable_rbac"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("enable_rbac"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableRbacProp)) {
obj["enableRbac"] = enableRbacProp
}
labelsProp, err := expandDataFusionInstanceLabels(d.Get("labels"), d, config)
if err != nil {
return err
Expand All @@ -501,6 +522,27 @@ func resourceDataFusionInstanceUpdate(d *schema.ResourceData, meta interface{})
}

log.Printf("[DEBUG] Updating Instance %q: %#v", d.Id(), obj)
updateMask := []string{}

if d.HasChange("enable_stackdriver_logging") {
updateMask = append(updateMask, "enableStackdriverLogging")
}

if d.HasChange("enable_stackdriver_monitoring") {
updateMask = append(updateMask, "enableStackdriverMonitoring")
}

if d.HasChange("enable_rbac") {
updateMask = append(updateMask, "enableRbac")
}

// updateMask is a URL parameter but not present in the schema, so replaceVars
// won't set it

url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
if err != nil {
return err
}

// err == nil indicates that the billing_project value was found
if bp, err := getBillingProject(d, config); err == nil {
Expand Down Expand Up @@ -615,6 +657,10 @@ func flattenDataFusionInstanceEnableStackdriverMonitoring(v interface{}, d *sche
return v
}

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

func flattenDataFusionInstanceLabels(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}
Expand Down Expand Up @@ -723,6 +769,10 @@ func expandDataFusionInstanceEnableStackdriverMonitoring(v interface{}, d Terraf
return v, nil
}

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

func expandDataFusionInstanceLabels(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down
40 changes: 40 additions & 0 deletions google/resource_data_fusion_instance_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,46 @@ data "google_project" "project" {}
`, context)
}

func TestAccDataFusionInstance_dataFusionInstanceEnterpriseExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDataFusionInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataFusionInstance_dataFusionInstanceEnterpriseExample(context),
},
{
ResourceName: "google_data_fusion_instance.enterprise_instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})
}

func testAccDataFusionInstance_dataFusionInstanceEnterpriseExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_data_fusion_instance" "enterprise_instance" {
name = "tf-test-my-instance%{random_suffix}"
region = "us-central1"
type = "ENTERPRISE"
enable_rbac = true
# Mark for testing to avoid service networking connection usage that is not cleaned up
options = {
prober_test_run = "true"
}
}
`, context)
}

func testAccCheckDataFusionInstanceDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
24 changes: 24 additions & 0 deletions website/docs/r/data_fusion_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ resource "google_kms_crypto_key_iam_binding" "crypto_key_binding" {
data "google_project" "project" {}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=data_fusion_instance_enterprise&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Data Fusion Instance Enterprise


```hcl
resource "google_data_fusion_instance" "enterprise_instance" {
name = "my-instance"
region = "us-central1"
type = "ENTERPRISE"
enable_rbac = true
# Mark for testing to avoid service networking connection usage that is not cleaned up
options = {
prober_test_run = "true"
}
}
```

## Argument Reference

Expand Down Expand Up @@ -165,6 +185,10 @@ The following arguments are supported:
(Optional)
Option to enable Stackdriver Monitoring.

* `enable_rbac` -
(Optional)
Option to enable granular role-based access control.

* `labels` -
(Optional)
The resource labels for instance to use to annotate any related underlying resources,
Expand Down

0 comments on commit 4d69033

Please sign in to comment.