Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yupwei68 committed Jul 30, 2020
1 parent 8273a75 commit 0876e7f
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 58 deletions.
95 changes: 43 additions & 52 deletions azurerm/internal/services/apimanagement/api_management_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,32 +542,28 @@ func resourceArmApiManagementServiceCreateUpdate(d *schema.ResourceData, meta in

d.SetId(*read.ID)

if d.HasChange("sign_in") {
signInSettingsRaw := d.Get("sign_in").([]interface{})
signInSettings := expandApiManagementSignInSettings(signInSettingsRaw)
signInClient := meta.(*clients.Client).ApiManagement.SignInClient
if _, err := signInClient.CreateOrUpdate(ctx, resourceGroup, name, signInSettings, ""); err != nil {
return fmt.Errorf(" setting Sign In settings for API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}
signInSettingsRaw := d.Get("sign_in").([]interface{})
signInSettings := expandApiManagementSignInSettings(signInSettingsRaw)
signInClient := meta.(*clients.Client).ApiManagement.SignInClient
if _, err := signInClient.CreateOrUpdate(ctx, resourceGroup, name, signInSettings, ""); err != nil {
return fmt.Errorf(" setting Sign In settings for API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if d.HasChange("sign_up") {
signUpSettingsRaw := d.Get("sign_up").([]interface{})
signUpSettings := expandApiManagementSignUpSettings(signUpSettingsRaw)
signUpClient := meta.(*clients.Client).ApiManagement.SignUpClient
signUpSettingsRaw := d.Get("sign_up").([]interface{})
signUpSettings := expandApiManagementSignUpSettings(signUpSettingsRaw)
signUpClient := meta.(*clients.Client).ApiManagement.SignUpClient
if _, err := signUpClient.CreateOrUpdate(ctx, resourceGroup, name, signUpSettings, ""); err != nil {
return fmt.Errorf(" setting Sign Up settings for API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if _, err := signUpClient.CreateOrUpdate(ctx, resourceGroup, name, signUpSettings, ""); err != nil {
return fmt.Errorf(" setting Sign Up settings for API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}
policyClient := meta.(*clients.Client).ApiManagement.PolicyClient
policiesRaw := d.Get("policy").([]interface{})
policy, err := expandApiManagementPolicies(policiesRaw)
if err != nil {
return err
}

if d.HasChange("policy") {
policyClient := meta.(*clients.Client).ApiManagement.PolicyClient
policiesRaw := d.Get("policy").([]interface{})
policy, err := expandApiManagementPolicies(policiesRaw)
if err != nil {
return err
}
// remove the existing policy
if resp, err := policyClient.Delete(ctx, resourceGroup, name, ""); err != nil {
if !utils.ResponseWasNotFound(resp) {
Expand Down Expand Up @@ -610,41 +606,24 @@ func resourceArmApiManagementServiceRead(d *schema.ResourceData, meta interface{
return fmt.Errorf("making Read request on API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if resp.ServiceProperties != nil && resp.ServiceProperties.VirtualNetworkType != apimanagement.VirtualNetworkTypeInternal {
signInClient := meta.(*clients.Client).ApiManagement.SignInClient
signInSettings, err := signInClient.Get(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("retrieving Sign In Settings for API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if err := d.Set("sign_in", flattenApiManagementSignInSettings(signInSettings)); err != nil {
return fmt.Errorf("setting `sign_in`: %+v", err)
}

signUpClient := meta.(*clients.Client).ApiManagement.SignUpClient
signUpSettings, err := signUpClient.Get(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("retrieving Sign Up Settings for API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}
signInClient := meta.(*clients.Client).ApiManagement.SignInClient
signInSettings, err := signInClient.Get(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("retrieving Sign In Settings for API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if err := d.Set("sign_up", flattenApiManagementSignUpSettings(signUpSettings)); err != nil {
return fmt.Errorf("setting `sign_up`: %+v", err)
}
signUpClient := meta.(*clients.Client).ApiManagement.SignUpClient
signUpSettings, err := signUpClient.Get(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("retrieving Sign Up Settings for API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}

policyClient := meta.(*clients.Client).ApiManagement.PolicyClient
policy, err := policyClient.Get(ctx, resourceGroup, name, apimanagement.PolicyExportFormatXML)
if err != nil {
if !utils.ResponseWasNotFound(policy.Response) {
return fmt.Errorf("retrieving Policy for API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}
}
if err := d.Set("policy", flattenApiManagementPolicies(d, policy)); err != nil {
return fmt.Errorf("setting `policy`: %+v", err)
policyClient := meta.(*clients.Client).ApiManagement.PolicyClient
policy, err := policyClient.Get(ctx, resourceGroup, name, apimanagement.PolicyExportFormatXML)
if err != nil {
if !utils.ResponseWasNotFound(policy.Response) {
return fmt.Errorf("retrieving Policy for API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}
} else {
d.Set("sign_in", []interface{}{})
d.Set("sign_up", []interface{}{})
d.Set("policy", []interface{}{})
}

d.Set("name", name)
Expand Down Expand Up @@ -699,6 +678,18 @@ func resourceArmApiManagementServiceRead(d *schema.ResourceData, meta interface{
return fmt.Errorf("setting `sku_name`: %+v", err)
}

if err := d.Set("sign_in", flattenApiManagementSignInSettings(signInSettings)); err != nil {
return fmt.Errorf("setting `sign_in`: %+v", err)
}

if err := d.Set("sign_up", flattenApiManagementSignUpSettings(signUpSettings)); err != nil {
return fmt.Errorf("setting `sign_up`: %+v", err)
}

if err := d.Set("policy", flattenApiManagementPolicies(d, policy)); err != nil {
return fmt.Errorf("setting `policy`: %+v", err)
}

return tags.FlattenAndSet(d, resp.Tags)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,26 +870,65 @@ provider "azurerm" {
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
name = "acctestRG-%[1]d"
location = "%[2]s"
}
resource "azurerm_virtual_network" "test" {
name = "acctestVNET-%d"
name = "acctestVNET-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
address_space = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "test" {
name = "acctestSNET-%d"
name = "acctestSNET-%[1]d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefix = "10.0.1.0/24"
}
resource "azurerm_network_security_group" "test" {
name = "acctest-NSG-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_subnet_network_security_group_association" "test" {
subnet_id = azurerm_subnet.test.id
network_security_group_id = azurerm_network_security_group.test.id
}
resource "azurerm_network_security_rule" "port_3443" {
name = "Port_3443"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "3443"
source_address_prefix = "ApiManagement"
destination_address_prefix = "VirtualNetwork"
resource_group_name = azurerm_resource_group.test.name
network_security_group_name = azurerm_network_security_group.test.name
}
resource "azurerm_network_security_rule" "port_443_1433" {
name = "Port_443_1433"
priority = 100
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_ranges = ["443", "1433"]
source_address_prefix = "VirtualNetwork"
destination_address_prefix = "VirtualNetwork"
resource_group_name = azurerm_resource_group.test.name
network_security_group_name = azurerm_network_security_group.test.name
}
resource "azurerm_api_management" "test" {
name = "acctestAM-%d"
name = "acctestAM-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
publisher_name = "pub1"
Expand All @@ -902,7 +941,7 @@ resource "azurerm_api_management" "test" {
subnet_id = azurerm_subnet.test.id
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
`, data.RandomInteger, data.Locations.Primary)
}

func testAccAzureRMApiManagement_identityUserAssigned(data acceptance.TestData) string {
Expand Down

0 comments on commit 0876e7f

Please sign in to comment.