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 custom domain configuration for Looker #6979

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/9936.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
looker: added `custom_domain` field to `google_looker_instance ` resource
```
96 changes: 96 additions & 0 deletions google-beta/services/looker/resource_looker_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ existing list of allowed email domains.`,
Note that the consumer network may be in a different GCP project than the consumer
project that is hosting the Looker Instance.`,
},
"custom_domain": {
Type: schema.TypeList,
Optional: true,
Description: `Custom domain settings for a Looker instance.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"domain": {
Type: schema.TypeString,
Optional: true,
Description: `Domain name`,
},
"state": {
Type: schema.TypeString,
Computed: true,
Description: `Status of the custom domain.`,
},
},
},
},
"deny_maintenance_period": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -503,6 +523,12 @@ func resourceLookerInstanceCreate(d *schema.ResourceData, meta interface{}) erro
} else if v, ok := d.GetOkExists("user_metadata"); !tpgresource.IsEmptyValue(reflect.ValueOf(userMetadataProp)) && (ok || !reflect.DeepEqual(v, userMetadataProp)) {
obj["userMetadata"] = userMetadataProp
}
customDomainProp, err := expandLookerInstanceCustomDomain(d.Get("custom_domain"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("custom_domain"); !tpgresource.IsEmptyValue(reflect.ValueOf(customDomainProp)) && (ok || !reflect.DeepEqual(v, customDomainProp)) {
obj["customDomain"] = customDomainProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{LookerBasePath}}projects/{{project}}/locations/{{region}}/instances?instanceId={{name}}")
if err != nil {
Expand Down Expand Up @@ -661,6 +687,9 @@ func resourceLookerInstanceRead(d *schema.ResourceData, meta interface{}) error
if err := d.Set("user_metadata", flattenLookerInstanceUserMetadata(res["userMetadata"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("custom_domain", flattenLookerInstanceCustomDomain(res["customDomain"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}

return nil
}
Expand Down Expand Up @@ -741,6 +770,12 @@ func resourceLookerInstanceUpdate(d *schema.ResourceData, meta interface{}) erro
} else if v, ok := d.GetOkExists("user_metadata"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, userMetadataProp)) {
obj["userMetadata"] = userMetadataProp
}
customDomainProp, err := expandLookerInstanceCustomDomain(d.Get("custom_domain"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("custom_domain"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, customDomainProp)) {
obj["customDomain"] = customDomainProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{LookerBasePath}}projects/{{project}}/locations/{{region}}/instances/{{name}}")
if err != nil {
Expand Down Expand Up @@ -789,6 +824,10 @@ func resourceLookerInstanceUpdate(d *schema.ResourceData, meta interface{}) erro
if d.HasChange("user_metadata") {
updateMask = append(updateMask, "userMetadata")
}

if d.HasChange("custom_domain") {
updateMask = append(updateMask, "customDomain")
}
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
Expand Down Expand Up @@ -1415,6 +1454,29 @@ func flattenLookerInstanceUserMetadataAdditionalDeveloperUserCount(v interface{}
return v // let terraform core handle it otherwise
}

func flattenLookerInstanceCustomDomain(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["domain"] =
flattenLookerInstanceCustomDomainDomain(original["domain"], d, config)
transformed["state"] =
flattenLookerInstanceCustomDomainState(original["state"], d, config)
return []interface{}{transformed}
}
func flattenLookerInstanceCustomDomainDomain(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

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

func expandLookerInstanceAdminSettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down Expand Up @@ -1846,3 +1908,37 @@ func expandLookerInstanceUserMetadataAdditionalStandardUserCount(v interface{},
func expandLookerInstanceUserMetadataAdditionalDeveloperUserCount(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandLookerInstanceCustomDomain(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.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{})

transformedDomain, err := expandLookerInstanceCustomDomainDomain(original["domain"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedDomain); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["domain"] = transformedDomain
}

transformedState, err := expandLookerInstanceCustomDomainState(original["state"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedState); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["state"] = transformedState
}

return transformed, nil
}

func expandLookerInstanceCustomDomainDomain(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandLookerInstanceCustomDomainState(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,48 @@ resource "google_kms_crypto_key_iam_member" "crypto_key" {
`, context)
}

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

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

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckLookerInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccLookerInstance_lookerInstanceCustomDomainExample(context),
},
{
ResourceName: "google_looker_instance.looker-instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "oauth_config", "region"},
},
},
})
}

func testAccLookerInstance_lookerInstanceCustomDomainExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_looker_instance" "looker-instance" {
name = "tf-test-my-instance%{random_suffix}"
platform_edition = "LOOKER_CORE_STANDARD"
region = "us-central1"
oauth_config {
client_id = "tf-test-my-client-id%{random_suffix}"
client_secret = "tf-test-my-client-secret%{random_suffix}"
}
custom_domain {
domain = "tf-test-my-custom-domain%{random_suffix}.com"
}
}
`, context)
}

func testAccCheckLookerInstanceDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
37 changes: 37 additions & 0 deletions website/docs/r/looker_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ resource "google_kms_crypto_key_iam_member" "crypto_key" {
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-looker.iam.gserviceaccount.com"
}
```
<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.jparrowsec.cn%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=looker_instance_custom_domain&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%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 - Looker Instance Custom Domain


```hcl
resource "google_looker_instance" "looker-instance" {
name = "my-instance"
platform_edition = "LOOKER_CORE_STANDARD"
region = "us-central1"
oauth_config {
client_id = "my-client-id"
client_secret = "my-client-secret"
}
custom_domain {
domain = "my-custom-domain.com"
}
}
```

## Argument Reference

Expand Down Expand Up @@ -269,6 +291,11 @@ The following arguments are supported:
total users, distributed across Viewer, Standard, and Developer.
Structure is [documented below](#nested_user_metadata).

* `custom_domain` -
(Optional)
Custom domain settings for a Looker instance.
Structure is [documented below](#nested_custom_domain).

* `region` -
(Optional)
The name of the Looker region of the instance.
Expand Down Expand Up @@ -433,6 +460,16 @@ The following arguments are supported:
(Optional)
Number of additional Developer Users to allocate to the Looker Instance.

<a name="nested_custom_domain"></a>The `custom_domain` block supports:

* `domain` -
(Optional)
Domain name

* `state` -
(Output)
Status of the custom domain.

## Attributes Reference

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