@@ -42,6 +42,73 @@ func TestResourceInstanceProfileCreate(t *testing.T) {
4242 assert .Equal (t , "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" , d .Id ())
4343}
4444
45+ func TestResourceInstanceProfileWithRoleCreate (t * testing.T ) {
46+ d , err := qa.ResourceFixture {
47+ Fixtures : []qa.HTTPFixture {
48+ {
49+ Method : "POST" ,
50+ Resource : "/api/2.0/instance-profiles/add" ,
51+ ExpectedRequest : InstanceProfileInfo {
52+ InstanceProfileArn : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
53+ IamRoleArn : "arn:aws:iam::999999999999:role/my-fake-instance-profile-role" ,
54+ },
55+ },
56+ {
57+ Method : "GET" ,
58+ Resource : "/api/2.0/instance-profiles/list" ,
59+ Response : InstanceProfileList {
60+ InstanceProfiles : []InstanceProfileInfo {
61+ {
62+ InstanceProfileArn : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
63+ },
64+ },
65+ },
66+ },
67+ },
68+ Resource : ResourceInstanceProfile (),
69+ State : map [string ]any {
70+ "instance_profile_arn" : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
71+ "iam_role_arn" : "arn:aws:iam::999999999999:role/my-fake-instance-profile-role" ,
72+ },
73+ Create : true ,
74+ }.Apply (t )
75+ assert .NoError (t , err , err )
76+ assert .Equal (t , "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" , d .Id ())
77+ }
78+
79+ func TestResourceInstanceProfileWithEmptyRoleCreate (t * testing.T ) {
80+ d , err := qa.ResourceFixture {
81+ Fixtures : []qa.HTTPFixture {
82+ {
83+ Method : "POST" ,
84+ Resource : "/api/2.0/instance-profiles/add" ,
85+ ExpectedRequest : InstanceProfileInfo {
86+ InstanceProfileArn : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
87+ },
88+ },
89+ {
90+ Method : "GET" ,
91+ Resource : "/api/2.0/instance-profiles/list" ,
92+ Response : InstanceProfileList {
93+ InstanceProfiles : []InstanceProfileInfo {
94+ {
95+ InstanceProfileArn : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
96+ },
97+ },
98+ },
99+ },
100+ },
101+ Resource : ResourceInstanceProfile (),
102+ State : map [string ]any {
103+ "instance_profile_arn" : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
104+ "iam_role_arn" : "" ,
105+ },
106+ Create : true ,
107+ }.Apply (t )
108+ assert .NoError (t , err , err )
109+ assert .Equal (t , "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" , d .Id ())
110+ }
111+
45112func TestResourceInstanceProfileCreate_Error (t * testing.T ) {
46113 d , err := qa.ResourceFixture {
47114 Fixtures : []qa.HTTPFixture {
@@ -65,7 +132,7 @@ func TestResourceInstanceProfileCreate_Error(t *testing.T) {
65132 assert .Equal (t , "" , d .Id (), "Id should be empty for error creates" )
66133}
67134
68- func TestResourceInstanceProfileCreate_Error_InvalidARN (t * testing.T ) {
135+ func TestResourceInstanceProfileValidate_Error_InvalidInstanceProfileARN (t * testing.T ) {
69136 _ , err := qa.ResourceFixture {
70137 Resource : ResourceInstanceProfile (),
71138 State : map [string ]any {
@@ -76,6 +143,64 @@ func TestResourceInstanceProfileCreate_Error_InvalidARN(t *testing.T) {
76143 assert .EqualError (t , err , "invalid config supplied. [instance_profile_arn] Invalid ARN" )
77144}
78145
146+ func TestResourceInstanceProfileValidate_Error_InvalidRoleARN (t * testing.T ) {
147+ _ , err := qa.ResourceFixture {
148+ Resource : ResourceInstanceProfile (),
149+ State : map [string ]any {
150+ "instance_profile_arn" : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
151+ "iam_role_arn" : "abc" ,
152+ },
153+ Create : true ,
154+ }.Apply (t )
155+ assert .EqualError (t , err , "invalid config supplied. [iam_role_arn] Invalid ARN" )
156+ }
157+
158+ func TestResourceInstanceProfileValidate_Error_MalformedARN (t * testing.T ) {
159+ _ , err := qa.ResourceFixture {
160+ Resource : ResourceInstanceProfile (),
161+ State : map [string ]any {
162+ "instance_profile_arn" : "arn:aws:iam::instance-profile/my-fake-instance-profile" ,
163+ },
164+ Create : true ,
165+ }.Apply (t )
166+ assert .EqualError (t , err , "invalid config supplied. [instance_profile_arn] Invalid ARN" )
167+ }
168+
169+ func TestResourceInstanceProfileValidate_Error_WrongTypeProfileARN (t * testing.T ) {
170+ _ , err := qa.ResourceFixture {
171+ Resource : ResourceInstanceProfile (),
172+ State : map [string ]any {
173+ "instance_profile_arn" : "arn:aws:iam::999999999999:failure/my-fake-instance-profile" ,
174+ },
175+ Create : true ,
176+ }.Apply (t )
177+ assert .EqualError (t , err , "invalid config supplied. [instance_profile_arn] Invalid ARN" )
178+ }
179+
180+ func TestResourceInstanceProfileValidate_Error_WrongTypeRoleARN (t * testing.T ) {
181+ _ , err := qa.ResourceFixture {
182+ Resource : ResourceInstanceProfile (),
183+ State : map [string ]any {
184+ "instance_profile_arn" : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
185+ "iam_role_arn" : "arn:aws:iam::999999999999:failure/my-fake-instance-profile-role" ,
186+ },
187+ Create : true ,
188+ }.Apply (t )
189+ assert .EqualError (t , err , "invalid config supplied. [iam_role_arn] Invalid ARN" )
190+ }
191+
192+ func TestResourceInstanceProfileValidate_Error_EmptyInstanceProfileARN (t * testing.T ) {
193+ _ , err := qa.ResourceFixture {
194+ Resource : ResourceInstanceProfile (),
195+ State : map [string ]any {
196+ "instance_profile_arn" : "" ,
197+ "iam_role_arn" : "arn:aws:iam::999999999999:role/my-fake-instance-profile-role" ,
198+ },
199+ Create : true ,
200+ }.Apply (t )
201+ assert .EqualError (t , err , "invalid config supplied. [instance_profile_arn] Invalid ARN" )
202+ }
203+
79204func TestResourceInstanceProfileRead (t * testing.T ) {
80205 d , err := qa.ResourceFixture {
81206 Fixtures : []qa.HTTPFixture {
@@ -180,6 +305,77 @@ func TestResourceInstanceProfileDelete_Error(t *testing.T) {
180305 assert .Equal (t , "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" , d .Id ())
181306}
182307
308+ func TestResourceInstanceProfileUpdate (t * testing.T ) {
309+ d , err := qa.ResourceFixture {
310+ Fixtures : []qa.HTTPFixture {
311+ {
312+ Method : "GET" ,
313+ Resource : "/api/2.0/instance-profiles/list" ,
314+ Response : InstanceProfileList {
315+ InstanceProfiles : []InstanceProfileInfo {
316+ {
317+ InstanceProfileArn : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
318+ },
319+ },
320+ },
321+ },
322+ {
323+ Method : "POST" ,
324+ Resource : "/api/2.0/instance-profiles/edit" ,
325+ ExpectedRequest : InstanceProfileInfo {
326+ InstanceProfileArn : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
327+ IamRoleArn : "arn:aws:iam::999999999999:role/my-fake-instance-profile-role" ,
328+ },
329+ },
330+ },
331+ Resource : ResourceInstanceProfile (),
332+ State : map [string ]any {
333+ "instance_profile_arn" : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
334+ "iam_role_arn" : "arn:aws:iam::999999999999:role/my-fake-instance-profile-role" ,
335+ },
336+ Update : true ,
337+ ID : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
338+ }.Apply (t )
339+ assert .NoError (t , err , err )
340+ assert .Equal (t , "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" , d .Id ())
341+ }
342+
343+ func TestResourceInstanceProfileUpdate_Error (t * testing.T ) {
344+ d , err := qa.ResourceFixture {
345+ Fixtures : []qa.HTTPFixture {
346+ {
347+ Method : "GET" ,
348+ Resource : "/api/2.0/instance-profiles/list" ,
349+ Response : InstanceProfileList {
350+ InstanceProfiles : []InstanceProfileInfo {
351+ {
352+ InstanceProfileArn : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
353+ },
354+ },
355+ },
356+ },
357+ {
358+ Method : "POST" ,
359+ Resource : "/api/2.0/instance-profiles/edit" ,
360+ Response : common.APIErrorBody {
361+ ErrorCode : "INVALID_REQUEST" ,
362+ Message : "Internal error happened" ,
363+ },
364+ Status : 400 ,
365+ },
366+ },
367+ Resource : ResourceInstanceProfile (),
368+ State : map [string ]any {
369+ "instance_profile_arn" : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
370+ "iam_role_arn" : "" ,
371+ },
372+ Update : true ,
373+ ID : "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" ,
374+ }.Apply (t )
375+ qa .AssertErrorStartsWith (t , err , "Internal error happened" )
376+ assert .Equal (t , "arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile" , d .Id ())
377+ }
378+
183379func TestAccAwsInstanceProfiles (t * testing.T ) {
184380 arn := qa .GetEnvOrSkipTest (t , "TEST_EC2_INSTANCE_PROFILE" )
185381 client := common .NewClientFromEnvironment ()
0 commit comments