Skip to content

Commit

Permalink
feat: add AWS GOV support in api_integration (#1118)
Browse files Browse the repository at this point in the history
* Updating api_provider list

* api acceptance test

* adding test for aws_gov_api_gateway

* changing the region from us-gov-west-2 to us-gov-west-1 in expectRead func

Co-authored-by: Jason Lin <[email protected]>
  • Loading branch information
sfc-gh-kumaurya and sfc-gh-jalin authored Jul 14, 2022
1 parent 82616e3 commit 2705970
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/resources/api_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var apiIntegrationSchema = map[string]*schema.Schema{
"api_provider": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"aws_api_gateway", "aws_private_api_gateway", "azure_api_management"}, false),
ValidateFunc: validation.StringInSlice([]string{"aws_api_gateway", "aws_private_api_gateway", "azure_api_management", "aws_gov_api_gateway", "aws_gov_private_api_gateway"}, false),
Description: "Specifies the HTTPS proxy service type.",
},
"api_aws_role_arn": {
Expand Down Expand Up @@ -304,7 +304,7 @@ func setAPIProviderSettings(data *schema.ResourceData, stmt snowflake.SettingBui
stmt.SetRaw("API_PROVIDER=" + apiProvider)

switch apiProvider {
case "aws_api_gateway", "aws_private_api_gateway":
case "aws_api_gateway", "aws_private_api_gateway", "aws_gov_api_gateway", "aws_gov_private_api_gateway":
v, ok := data.GetOk("api_aws_role_arn")
if !ok {
return fmt.Errorf("If you use AWS api provider you must specify an api_aws_role_arn")
Expand Down
38 changes: 38 additions & 0 deletions pkg/resources/api_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@ func TestAPIIntegrationCreate(t *testing.T) {
"api_provider": "aws_api_gateway",
"api_aws_role_arn": "arn:aws:iam::000000000001:/role/test",
}

in2 := map[string]interface{}{
"name": "test_gov_api_integration",
"api_allowed_prefixes": []interface{}{"https://123456.execute-api.us-gov-west-1.amazonaws.com/prod/"},
"api_provider": "aws_gov_api_gateway",
"api_aws_role_arn": "arn:aws:iam::000000000001:/role/test",
}

d := schema.TestResourceDataRaw(t, resources.APIIntegration().Schema, in)
d2 := schema.TestResourceDataRaw(t, resources.APIIntegration().Schema, in2)

r.NotNil(d)
r.NotNil(d2)

WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(
Expand All @@ -39,6 +50,16 @@ func TestAPIIntegrationCreate(t *testing.T) {
err := resources.CreateAPIIntegration(d, db)
r.NoError(err)
})

WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(
`^CREATE API INTEGRATION "test_gov_api_integration" API_PROVIDER=aws_gov_api_gateway API_AWS_ROLE_ARN='arn:aws:iam::000000000001:/role/test' API_ALLOWED_PREFIXES=\('https://123456.execute-api.us-gov-west-1.amazonaws.com/prod/'\) ENABLED=true$`,
).WillReturnResult(sqlmock.NewResult(1, 1))
expectReadGovAPIIntegration(mock)

err := resources.CreateAPIIntegration(d2, db)
r.NoError(err)
})
}

func TestAPIIntegrationRead(t *testing.T) {
Expand Down Expand Up @@ -82,3 +103,20 @@ func expectReadAPIIntegration(mock sqlmock.Sqlmock) {

mock.ExpectQuery(`DESCRIBE API INTEGRATION "test_api_integration"$`).WillReturnRows(descRows)
}

func expectReadGovAPIIntegration(mock sqlmock.Sqlmock) {
showRows := sqlmock.NewRows([]string{
"name", "type", "category", "enabled", "created_on"},
).AddRow("test_gov_api_integration", "EXTERNAL_API", "API", true, "now")
mock.ExpectQuery(`^SHOW API INTEGRATIONS LIKE 'test_gov_api_integration'$`).WillReturnRows(showRows)

descRows := sqlmock.NewRows([]string{
"property", "property_type", "property_value", "property_default",
}).AddRow("ENABLED", "Boolean", true, false).
AddRow("API_ALLOWED_PREFIXES", "List", "https://123456.execute-api.us-gov-west-1.amazonaws.com/prod/,https://123456.execute-api.us-gov-west-1.amazonaws.com/staging/", nil).
AddRow("API_AWS_IAM_USER_ARN", "String", "arn:aws:iam::000000000000:/user/test", nil).
AddRow("API_AWS_ROLE_ARN", "String", "arn:aws:iam::000000000001:/role/test", nil).
AddRow("API_AWS_EXTERNAL_ID", "String", "AGreatExternalID", nil)

mock.ExpectQuery(`DESCRIBE API INTEGRATION "test_gov_api_integration"$`).WillReturnRows(descRows)
}

0 comments on commit 2705970

Please sign in to comment.