-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Data Lake Store File: updating the ID (#1856)
* Data Lake: exposing the `endpoint` field * Data Lake Store File: switching the ID ``` $ acctests azurerm TestAccAzureRMDataLakeStoreFileMigrateState === RUN TestAccAzureRMDataLakeStoreFileMigrateState 2018/08/31 18:59:29 [INFO] Found AzureRM Data Lake Store File State v0; migrating to v1 2018/08/31 18:59:29 [DEBUG] ARM Data Lake Store File Attributes before Migration: map[string]string{"account_name":"example", "remote_file_path":"/test/blob.vhd"} 2018/08/31 18:59:29 [DEBUG] ARM Data Lake Store File Attributes after State Migration: map[string]string{"remote_file_path":"/test/blob.vhd", "account_name":"example", "id":"example.azuredatalakestore.net/test/blob.vhd"} --- PASS: TestAccAzureRMDataLakeStoreFileMigrateState (0.00s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 0.411s ``` * Data Lake Store File: import support * Parsing the URI correctly
- Loading branch information
1 parent
d8653de
commit 5c7dd38
Showing
7 changed files
with
187 additions
and
16 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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func resourceDataLakeStoreFileMigrateState(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { | ||
switch v { | ||
case 0: | ||
log.Println("[INFO] Found AzureRM Data Lake Store File State v0; migrating to v1") | ||
return resourceDataLakeStoreFileStateV0toV1(is, meta) | ||
default: | ||
return is, fmt.Errorf("Unexpected schema version: %d", v) | ||
} | ||
} | ||
|
||
func resourceDataLakeStoreFileStateV0toV1(is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { | ||
if is.Empty() { | ||
log.Println("[DEBUG] Empty InstanceState; nothing to migrate.") | ||
return is, nil | ||
} | ||
|
||
log.Printf("[DEBUG] ARM Data Lake Store File Attributes before Migration: %#v", is.Attributes) | ||
|
||
client := meta.(*ArmClient).dataLakeStoreFilesClient | ||
|
||
storageAccountName := is.Attributes["account_name"] | ||
filePath := is.Attributes["remote_file_path"] | ||
newID := fmt.Sprintf("%s.%s%s", storageAccountName, client.AdlsFileSystemDNSSuffix, filePath) | ||
is.Attributes["id"] = newID | ||
is.ID = newID | ||
|
||
log.Printf("[DEBUG] ARM Data Lake Store File Attributes after State Migration: %#v", is.Attributes) | ||
|
||
return is, nil | ||
} |
66 changes: 66 additions & 0 deletions
66
azurerm/resource_arm_data_lake_store_file_migration_test.go
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,66 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
// NOTE: this is intentionally an acceptance test (and we're not explicitly setting the env) | ||
// as we want to run this depending on the cloud we're in. | ||
func TestAccAzureRMDataLakeStoreFileMigrateState(t *testing.T) { | ||
config := testGetAzureConfig(t) | ||
if config == nil { | ||
t.SkipNow() | ||
return | ||
} | ||
|
||
client, err := getArmClient(config) | ||
if err != nil { | ||
t.Fatal(fmt.Errorf("Error building ARM Client: %+v", err)) | ||
return | ||
} | ||
|
||
client.StopContext = testAccProvider.StopContext() | ||
|
||
filesClient := client.dataLakeStoreFilesClient | ||
|
||
cases := map[string]struct { | ||
StateVersion int | ||
ID string | ||
InputAttributes map[string]string | ||
ExpectedAttributes map[string]string | ||
}{ | ||
"v0_1_without_value": { | ||
StateVersion: 0, | ||
ID: "some_id", | ||
InputAttributes: map[string]string{ | ||
"remote_file_path": "/test/blob.vhd", | ||
"account_name": "example", | ||
}, | ||
ExpectedAttributes: map[string]string{ | ||
"id": fmt.Sprintf("example.%s/test/blob.vhd", filesClient.AdlsFileSystemDNSSuffix), | ||
}, | ||
}, | ||
} | ||
|
||
for tn, tc := range cases { | ||
is := &terraform.InstanceState{ | ||
ID: tc.ID, | ||
Attributes: tc.InputAttributes, | ||
} | ||
is, err := resourceDataLakeStoreFileMigrateState(tc.StateVersion, is, client) | ||
|
||
if err != nil { | ||
t.Fatalf("bad: %s, err: %#v", tn, err) | ||
} | ||
|
||
for k, v := range tc.ExpectedAttributes { | ||
actual := is.Attributes[k] | ||
if actual != v { | ||
t.Fatalf("Bad Data Lake Store File Migrate for %q: %q\n\n expected: %q", k, actual, v) | ||
} | ||
} | ||
} | ||
} |
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
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