|
| 1 | +package storage |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/databrickslabs/terraform-provider-databricks/clusters" |
| 8 | + "github.com/databrickslabs/terraform-provider-databricks/common" |
| 9 | + "github.com/databrickslabs/terraform-provider-databricks/qa" |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | +) |
| 12 | + |
| 13 | +func TestPreprocessS3MountOnDeletedClusterNoInstanceProfileSpecifiedError(t *testing.T) { |
| 14 | + qa.HTTPFixturesApply(t, []qa.HTTPFixture{ |
| 15 | + { |
| 16 | + Method: "GET", |
| 17 | + Resource: "/api/2.0/clusters/get?cluster_id=removed-cluster", |
| 18 | + Status: 404, |
| 19 | + Response: common.NotFound("cluster deleted"), |
| 20 | + }, |
| 21 | + }, func(ctx context.Context, client *common.DatabricksClient) { |
| 22 | + r := ResourceMount() |
| 23 | + d := r.TestResourceData() |
| 24 | + d.Set("uri", "s3://bucket") |
| 25 | + d.Set("cluster_id", "removed-cluster") |
| 26 | + err := preprocessS3MountGeneric(ctx, r.Schema, d, client) |
| 27 | + assert.EqualError(t, err, "instance profile is required to re-create mounting cluster") |
| 28 | + }) |
| 29 | +} |
| 30 | + |
| 31 | +func TestPreprocessS3MountOnDeletedClusterWorks(t *testing.T) { |
| 32 | + qa.HTTPFixturesApply(t, []qa.HTTPFixture{ |
| 33 | + { |
| 34 | + Method: "GET", |
| 35 | + Resource: "/api/2.0/clusters/get?cluster_id=removed-cluster", |
| 36 | + Status: 404, |
| 37 | + Response: common.NotFound("cluster deleted"), |
| 38 | + }, |
| 39 | + { |
| 40 | + Method: "GET", |
| 41 | + Resource: "/api/2.0/clusters/list", |
| 42 | + Response: clusters.ClusterList{ |
| 43 | + Clusters: []clusters.ClusterInfo{}, |
| 44 | + }, |
| 45 | + }, |
| 46 | + { |
| 47 | + ReuseRequest: true, |
| 48 | + Method: "GET", |
| 49 | + Resource: "/api/2.0/clusters/spark-versions", |
| 50 | + }, |
| 51 | + { |
| 52 | + ReuseRequest: true, |
| 53 | + Method: "GET", |
| 54 | + Resource: "/api/2.0/clusters/list-node-types", |
| 55 | + }, |
| 56 | + { |
| 57 | + Method: "POST", |
| 58 | + Resource: "/api/2.0/clusters/create", |
| 59 | + ExpectedRequest: clusters.Cluster{ |
| 60 | + CustomTags: map[string]string{ |
| 61 | + "ResourceClass": "SingleNode", |
| 62 | + }, |
| 63 | + ClusterName: "terraform-mount-s3-access", |
| 64 | + SparkVersion: "7.3.x-scala2.12", |
| 65 | + NumWorkers: 0, |
| 66 | + NodeTypeID: "i3.xlarge", |
| 67 | + AwsAttributes: &clusters.AwsAttributes{ |
| 68 | + Availability: "SPOT", |
| 69 | + InstanceProfileArn: "arn:aws:iam::1234567:instance-profile/s3-access", |
| 70 | + }, |
| 71 | + AutoterminationMinutes: 10, |
| 72 | + SparkConf: map[string]string{ |
| 73 | + "spark.databricks.cluster.profile": "singleNode", |
| 74 | + "spark.master": "local[*]", |
| 75 | + "spark.scheduler.mode": "FIFO", |
| 76 | + }, |
| 77 | + }, |
| 78 | + Response: clusters.ClusterID{ |
| 79 | + ClusterID: "new-cluster", |
| 80 | + }, |
| 81 | + }, |
| 82 | + { |
| 83 | + Method: "GET", |
| 84 | + Resource: "/api/2.0/clusters/get?cluster_id=new-cluster", |
| 85 | + Response: clusters.ClusterInfo{ |
| 86 | + ClusterID: "new-cluster", |
| 87 | + State: "RUNNING", |
| 88 | + StateMessage: "created", |
| 89 | + }, |
| 90 | + }, |
| 91 | + }, func(ctx context.Context, client *common.DatabricksClient) { |
| 92 | + r := ResourceMount() |
| 93 | + d := r.TestResourceData() |
| 94 | + d.MarkNewResource() |
| 95 | + common.StructToData(GenericMount{ |
| 96 | + URI: "s3://bucket", |
| 97 | + ClusterID: "removed-cluster", |
| 98 | + S3: &S3IamMount{ |
| 99 | + InstanceProfile: "arn:aws:iam::1234567:instance-profile/s3-access", |
| 100 | + }, |
| 101 | + }, r.Schema, d) |
| 102 | + err := preprocessS3MountGeneric(ctx, r.Schema, d, client) |
| 103 | + assert.NoError(t, err) |
| 104 | + assert.Equal(t, "new-cluster", d.Get("cluster_id")) |
| 105 | + }) |
| 106 | +} |
0 commit comments