Skip to content

ECO-11035 | Main <- Develop | merge to main #104

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

Merged
merged 10 commits into from
Nov 29, 2024
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
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
env:
- PROVIDER_VERSION=3.3.0
- PROVIDER_VERSION=3.3.1
before:
hooks:
# this is just an example and not a requirement for provider building/publishing
Expand Down
4 changes: 1 addition & 3 deletions docs/resources/database_postgresql.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ resource "delphix_database_postgresql" "source" {
* `key` - Key of the tag
* `value` - Value of the tag

## Import (Beta)
## Import

Use the [`import` block](https://developer.hashicorp.com/terraform/language/import) to add source configs created directly in Data Control Tower into a Terraform state file.

Expand All @@ -79,5 +79,3 @@ import {
}
```

*This is a beta feature. Delphix offers no guarantees of support or compatibility.*

518 changes: 242 additions & 276 deletions docs/resources/vdb.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions internal/provider/commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var updatableVdbKeys = map[string]bool{
"new_dbid": true,
"mount_point": true,
"tags": true,
"database_name": true,
}

var isDestructiveVdbUpdate = map[string]bool{
Expand Down
22 changes: 11 additions & 11 deletions internal/provider/resource_appdata_dsource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func TestDsource_create_positive(t *testing.T) {
name := os.Getenv("DSOURCE_NAME")
environmentUser := os.Getenv("DSOURCE_ENV_USER")
stagingEnvironment := os.Getenv("DSOURCE_STAGE_ENV")
postgresPort := os.Getenv("DSOURCE_POSTGRES_PORT")
parameters := os.Getenv("DSOURCE_PARAMETERS")

resource.Test(t, resource.TestCase{
PreCheck: func() {
testDsourcePreCheck(t, sourceId, groupId, name, environmentUser, stagingEnvironment, postgresPort)
testDsourcePreCheck(t, sourceId, groupId, name, environmentUser, stagingEnvironment, parameters)
},
Providers: testAccProviders,
CheckDestroy: testDsourceDestroy,
Expand All @@ -31,13 +31,13 @@ func TestDsource_create_positive(t *testing.T) {
ExpectError: regexp.MustCompile(`.*`),
},
{
Config: testDsourceBasic(sourceId, groupId, name, environmentUser, stagingEnvironment, postgresPort),
Config: testDsourceBasic(sourceId, groupId, name, environmentUser, stagingEnvironment, parameters),
Check: resource.ComposeTestCheckFunc(
testDsourceExists("delphix_appdata_dsource.new_data_dsource", sourceId),
resource.TestCheckResourceAttr("delphix_appdata_dsource.new_data_dsource", "source_id", sourceId)),
},
{
Config: testDsourceUpdate(sourceId, groupId, "update_same_dsource", environmentUser, stagingEnvironment, postgresPort),
Config: testDsourceUpdate(sourceId, groupId, "update_same_dsource", environmentUser, stagingEnvironment, parameters),
Check: resource.ComposeAggregateTestCheckFunc(
// irrelevant
),
Expand All @@ -47,7 +47,7 @@ func TestDsource_create_positive(t *testing.T) {
})
}

func testDsourcePreCheck(t *testing.T, sourceId string, groupId string, name string, environmentUser string, stagingEnvironment string, postgresPort string) {
func testDsourcePreCheck(t *testing.T, sourceId string, groupId string, name string, environmentUser string, stagingEnvironment string, parameters string) {
testAccPreCheck(t)
if sourceId == "" {
t.Fatal("DSOURCE_SOURCE_ID must be set for env acceptance tests")
Expand All @@ -64,12 +64,12 @@ func testDsourcePreCheck(t *testing.T, sourceId string, groupId string, name str
if stagingEnvironment == "" {
t.Fatal("DSOURCE_STAGE_ENV must be set for env acceptance tests")
}
if postgresPort == "" {
t.Fatal("DSOURCE_POSTGRES_PORT must be set for env acceptance tests")
if parameters == "" {
t.Fatal("DSOURCE_PARAMETERS must be set for env acceptance tests")
}
}

func testDsourceBasic(sourceId string, groupId string, name string, environmentUser string, stagingEnvironment string, postgresPort string) string {
func testDsourceBasic(sourceId string, groupId string, name string, environmentUser string, stagingEnvironment string, parameters string) string {
return fmt.Sprintf(`
resource "delphix_appdata_dsource" "new_data_dsource" {
source_value = "%s"
Expand All @@ -86,10 +86,10 @@ resource "delphix_appdata_dsource" "new_data_dsource" {
resync = true
})
}
`, sourceId, groupId, name, environmentUser, stagingEnvironment, postgresPort)
`, sourceId, groupId, name, environmentUser, stagingEnvironment, parameters)
}

func testDsourceUpdate(sourceId string, groupId string, name string, environmentUser string, stagingEnvironment string, postgresPort string) string {
func testDsourceUpdate(sourceId string, groupId string, name string, environmentUser string, stagingEnvironment string, parameters string) string {
return fmt.Sprintf(`
resource "delphix_appdata_dsource" "new_data_dsource" {
source_value = "%s"
Expand All @@ -106,7 +106,7 @@ resource "delphix_appdata_dsource" "new_data_dsource" {
resync = true
})
}
`, sourceId, groupId, name, environmentUser, stagingEnvironment, postgresPort)
`, sourceId, groupId, name, environmentUser, stagingEnvironment, parameters)
}

func testDsourceExists(n string, sourceId string) resource.TestCheckFunc {
Expand Down
6 changes: 4 additions & 2 deletions internal/provider/resource_vdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,10 @@ func resourceVdbRead(ctx context.Context, d *schema.ResourceData, meta interface
d.Set("post_stop", flattenHooks(result.GetHooks().PostStop))
d.Set("pre_rollback", flattenHooks(result.GetHooks().PreRollback))
d.Set("post_rollback", flattenHooks(result.GetHooks().PostRollback))
d.Set("database_name", result.GetDatabaseName())
if !*result.IsAppdata {
d.Set("database_name", result.GetDatabaseName())
}

d.Set("tags", flattenTags(result.GetTags()))
d.Set("vdb_restart", result.GetVdbRestart())

Expand Down Expand Up @@ -1927,7 +1930,6 @@ func resourceVdbUpdate(ctx context.Context, d *schema.ResourceData, meta interfa
tflog.Debug(ctx, "tag to be deleted: "+toTagArray(oldTag)[0].GetKey()+" "+toTagArray(oldTag)[0].GetValue())
deleteTag := *dctapi.NewDeleteTag()
tagDelResp, tagDelErr := client.VDBsAPI.DeleteVdbTags(ctx, vdbId).DeleteTag(deleteTag).Execute()
tflog.Debug(ctx, "tag delete response: "+tagDelResp.Status)
if diags := apiErrorResponseHelper(ctx, nil, tagDelResp, tagDelErr); diags != nil {
revertChanges(d, changedKeys)
updateFailure = true
Expand Down
9 changes: 5 additions & 4 deletions internal/provider/resource_vdb_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func resourceVdbGroup() *schema.Resource {
},
"vdb_ids": {
Type: schema.TypeList,
Required: true,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Expand All @@ -45,9 +45,9 @@ func resourceVdbGroupCreate(ctx context.Context, d *schema.ResourceData, meta in

client := meta.(*apiClient).client

apiRes, httpRes, err := client.VDBGroupsAPI.CreateVdbGroup(ctx).CreateVDBGroupRequest(*dctapi.NewCreateVDBGroupRequest(
d.Get("name").(string),
)).Execute()
vdbGroupCreateReq := *dctapi.NewCreateVDBGroupRequest(d.Get("name").(string))
vdbGroupCreateReq.SetVdbIds(toStringArray(d.Get("vdb_ids")))
apiRes, httpRes, err := client.VDBGroupsAPI.CreateVdbGroup(ctx).CreateVDBGroupRequest(vdbGroupCreateReq).Execute()

if diags := apiErrorResponseHelper(ctx, apiRes, httpRes, err); diags != nil {
return diags
Expand All @@ -74,6 +74,7 @@ func resourceVdbGroupRead(ctx context.Context, d *schema.ResourceData, meta inte
apiRes, httpRes, err := client.VDBGroupsAPI.GetVdbGroup(ctx, vdbGroupId).Execute()

if diags := apiErrorResponseHelper(ctx, apiRes, httpRes, err); diags != nil {
d.SetId("")
return diags
}

Expand Down
11 changes: 1 addition & 10 deletions internal/provider/resource_vdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ func testAccVdbAppDataPreCheck(t *testing.T) {
if err := os.Getenv("APPDATA_SOURCE_PARAMS"); err == "" {
t.Fatal("APPDATA_SOURCE_PARAMS must be set for vdb acceptance tests")
}
if err := os.Getenv("APPDATA_CONFIG_PARAMS"); err == "" {
t.Fatal("APPDATA_CONFIG_PARAMS must be set for vdb acceptance tests")
}
}

func testAccCheckDctVDBConfigBasic() string {
Expand All @@ -111,15 +108,13 @@ func testAccCheckDctVDBConfigBasic() string {
func testAccCheckDctVDBConfigAppDataBasic() string {
appdata_datasource_id := os.Getenv("APPDATA_DATASOURCE_ID")
appdata_source_params := os.Getenv("APPDATA_SOURCE_PARAMS")
appdata_config_params := os.Getenv("APPDATA_CONFIG_PARAMS")
return fmt.Sprintf(`
resource "delphix_vdb" "new_appdata" {
auto_select_repository = true
source_data_id = "%s"
appdata_source_params = jsonencode(%s)
appdata_config_params = jsonencode(%s)
}
`, appdata_datasource_id, appdata_source_params, appdata_config_params)
`, appdata_datasource_id, appdata_source_params)
}

func testAccCheckDctVDBBookmarkConfigBasic() string {
Expand Down Expand Up @@ -185,8 +180,6 @@ func testAccCheckDctVDBBookmarkConfigBasic() string {
}
`, bookmark_id)

print(resource)

return resource

}
Expand Down Expand Up @@ -314,8 +307,6 @@ func testAccCheckVdbDestroy(s *terraform.State) error {

func testAccCheckVdbDestroyBookmark(s *terraform.State) error {
client := testAccProvider.Meta().(*apiClient).client

print("Deleting parent vdb " + vdb_id)
deleteVdbParams := dctapi.NewDeleteVDBParametersWithDefaults()
deleteVdbParams.SetForce(false)
client.VDBsAPI.DeleteVdb(context.Background(), vdb_id).DeleteVDBParameters(*deleteVdbParams).Execute()
Expand Down
5 changes: 4 additions & 1 deletion internal/provider/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"math"
"net/http"
"reflect"
"strconv"
"time"

Expand Down Expand Up @@ -285,7 +286,9 @@ func enableVDB(ctx context.Context, client *dctapi.APIClient, vdbId string) diag
func revertChanges(d *schema.ResourceData, changedKeys []string) {
for _, key := range changedKeys {
old, _ := d.GetChange(key)
d.Set(key, old)
if !reflect.ValueOf(old).IsZero() { // so that a previously optional param is not set to blank erroraneously
d.Set(key, old)
}
}
}

Expand Down