-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 - support for virtual network integration #5769
Changes from 8 commits
131e088
a664951
560f383
66e6d13
06db1d3
76de8e1
8100760
900f945
dc3fe40
9f165ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,14 @@ func resourceArmApiManagementService() *schema.Resource { | |
}, | ||
}, | ||
|
||
"private_ip_addresses": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
|
||
"publisher_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
|
@@ -112,6 +120,33 @@ func resourceArmApiManagementService() *schema.Resource { | |
}, | ||
}, | ||
|
||
"virtual_network_type": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
string(apimanagement.VirtualNetworkTypeNone), | ||
string(apimanagement.VirtualNetworkTypeExternal), | ||
string(apimanagement.VirtualNetworkTypeInternal), | ||
}, false), | ||
}, | ||
|
||
"virtual_network_configuration": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"subnet_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: azure.ValidateResourceID, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we validate this is a proper id with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
}, | ||
}, | ||
}, | ||
|
||
"notification_sender_email": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
|
@@ -414,6 +449,7 @@ func resourceArmApiManagementServiceCreateUpdate(d *schema.ResourceData, meta in | |
publisherName := d.Get("publisher_name").(string) | ||
publisherEmail := d.Get("publisher_email").(string) | ||
notificationSenderEmail := d.Get("notification_sender_email").(string) | ||
virtualNetworkType := d.Get("virtual_network_type").(string) | ||
|
||
customProperties := expandApiManagementCustomProperties(d) | ||
certificates := expandAzureRmApiManagementCertificates(d) | ||
|
@@ -444,6 +480,18 @@ func resourceArmApiManagementServiceCreateUpdate(d *schema.ResourceData, meta in | |
properties.ServiceProperties.NotificationSenderEmail = ¬ificationSenderEmail | ||
} | ||
|
||
if virtualNetworkType != "" { | ||
properties.ServiceProperties.VirtualNetworkType = apimanagement.VirtualNetworkType(virtualNetworkType) | ||
|
||
if virtualNetworkType != string(apimanagement.VirtualNetworkTypeNone) { | ||
virtualNetworkConfiguration := expandAzureRmApiManagementVirtualNetworkConfigurations(d) | ||
if virtualNetworkConfiguration == nil { | ||
return fmt.Errorf("You must specify 'virtual_network_configuration' when 'virtual_network_type' is %q", virtualNetworkType) | ||
} | ||
properties.ServiceProperties.VirtualNetworkConfiguration = virtualNetworkConfiguration | ||
} | ||
} | ||
|
||
future, err := client.CreateOrUpdate(ctx, resourceGroup, name, properties) | ||
if err != nil { | ||
return fmt.Errorf("creating/updating API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
|
@@ -570,6 +618,8 @@ func resourceArmApiManagementServiceRead(d *schema.ResourceData, meta interface{ | |
d.Set("management_api_url", props.ManagementAPIURL) | ||
d.Set("scm_url", props.ScmURL) | ||
d.Set("public_ip_addresses", props.PublicIPAddresses) | ||
d.Set("private_ip_addresses", props.PrivateIPAddresses) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This property doesn't exist? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we add it to the schema There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
d.Set("virtual_network_type", props.VirtualNetworkType) | ||
|
||
if err := d.Set("security", flattenApiManagementSecurityCustomProperties(props.CustomProperties)); err != nil { | ||
return fmt.Errorf("setting `security`: %+v", err) | ||
|
@@ -587,6 +637,10 @@ func resourceArmApiManagementServiceRead(d *schema.ResourceData, meta interface{ | |
if err := d.Set("additional_location", flattenApiManagementAdditionalLocations(props.AdditionalLocations)); err != nil { | ||
return fmt.Errorf("setting `additional_location`: %+v", err) | ||
} | ||
|
||
if err := d.Set("virtual_network_configuration", flattenApiManagementVirtualNetworkConfiguration(props.VirtualNetworkConfiguration)); err != nil { | ||
return fmt.Errorf("setting `virtual_network_configuration`: %+v", err) | ||
} | ||
} | ||
|
||
if err := d.Set("sku_name", flattenApiManagementServiceSkuName(resp.Sku)); err != nil { | ||
|
@@ -942,6 +996,20 @@ func expandApiManagementCustomProperties(d *schema.ResourceData) map[string]*str | |
return customProperties | ||
} | ||
|
||
func expandAzureRmApiManagementVirtualNetworkConfigurations(d *schema.ResourceData) *apimanagement.VirtualNetworkConfiguration { | ||
vs := d.Get("virtual_network_configuration").([]interface{}) | ||
if len(vs) == 0 { | ||
return nil | ||
} | ||
|
||
v := vs[0].(map[string]interface{}) | ||
subnetResourceId := v["subnet_id"].(string) | ||
|
||
return &apimanagement.VirtualNetworkConfiguration{ | ||
SubnetResourceID: &subnetResourceId, | ||
} | ||
} | ||
|
||
func flattenApiManagementSecurityCustomProperties(input map[string]*string) []interface{} { | ||
output := make(map[string]interface{}) | ||
|
||
|
@@ -964,6 +1032,20 @@ func flattenApiManagementProtocolsCustomProperties(input map[string]*string) []i | |
return []interface{}{output} | ||
} | ||
|
||
func flattenApiManagementVirtualNetworkConfiguration(input *apimanagement.VirtualNetworkConfiguration) []interface{} { | ||
if input == nil { | ||
return []interface{}{} | ||
} | ||
|
||
virtualNetworkConfiguration := make(map[string]interface{}) | ||
|
||
if input.SubnetResourceID != nil { | ||
virtualNetworkConfiguration["subnet_id"] = *input.SubnetResourceID | ||
} | ||
|
||
return []interface{}{virtualNetworkConfiguration} | ||
} | ||
|
||
func apiManagementResourceHostnameSchema(schemaName string) map[string]*schema.Schema { | ||
return map[string]*schema.Schema{ | ||
"host_name": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,26 @@ func TestAccAzureRMApiManagement_policy(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAzureRMApiManagement_virtualNetworkInternal(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_api_management", "test") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.PreCheck(t) }, | ||
Providers: acceptance.SupportedProviders, | ||
CheckDestroy: testCheckAzureRMApiManagementDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAzureRMApiManagement_virtualNetworkInternal(data), | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMApiManagementExists(data.ResourceName), | ||
resource.TestCheckResourceAttr(data.ResourceName, "virtual_network_type", "Internal"), | ||
), | ||
}, | ||
data.ImportStep(), | ||
}, | ||
}) | ||
} | ||
|
||
func testCheckAzureRMApiManagementDestroy(s *terraform.State) error { | ||
conn := acceptance.AzureProvider.Meta().(*clients.Client).ApiManagement.ServiceClient | ||
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext | ||
|
@@ -506,3 +526,45 @@ resource "azurerm_api_management" "test" { | |
} | ||
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.Locations.Ternary, data.RandomInteger) | ||
} | ||
|
||
func testAccAzureRMApiManagement_virtualNetworkInternal(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
resource "azurerm_resource_group" "test" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we'll need a provider block here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
name = "acctestRG-%d" | ||
location = "%s" | ||
} | ||
|
||
resource "azurerm_virtual_network" "test" { | ||
name = "acctestVNET-%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" | ||
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_api_management" "test" { | ||
name = "acctestAM-%d" | ||
location = azurerm_resource_group.test.location | ||
resource_group_name = azurerm_resource_group.test.name | ||
publisher_name = "pub1" | ||
publisher_email = "[email protected]" | ||
|
||
sku_name = "Developer_1" | ||
|
||
virtual_network_type = "Internal" | ||
virtual_network_configuration { | ||
subnet_id = azurerm_subnet.test.id | ||
} | ||
} | ||
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically group computed properties at the bottom of the schema, ie required -> optional -> computes