-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add customized diff for unique_writer_identity on resource google_log…
…ging_project_sink (#4301) (#7974) * Add customized diff and documentation for bigquery options scenario * resolve comments Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
13e49e4
commit 03402d7
Showing
4 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:enhancement | ||
logging: added plan time validation for `unique_writer_identity` on `google_logging_project_sink` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package google | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
@@ -10,11 +12,12 @@ const nonUniqueWriterAccount = "serviceAccount:[email protected] | |
|
||
func resourceLoggingProjectSink() *schema.Resource { | ||
schm := &schema.Resource{ | ||
Create: resourceLoggingProjectSinkCreate, | ||
Read: resourceLoggingProjectSinkRead, | ||
Delete: resourceLoggingProjectSinkDelete, | ||
Update: resourceLoggingProjectSinkUpdate, | ||
Schema: resourceLoggingSinkSchema(), | ||
Create: resourceLoggingProjectSinkCreate, | ||
Read: resourceLoggingProjectSinkRead, | ||
Delete: resourceLoggingProjectSinkDelete, | ||
Update: resourceLoggingProjectSinkUpdate, | ||
Schema: resourceLoggingSinkSchema(), | ||
CustomizeDiff: resourceLoggingProjectSinkCustomizeDiff, | ||
Importer: &schema.ResourceImporter{ | ||
State: resourceLoggingSinkImportState("project"), | ||
}, | ||
|
@@ -61,6 +64,27 @@ func resourceLoggingProjectSinkCreate(d *schema.ResourceData, meta interface{}) | |
return resourceLoggingProjectSinkRead(d, meta) | ||
} | ||
|
||
// if bigquery_options is set unique_writer_identity must be true | ||
func resourceLoggingProjectSinkCustomizeDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error { | ||
// separate func to allow unit testing | ||
return resourceLoggingProjectSinkCustomizeDiffFunc(d) | ||
} | ||
|
||
func resourceLoggingProjectSinkCustomizeDiffFunc(diff TerraformResourceDiff) error { | ||
if !diff.HasChange("bigquery_options.#") { | ||
return nil | ||
} | ||
|
||
bigqueryOptions := diff.Get("bigquery_options.#").(int) | ||
if bigqueryOptions > 0 { | ||
uwi := diff.Get("unique_writer_identity") | ||
if !uwi.(bool) { | ||
return errors.New("unique_writer_identity must be true when bigquery_options is supplied") | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func resourceLoggingProjectSinkRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
userAgent, err := generateUserAgentString(d, config.userAgent) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,8 +140,8 @@ The following arguments are supported: | |
|
||
* `unique_writer_identity` - (Optional) Whether or not to create a unique identity associated with this sink. If `false` | ||
(the default), then the `writer_identity` used is `serviceAccount:[email protected]`. If `true`, | ||
then a unique service account is created and used for this sink. If you wish to publish logs across projects, you | ||
must set `unique_writer_identity` to true. | ||
then a unique service account is created and used for this sink. If you wish to publish logs across projects or utilize | ||
`bigquery_options`, you must set `unique_writer_identity` to true. | ||
|
||
* `bigquery_options` - (Optional) Options that affect sinks exporting data to BigQuery. Structure documented below. | ||
|
||
|