|
| 1 | +package aws |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/databricks/databricks-sdk-go/service/compute" |
| 7 | + "github.com/databricks/terraform-provider-databricks/qa" |
| 8 | +) |
| 9 | + |
| 10 | +func TestInstanceProfilesData(t *testing.T) { |
| 11 | + qa.ResourceFixture{ |
| 12 | + Fixtures: []qa.HTTPFixture{ |
| 13 | + { |
| 14 | + Method: "GET", |
| 15 | + Resource: "/api/2.0/instance-profiles/list", |
| 16 | + Response: compute.ListInstanceProfilesResponse{ |
| 17 | + InstanceProfiles: []compute.InstanceProfile{ |
| 18 | + { |
| 19 | + IamRoleArn: "arn:aws:iam::123456789012:role/S3Access", |
| 20 | + InstanceProfileArn: "arn:aws:iam::123456789012:instance-profile/S3Access", |
| 21 | + IsMetaInstanceProfile: true, |
| 22 | + }, |
| 23 | + { |
| 24 | + IamRoleArn: "arn:aws:iam::123456789098:role/KMSAccess", |
| 25 | + InstanceProfileArn: "arn:aws:iam::123456789098:instance-profile/KMSAccess", |
| 26 | + IsMetaInstanceProfile: false, |
| 27 | + }, |
| 28 | + { |
| 29 | + InstanceProfileArn: "arn:aws:iam::123456789098:instance-profile/different", |
| 30 | + IamRoleArn: "arn:aws:iam::123456789098:role/value", |
| 31 | + IsMetaInstanceProfile: false, |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | + }, |
| 36 | + }, |
| 37 | + Resource: DataSourceInstanceProfiles(), |
| 38 | + Read: true, |
| 39 | + NonWritable: true, |
| 40 | + ID: "_", |
| 41 | + }.ApplyAndExpectData(t, map[string]any{ |
| 42 | + "instance_profiles": []interface{}{ |
| 43 | + map[string]interface{}{ |
| 44 | + "name": "S3Access", |
| 45 | + "arn": "arn:aws:iam::123456789012:instance-profile/S3Access", |
| 46 | + "role_arn": "arn:aws:iam::123456789012:role/S3Access", |
| 47 | + "is_meta": true, |
| 48 | + }, |
| 49 | + map[string]interface{}{ |
| 50 | + "name": "KMSAccess", |
| 51 | + "arn": "arn:aws:iam::123456789098:instance-profile/KMSAccess", |
| 52 | + "role_arn": "arn:aws:iam::123456789098:role/KMSAccess", |
| 53 | + "is_meta": false, |
| 54 | + }, |
| 55 | + map[string]interface{}{ |
| 56 | + "name": "different", |
| 57 | + "arn": "arn:aws:iam::123456789098:instance-profile/different", |
| 58 | + "role_arn": "arn:aws:iam::123456789098:role/value", |
| 59 | + "is_meta": false, |
| 60 | + }, |
| 61 | + }, |
| 62 | + }) |
| 63 | +} |
| 64 | + |
| 65 | +func TestInstanceProfilesDataEmpty(t *testing.T) { |
| 66 | + qa.ResourceFixture{ |
| 67 | + Fixtures: []qa.HTTPFixture{ |
| 68 | + { |
| 69 | + Method: "GET", |
| 70 | + Resource: "/api/2.0/instance-profiles/list", |
| 71 | + Response: compute.ListInstanceProfilesResponse{ |
| 72 | + InstanceProfiles: []compute.InstanceProfile{}, |
| 73 | + }, |
| 74 | + }, |
| 75 | + }, |
| 76 | + Resource: DataSourceInstanceProfiles(), |
| 77 | + Read: true, |
| 78 | + NonWritable: true, |
| 79 | + ID: "_", |
| 80 | + }.ApplyAndExpectData(t, map[string]any{ |
| 81 | + "instance_profiles": []interface{}{}, |
| 82 | + }) |
| 83 | +} |
| 84 | + |
| 85 | +func TestInstanceProfilesDataDuplicate(t *testing.T) { |
| 86 | + qa.ResourceFixture{ |
| 87 | + Fixtures: []qa.HTTPFixture{ |
| 88 | + { |
| 89 | + Method: "GET", |
| 90 | + Resource: "/api/2.0/instance-profiles/list", |
| 91 | + Response: compute.ListInstanceProfilesResponse{ |
| 92 | + InstanceProfiles: []compute.InstanceProfile{ |
| 93 | + { |
| 94 | + IamRoleArn: "arn:aws:iam::123456789012:role/S3Access", |
| 95 | + InstanceProfileArn: "arn:aws:iam::123456789012:instance-profile/S3Access", |
| 96 | + IsMetaInstanceProfile: true, |
| 97 | + }, |
| 98 | + { |
| 99 | + IamRoleArn: "arn:aws:iam::123456789012:role/S3Access", |
| 100 | + InstanceProfileArn: "arn:aws:iam::123456789012:instance-profile/S3Access", |
| 101 | + IsMetaInstanceProfile: true, |
| 102 | + }, |
| 103 | + }, |
| 104 | + }, |
| 105 | + }, |
| 106 | + }, |
| 107 | + Resource: DataSourceInstanceProfiles(), |
| 108 | + Read: true, |
| 109 | + NonWritable: true, |
| 110 | + ID: "_", |
| 111 | + }.ApplyAndExpectData(t, map[string]any{ |
| 112 | + "instance_profiles": []interface{}{ |
| 113 | + map[string]interface{}{ |
| 114 | + "name": "S3Access", |
| 115 | + "arn": "arn:aws:iam::123456789012:instance-profile/S3Access", |
| 116 | + "role_arn": "arn:aws:iam::123456789012:role/S3Access", |
| 117 | + "is_meta": true, |
| 118 | + }, |
| 119 | + map[string]interface{}{ |
| 120 | + "name": "S3Access", |
| 121 | + "arn": "arn:aws:iam::123456789012:instance-profile/S3Access", |
| 122 | + "role_arn": "arn:aws:iam::123456789012:role/S3Access", |
| 123 | + "is_meta": true, |
| 124 | + }, |
| 125 | + }, |
| 126 | + }) |
| 127 | +} |
0 commit comments