Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_api_management_api - support for subscription_required #4885

Merged
merged 6 commits into from Jun 24, 2020

Conversation

jackbatzner
Copy link
Contributor

@jackbatzner jackbatzner commented Nov 14, 2019

Add subscription_required to data and resource for azurerm_api_management_api

(fixes ##3863 )

@mbfrahry mbfrahry self-assigned this Nov 14, 2019
Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Brunhil, thanks for opening this PR. There are a couple misspellings which cause the provider to panic which might cause us to lose users statefiles. Once those are fixed up, can you add tests to confirm this functionality works. Those tests are useful to catch these panics before review time as well.

azurerm/resource_arm_api_management_api.go Outdated Show resolved Hide resolved
azurerm/resource_arm_api_management_api.go Outdated Show resolved Hide resolved
website/docs/d/api_management_api.html.markdown Outdated Show resolved Hide resolved
@jackbatzner
Copy link
Contributor Author

Good catch with the spelling @mbfrahry , it was one of those days yesterday -_-. I'll get the tests added and other changes fixed and push them up.

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Brunhil, unfortunately we're still not quite there. One test panicked and the other 2 modified in this PR failed.

azurerm/resource_arm_api_management_api.go Outdated Show resolved Hide resolved
@@ -28,6 +28,8 @@ func TestAccAzureRMApiManagementApi_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "soap_pass_through", "false"),
resource.TestCheckResourceAttr(resourceName, "is_current", "true"),
resource.TestCheckResourceAttr(resourceName, "is_online", "false"),
resource.TestCheckResourceAttr(resourceName, "authentication_settings.#", "1"),
resource.TestCheckResourceAttr(resourceName, "authentication_settings.0.subscription_key_required", "true"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test now errors. It doesn't look like this is being set properly

------- Stdout: -------
=== RUN   TestAccAzureRMApiManagementApi_basic
--- FAIL: TestAccAzureRMApiManagementApi_basic (2612.17s)
    testing.go:569: Step 0 error: Check failed: Check 6/6 error: azurerm_api_management_api.test: Attribute 'authentication_settings.0.subscription_key_required' not found
FAIL

@@ -120,6 +122,33 @@ func TestAccAzureRMApiManagementApi_version(t *testing.T) {
})
}

func TestAccAzureRMApiManagementApi_authenticationSettings(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is also failing

=== RUN   TestAccAzureRMApiManagementApi_authenticationSettings
--- FAIL: TestAccAzureRMApiManagementApi_authenticationSettings (2825.43s)
    testing.go:569: Step 0 error: Check failed: Check 3/3 error: azurerm_api_management_api.test: Attribute 'authentication_settings.0.subscription_key_required' not found
FAIL

Copy link
Member

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @Brunhil

Thanks for pushing those changes - running the tests again it looks like the AuthenticationSettings block may not be being returned from the API here (which is why this shows as missing):

Screenshot 2019-11-17 at 17 03 17

Out of interest are you able to confirm if this is present in the response for a provisioned APIM API? It's generally easiest to see this in the resource response via resources.azure.com (or by proxing Terraform via Charles/Fiddler depending on your OS)

Thanks!

"authentication_settings": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running the tests for this - both the basic and authenticationRequired tests fail:

=== RUN   TestAccAzureRMApiManagementApi_authenticationSettings
--- FAIL: TestAccAzureRMApiManagementApi_authenticationSettings (2264.83s)
    testing.go:569: Step 0 error: Check failed: Check 3/3 error: azurerm_api_management_api.test: Attribute 'authentication_settings.0.subscription_key_required' not found
FAIL

and

------- Stdout: -------
=== RUN   TestAccAzureRMApiManagementApi_basic
--- FAIL: TestAccAzureRMApiManagementApi_basic (2276.86s)
    testing.go:569: Step 0 error: Check failed: Check 6/6 error: azurerm_api_management_api.test: Attribute 'authentication_settings.0.subscription_key_required' not found
FAIL

is it possible this information isn't returned from the API? If so, we may need to update the flatten function to set a default value here: https://github.com/terraform-providers/terraform-provider-azurerm/pull/4885/files#diff-e28c81f44cf2e8523cae5b19081cf837R494

e.g. something like this:

func flattenApiManagementAuthenticationSettings(input *apimanagement.AuthenticationSettingsContract) []interface{} {
  subscriptionKeyRequired := false

 	if input != nil && input.SubscriptionKeyRequired != nil {
    subscriptionKeyRequired = *paramNames.SubscriptionKeyRequired
 	}

 	return []interface{}{
    map[string]interface{}{
      "subscription_key_required": subscriptionKeyRequired,
    },
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this actually is a misunderstanding on my part...I'll explain more in the message on this PR.

@katbyte katbyte changed the title Apim authentication settings azurerm_api_management_api - support for authentication settings Nov 17, 2019
@jackbatzner jackbatzner changed the title azurerm_api_management_api - support for authentication settings [WIP] azurerm_api_management_api - support for authentication settings Nov 20, 2019
@jackbatzner
Copy link
Contributor Author

jackbatzner commented Nov 20, 2019

@tombuildsstuff , after digging further into this, it turns out we have to wait for the new API Management API Version.

The 'AuthenticationSettings' field is a 2019-01-01 API Version property. So these changes are actually for 2019-01-01. I was implementing this when looking at the REST API here. I had modified the try-it option to point at 2018-01-1 and assumed the documentation on the left updated, it did not :).

After testing/verifying in 2018-01-01, the response body for GET is as follows:

{
  "id": "...",
  "type": "Microsoft.ApiManagement/service/apis",
  "name": "test-api-name",
  "properties": {
    "displayName": "test-api-name",
    "apiRevision": "1",
    "description": "",
    "subscriptionRequired": false,

Then attempting to set the value in the body for subscriptionRequired in the REST API led to,

{
  "error": {
    "code": "ValidationError",
    "message": "SubscriptionRequired property is not supported for versions before 20180601.",
    "details": null
  }
}

As a result, I'm marking this PR as WIP. We would need to update to 2019-01-01 API version to support this field, and this is blocked by the upstream issues that #2613 is blocked by.

@tombuildsstuff
Copy link
Member

Assigning this to the "blocked" milestone since this is blocked on upgrading to 2019-01-01, which is blocked on Azure/azure-rest-api-specs#6372

@tombuildsstuff tombuildsstuff added this to the Blocked milestone Dec 18, 2019
@tombuildsstuff tombuildsstuff added the upstream/microsoft Indicates that there's an upstream issue blocking this issue/PR label Dec 18, 2019
@jackbatzner jackbatzner deleted the apim_authentication_settings branch March 14, 2020 14:48
@jackbatzner jackbatzner restored the apim_authentication_settings branch March 14, 2020 14:48
@jackbatzner jackbatzner reopened this Mar 14, 2020
@katbyte
Copy link
Collaborator

katbyte commented Mar 24, 2020

Looks like this should be close, from the blocking issue

just yesterday we got signed all required PRs and now preparing the nuget package. Should be ready in nearest days.
``

@usamaahmadkhan
Copy link

@Brunhil can we have an estimated date when this will get released? Blocked as we want to consume this resource from terraform in our module

@markti
Copy link
Contributor

markti commented Apr 23, 2020

what about linking to an authorization_server (oauth / openidc) ??? is this included in this PR?

@ghost ghost added size/S and removed size/M labels Apr 24, 2020
@jackbatzner jackbatzner changed the title [WIP] azurerm_api_management_api - support for subscription_required azurerm_api_management_api - support for subscription_required Apr 24, 2020
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @Brunhil, thanks for the PR! however it looks like some tests are failing:

est Failed

------- Stdout: -------
=== RUN   TestAccAzureRMApiManagementApi_basic
    TestAccAzureRMApiManagementApi_basic: testing.go:640: Step 0 error: Check failed: Check 5/5 error: azurerm_api_management_api.test: Attribute 'subscription_required' expected "true", got "false"
--- FAIL: TestAccAzureRMApiManagementApi_basic (2574.11s)

are you sure the default is true for the property?

@jackbatzner
Copy link
Contributor Author

@katbyte , when this was initially implemented Subscription Required was turned on by default. They may have changed their behavior in the new API version.

@ghost ghost removed the waiting-response label May 15, 2020
@b-twis
Copy link

b-twis commented Jun 4, 2020

@Brunhil Do you have any update on when this might be ready?

@danderbury
Copy link

We're also blocked with this current issue. Do you have an ETA?

@jackbatzner
Copy link
Contributor Author

Sorry all, forgot to hit push! The test should be fixed if it defaults to false. Let me know if there's any other requested changes. Thanks for reviewing!

@3mard
Copy link

3mard commented Jun 23, 2020

Thanks you all for this, can't wait for this to get merged

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @Brunhil! LGTM now 🚀

@katbyte katbyte added this to the v2.16.0 milestone Jun 24, 2020
@katbyte katbyte merged commit 3511639 into hashicorp:master Jun 24, 2020
katbyte added a commit that referenced this pull request Jun 24, 2020
@ghost
Copy link

ghost commented Jun 25, 2020

This has been released in version 2.16.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.16.0"
}
# ... other configuration ...

jrauschenbusch pushed a commit to jrauschenbusch/terraform-provider-azurerm that referenced this pull request Jun 29, 2020
…hicorp#4885)

Add subscription_required to data and resource for azurerm_api_management_api

(fixes hashicorp#3863 )
jrauschenbusch pushed a commit to jrauschenbusch/terraform-provider-azurerm that referenced this pull request Jun 29, 2020
@ghost
Copy link

ghost commented Jul 25, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@hashicorp hashicorp locked and limited conversation to collaborators Jul 25, 2020
@jackbatzner jackbatzner deleted the apim_authentication_settings branch March 2, 2021 02:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants