|
89 | 89 | "storage_credential": {`CREATE_EXTERNAL_LOCATION`, `CREATE_EXTERNAL_TABLE`}, |
90 | 90 | "foreign_connection": {`CREATE_FOREIGN_CATALOG`}, |
91 | 91 | } |
92 | | - ParentDirectoryExtraKey = "parent_directory" |
| 92 | + ParentDirectoryExtraKey = "parent_directory" |
| 93 | + dbManagedExternalLocation = "__databricks_managed_storage_location" |
93 | 94 | ) |
94 | 95 |
|
95 | 96 | func generateMountBody(ic *importContext, body *hclwrite.Body, r *resource) error { |
@@ -899,9 +900,8 @@ var resourcesMap map[string]importable = map[string]importable{ |
899 | 900 | {Path: "libraries.jar", Resource: "databricks_repo", Match: "workspace_path", |
900 | 901 | MatchType: MatchPrefix, SearchValueTransformFunc: appendEndingSlashToDirName}, |
901 | 902 | }, |
902 | | - // TODO: special formatting required, where JSON is written line by line |
903 | | - // so that we're able to do the references |
904 | | - Body: resourceOrDataBlockBody, |
| 903 | + // TODO: implement a custom Body that will write with special formatting, where |
| 904 | + // JSON is written line by line so that we're able to do the references |
905 | 905 | }, |
906 | 906 | "databricks_group": { |
907 | 907 | Service: "groups", |
@@ -1051,7 +1051,6 @@ var resourcesMap map[string]importable = map[string]importable{ |
1051 | 1051 |
|
1052 | 1052 | return nil |
1053 | 1053 | }, |
1054 | | - Body: resourceOrDataBlockBody, |
1055 | 1054 | }, |
1056 | 1055 | "databricks_group_member": { |
1057 | 1056 | Service: "groups", |
@@ -2291,7 +2290,6 @@ var resourcesMap map[string]importable = map[string]importable{ |
2291 | 2290 | } |
2292 | 2291 | return nil |
2293 | 2292 | }, |
2294 | | - Body: resourceOrDataBlockBody, |
2295 | 2293 | Depends: []reference{ |
2296 | 2294 | {Path: "path", Resource: "databricks_user", Match: "home"}, |
2297 | 2295 | {Path: "path", Resource: "databricks_service_principal", Match: "home"}, |
@@ -2964,6 +2962,14 @@ var resourcesMap map[string]importable = map[string]importable{ |
2964 | 2962 | WorkspaceLevel: true, |
2965 | 2963 | Service: "uc-storage-credentials", |
2966 | 2964 | Import: func(ic *importContext, r *resource) error { |
| 2965 | + if r.ID == "__databricks_managed_storage_credential" { |
| 2966 | + // it's created by default and can't be imported |
| 2967 | + // TODO: add check for "securable_kind":"STORAGE_CREDENTIAL_DB_AWS_IAM" when we get it in the credential |
| 2968 | + r.Mode = "data" |
| 2969 | + data := tfcatalog.ResourceStorageCredential().ToResource().TestResourceData() |
| 2970 | + obj := tfcatalog.StorageCredentialInfo{Name: r.ID} |
| 2971 | + r.Data = ic.generateNewData(data, "databricks_storage_credential", r.ID, obj) |
| 2972 | + } |
2967 | 2973 | ic.emitUCGrantsWithOwner("storage_credential/"+r.ID, r) |
2968 | 2974 | if r.Data != nil { |
2969 | 2975 | isolationMode := r.Data.Get("isolation_mode").(string) |
@@ -3036,6 +3042,14 @@ var resourcesMap map[string]importable = map[string]importable{ |
3036 | 3042 | WorkspaceLevel: true, |
3037 | 3043 | Service: "uc-external-locations", |
3038 | 3044 | Import: func(ic *importContext, r *resource) error { |
| 3045 | + if r.ID == dbManagedExternalLocation { |
| 3046 | + // it's created by default and can't be imported |
| 3047 | + // TODO: add check for "securable_kind":"EXTERNAL_LOCATION_DB_STORAGE" when we get it in the credential |
| 3048 | + r.Mode = "data" |
| 3049 | + data := tfcatalog.ResourceExternalLocation().ToResource().TestResourceData() |
| 3050 | + obj := tfcatalog.ExternalLocationInfo{Name: r.ID} |
| 3051 | + r.Data = ic.generateNewData(data, "databricks_external_location", r.ID, obj) |
| 3052 | + } |
3039 | 3053 | ic.emitUCGrantsWithOwner("external_location/"+r.ID, r) |
3040 | 3054 | credentialName := r.Data.Get("credential_name").(string) |
3041 | 3055 | ic.Emit(&resource{ |
@@ -3067,7 +3081,15 @@ var resourcesMap map[string]importable = map[string]importable{ |
3067 | 3081 | } |
3068 | 3082 | return nil |
3069 | 3083 | }, |
3070 | | - ShouldOmitField: shouldOmitWithIsolationMode, |
| 3084 | + ShouldOmitField: func(ic *importContext, pathString string, as *schema.Schema, d *schema.ResourceData) bool { |
| 3085 | + if (pathString == "url" || pathString == "credential_name") && d.Get("name").(string) == dbManagedExternalLocation { |
| 3086 | + return true |
| 3087 | + } |
| 3088 | + if pathString == "isolation_mode" { |
| 3089 | + return d.Get(pathString).(string) != "ISOLATION_MODE_ISOLATED" |
| 3090 | + } |
| 3091 | + return shouldOmitForUnityCatalog(ic, pathString, as, d) |
| 3092 | + }, |
3071 | 3093 | // This external location is automatically created when metastore is created with the `storage_root` |
3072 | 3094 | Ignore: func(ic *importContext, r *resource) bool { |
3073 | 3095 | return r.ID == "metastore_default_location" |
|
0 commit comments