@@ -56,6 +56,109 @@ func TestResourceCredentialsCreate(t *testing.T) {
5656 })
5757}
5858
59+ func TestAccountIdOnlyInState (t * testing.T ) {
60+ qa.ResourceFixture {
61+ Fixtures : []qa.HTTPFixture {
62+ {
63+ Method : "POST" ,
64+ Resource : "/api/2.0/accounts/abc/credentials" ,
65+ ExpectedRequest : Credentials {
66+ CredentialsName : "Cross-account ARN" ,
67+ AwsCredentials : & AwsCredentials {
68+ StsRole : & StsRole {
69+ RoleArn : "arn:aws:iam::098765:role/cross-account" ,
70+ },
71+ },
72+ },
73+ Response : Credentials {
74+ CredentialsID : "cid" ,
75+ },
76+ },
77+ {
78+ Method : "GET" ,
79+ Resource : "/api/2.0/accounts/abc/credentials/cid?" ,
80+ Response : Credentials {
81+ CredentialsID : "cid" ,
82+ CredentialsName : "Cross-account ARN" ,
83+ AwsCredentials : & AwsCredentials {
84+ StsRole : & StsRole {
85+ RoleArn : "arn:aws:iam::098765:role/cross-account" ,
86+ },
87+ },
88+ },
89+ },
90+ },
91+ Resource : ResourceMwsCredentials (),
92+ State : map [string ]any {
93+ "account_id" : "abc" ,
94+ "credentials_name" : "Cross-account ARN" ,
95+ "role_arn" : "arn:aws:iam::098765:role/cross-account" ,
96+ },
97+ Create : true ,
98+ }.ApplyAndExpectData (t , map [string ]any {
99+ "id" : "abc/cid" ,
100+ "role_arn" : "arn:aws:iam::098765:role/cross-account" ,
101+ })
102+ }
103+
104+ func TestAccountIdOnlyInConfig (t * testing.T ) {
105+ qa.ResourceFixture {
106+ Fixtures : []qa.HTTPFixture {
107+ {
108+ Method : "POST" ,
109+ Resource : "/api/2.0/accounts/abc/credentials" ,
110+ ExpectedRequest : Credentials {
111+ CredentialsName : "Cross-account ARN" ,
112+ AwsCredentials : & AwsCredentials {
113+ StsRole : & StsRole {
114+ RoleArn : "arn:aws:iam::098765:role/cross-account" ,
115+ },
116+ },
117+ },
118+ Response : Credentials {
119+ CredentialsID : "cid" ,
120+ },
121+ },
122+ {
123+ Method : "GET" ,
124+ Resource : "/api/2.0/accounts/abc/credentials/cid?" ,
125+ Response : Credentials {
126+ CredentialsID : "cid" ,
127+ CredentialsName : "Cross-account ARN" ,
128+ AwsCredentials : & AwsCredentials {
129+ StsRole : & StsRole {
130+ RoleArn : "arn:aws:iam::098765:role/cross-account" ,
131+ },
132+ },
133+ },
134+ },
135+ },
136+ Resource : ResourceMwsCredentials (),
137+ State : map [string ]any {
138+ "credentials_name" : "Cross-account ARN" ,
139+ "role_arn" : "arn:aws:iam::098765:role/cross-account" ,
140+ },
141+ Create : true ,
142+ AccountID : "abc" ,
143+ }.ApplyAndExpectData (t , map [string ]any {
144+ "id" : "abc/cid" ,
145+ "role_arn" : "arn:aws:iam::098765:role/cross-account" ,
146+ })
147+ }
148+
149+ func TestFailIfDifferentAccountIds (t * testing.T ) {
150+ qa.ResourceFixture {
151+ Resource : ResourceMwsCredentials (),
152+ State : map [string ]any {
153+ "account_id" : "another" ,
154+ "credentials_name" : "Cross-account ARN" ,
155+ "role_arn" : "arn:aws:iam::098765:role/cross-account" ,
156+ },
157+ Create : true ,
158+ AccountID : "abc" ,
159+ }.ExpectError (t , "account ID is already set to abc" )
160+ }
161+
59162func TestResourceCredentialsCreateWithoutAccId (t * testing.T ) {
60163 qa.ResourceFixture {
61164 Fixtures : []qa.HTTPFixture {
0 commit comments