provider/azurerm: Support `azurerm_search_service` resource
This commit is contained in:
parent
27d82a2397
commit
0d750c16f0
|
@ -536,15 +536,19 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "github.com/jen20/riviera/azure",
|
||||
"Rev": "31f4644de1f4931e43271240069bf2b896f47005"
|
||||
"Rev": "64de55fa8cdd0c52f7d59494c1b03c1b583c52b4"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/jen20/riviera/dns",
|
||||
"Rev": "31f4644de1f4931e43271240069bf2b896f47005"
|
||||
"Rev": "64de55fa8cdd0c52f7d59494c1b03c1b583c52b4"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/jen20/riviera/search",
|
||||
"Rev": "64de55fa8cdd0c52f7d59494c1b03c1b583c52b4"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/jen20/riviera/sql",
|
||||
"Rev": "31f4644de1f4931e43271240069bf2b896f47005"
|
||||
"Rev": "64de55fa8cdd0c52f7d59494c1b03c1b583c52b4"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/jmespath/go-jmespath",
|
||||
|
|
|
@ -71,6 +71,7 @@ func Provider() terraform.ResourceProvider {
|
|||
"azurerm_sql_server": resourceArmSqlServer(),
|
||||
"azurerm_sql_database": resourceArmSqlDatabase(),
|
||||
"azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(),
|
||||
"azurerm_search_service": resourceArmSearchService(),
|
||||
},
|
||||
ConfigureFunc: providerConfigure,
|
||||
}
|
||||
|
@ -138,7 +139,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|||
func registerAzureResourceProvidersWithSubscription(config *Config, client *ArmClient) error {
|
||||
providerClient := client.providers
|
||||
|
||||
providers := []string{"Microsoft.Network", "Microsoft.Compute", "Microsoft.Cdn", "Microsoft.Storage", "Microsoft.Sql"}
|
||||
providers := []string{"Microsoft.Network", "Microsoft.Compute", "Microsoft.Cdn", "Microsoft.Storage", "Microsoft.Sql", "Microsoft.Search"}
|
||||
|
||||
for _, v := range providers {
|
||||
res, err := providerClient.Register(v)
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
package azurerm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/jen20/riviera/azure"
|
||||
"github.com/jen20/riviera/search"
|
||||
)
|
||||
|
||||
func resourceArmSearchService() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceArmSearchServiceCreate,
|
||||
Read: resourceArmSearchServiceRead,
|
||||
Update: resourceArmSearchServiceCreate,
|
||||
Delete: resourceArmSearchServiceDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"location": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
StateFunc: azureRMNormalizeLocation,
|
||||
},
|
||||
|
||||
"resource_group_name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"sku": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"replica_count": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"partition_count": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"tags": tagsSchema(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceArmSearchServiceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
rivieraClient := client.rivieraClient
|
||||
|
||||
tags := d.Get("tags").(map[string]interface{})
|
||||
expandedTags := expandTags(tags)
|
||||
|
||||
command := &search.CreateOrUpdateSearchService{
|
||||
Name: d.Get("name").(string),
|
||||
Location: d.Get("location").(string),
|
||||
ResourceGroupName: d.Get("resource_group_name").(string),
|
||||
Tags: *expandedTags,
|
||||
Sku: search.Sku{
|
||||
Name: d.Get("sku").(string),
|
||||
},
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("replica_count"); ok {
|
||||
command.ReplicaCount = azure.String(v.(string))
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("partition_count"); ok {
|
||||
command.PartitionCount = azure.String(v.(string))
|
||||
}
|
||||
|
||||
createRequest := rivieraClient.NewRequest()
|
||||
createRequest.Command = command
|
||||
|
||||
createResponse, err := createRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating Search Service: %s", err)
|
||||
}
|
||||
if !createResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Error creating Search Service: %s", createResponse.Error)
|
||||
}
|
||||
|
||||
readRequest := rivieraClient.NewRequest()
|
||||
readRequest.Command = &search.GetSearchService{
|
||||
Name: d.Get("name").(string),
|
||||
ResourceGroupName: d.Get("resource_group_name").(string),
|
||||
}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reading Search Service: %s", err)
|
||||
}
|
||||
if !readResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Error reading Search Service: %s", readResponse.Error)
|
||||
}
|
||||
|
||||
resp := readResponse.Parsed.(*search.GetSearchServiceResponse)
|
||||
d.SetId(*resp.ID)
|
||||
|
||||
return resourceArmSearchServiceRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceArmSearchServiceRead(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
rivieraClient := client.rivieraClient
|
||||
|
||||
readRequest := rivieraClient.NewRequestForURI(d.Id())
|
||||
readRequest.Command = &search.GetSearchService{}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reading Search Service: %s", err)
|
||||
}
|
||||
if !readResponse.IsSuccessful() {
|
||||
log.Printf("[INFO] Error reading Search Service %q - removing from state", d.Id())
|
||||
d.SetId("")
|
||||
return fmt.Errorf("Error reading Search Service: %s", readResponse.Error)
|
||||
}
|
||||
|
||||
resp := readResponse.Parsed.(*search.GetSearchServiceResponse)
|
||||
d.Set("sku", resp.Sku)
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceArmSearchServiceDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
rivieraClient := client.rivieraClient
|
||||
|
||||
deleteRequest := rivieraClient.NewRequestForURI(d.Id())
|
||||
deleteRequest.Command = &search.DeleteSearchService{}
|
||||
|
||||
deleteResponse, err := deleteRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting Search Service: %s", err)
|
||||
}
|
||||
if !deleteResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Error deleting Search Service: %s", deleteResponse.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
package azurerm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/jen20/riviera/search"
|
||||
)
|
||||
|
||||
func TestAccAzureRMSearchService_basic(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
config := fmt.Sprintf(testAccAzureRMSearchService_basic, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMSearchServiceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: config,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMSearchServiceExists("azurerm_search_service.test"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
//func TestAccAzureRMSearchService_withTags(t *testing.T) {
|
||||
// ri := acctest.RandInt()
|
||||
// preConfig := fmt.Sprintf(testAccAzureRMSearchService_withTags, ri, ri)
|
||||
// postConfig := fmt.Sprintf(testAccAzureRMSearchService_withTagsUpdated, ri, ri)
|
||||
//
|
||||
// resource.Test(t, resource.TestCase{
|
||||
// PreCheck: func() { testAccPreCheck(t) },
|
||||
// Providers: testAccProviders,
|
||||
// CheckDestroy: testCheckAzureRMSearchServiceDestroy,
|
||||
// Steps: []resource.TestStep{
|
||||
// resource.TestStep{
|
||||
// Config: preConfig,
|
||||
// Check: resource.ComposeTestCheckFunc(
|
||||
// testCheckAzureRMSearchServiceExists("azurerm_search_service.test"),
|
||||
// resource.TestCheckResourceAttr(
|
||||
// "azurerm_search_service.test", "tags.#", "2"),
|
||||
// ),
|
||||
// },
|
||||
//
|
||||
// resource.TestStep{
|
||||
// Config: postConfig,
|
||||
// Check: resource.ComposeTestCheckFunc(
|
||||
// testCheckAzureRMSearchServiceExists("azurerm_search_service.test"),
|
||||
// resource.TestCheckResourceAttr(
|
||||
// "azurerm_search_service.test", "tags.#", "1"),
|
||||
// ),
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
//}
|
||||
|
||||
func testCheckAzureRMSearchServiceExists(name string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
|
||||
rs, ok := s.RootModule().Resources[name]
|
||||
if !ok {
|
||||
return fmt.Errorf("Not found: %s", name)
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*ArmClient).rivieraClient
|
||||
|
||||
readRequest := conn.NewRequestForURI(rs.Primary.ID)
|
||||
readRequest.Command = &search.GetSearchService{}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Bad: GetSearchService: %s", err)
|
||||
}
|
||||
if !readResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Bad: GetSearchService: %s", readResponse.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testCheckAzureRMSearchServiceDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*ArmClient).rivieraClient
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "azurerm_search_service" {
|
||||
continue
|
||||
}
|
||||
|
||||
readRequest := conn.NewRequestForURI(rs.Primary.ID)
|
||||
readRequest.Command = &search.GetSearchService{}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Bad: GetSearchService: %s", err)
|
||||
}
|
||||
|
||||
if readResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Bad: Search Service still exists: %s", readResponse.Error)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var testAccAzureRMSearchService_basic = `
|
||||
resource "azurerm_resource_group" "test" {
|
||||
name = "acctest_rg_%d"
|
||||
location = "West US"
|
||||
}
|
||||
resource "azurerm_search_service" "test" {
|
||||
name = "acctestsearchservice%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
location = "West US"
|
||||
sku = "standard"
|
||||
}
|
||||
`
|
||||
|
||||
//var testAccAzureRMSearchService_withTags = `
|
||||
//resource "azurerm_resource_group" "test" {
|
||||
// name = "acctest_rg_%d"
|
||||
// location = "West US"
|
||||
//}
|
||||
//resource "azurerm_sql_server" "test" {
|
||||
// name = "acctestsqlserver%d"
|
||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
// location = "West US"
|
||||
// version = "12.0"
|
||||
// administrator_login = "mradministrator"
|
||||
// administrator_login_password = "thisIsDog11"
|
||||
//
|
||||
// tags {
|
||||
// environment = "staging"
|
||||
// database = "test"
|
||||
// }
|
||||
//}
|
||||
//`
|
||||
//
|
||||
//var testAccAzureRMSearchService_withTagsUpdated = `
|
||||
//resource "azurerm_resource_group" "test" {
|
||||
// name = "acctest_rg_%d"
|
||||
// location = "West US"
|
||||
//}
|
||||
//resource "azurerm_sql_server" "test" {
|
||||
// name = "acctestsqlserver%d"
|
||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
// location = "West US"
|
||||
// version = "12.0"
|
||||
// administrator_login = "mradministrator"
|
||||
// administrator_login_password = "thisIsDog11"
|
||||
//
|
||||
// tags {
|
||||
// environment = "production"
|
||||
// }
|
||||
//}
|
||||
//`
|
|
@ -37,6 +37,7 @@ func readTaggedFields(command interface{}) map[string]interface{} {
|
|||
result := make(map[string]interface{})
|
||||
|
||||
for i := 0; i < value.NumField(); i++ { // iterates through every struct type field
|
||||
fmt.Println(i, value.Type().Field(i).Name)
|
||||
tag := value.Type().Field(i).Tag // returns the tag string
|
||||
tagValue := tag.Get("riviera")
|
||||
if tagValue != "" {
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package search
|
||||
|
||||
import "fmt"
|
||||
|
||||
const apiVersion = "2015-08-19"
|
||||
const apiProvider = "Microsoft.Search"
|
||||
|
||||
func searchServiceDefaultURLPath(resourceGroupName, serviceName string) func() string {
|
||||
return func() string {
|
||||
return fmt.Sprintf("resourceGroups/%s/providers/%s/searchServices/%s", resourceGroupName, apiProvider, serviceName)
|
||||
}
|
||||
}
|
41
vendor/github.com/jen20/riviera/search/create_or_update_search_service.go
generated
vendored
Normal file
41
vendor/github.com/jen20/riviera/search/create_or_update_search_service.go
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
package search
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type Sku struct {
|
||||
Name string `json:"name" mapstructure:"name"`
|
||||
}
|
||||
|
||||
type CreateOrUpdateSearchServiceResponse struct {
|
||||
ID *string `mapstructure:"id"`
|
||||
Name *string `mapstructure:"name"`
|
||||
Location *string `mapstructure:"location"`
|
||||
Tags *map[string]*string `mapstructure:"tags"`
|
||||
Sku *Sku `json:"sku,omitempty"`
|
||||
ReplicaCount *string `json:"replicaCount,omitempty"`
|
||||
PartitionCount *string `json:"partitionCount,omitempty"`
|
||||
Status *string `mapstructure:"status"`
|
||||
StatusDetails *string `mapstructure:"statusDetails"`
|
||||
ProvisioningStatus *string `mapstructure:"provisioningStatus"`
|
||||
}
|
||||
|
||||
type CreateOrUpdateSearchService struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
Location string `json:"-" riviera:"location"`
|
||||
Tags map[string]*string `json:"-" riviera:"tags"`
|
||||
Sku Sku `json:"-" riviera:"sku"`
|
||||
ReplicaCount *string `json:"replicaCount,omitempty"`
|
||||
PartitionCount *string `json:"partitionCount,omitempty"`
|
||||
}
|
||||
|
||||
func (s CreateOrUpdateSearchService) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "PUT",
|
||||
URLPathFunc: searchServiceDefaultURLPath(s.ResourceGroupName, s.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &CreateOrUpdateSearchServiceResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package search
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type DeleteSearchService struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
}
|
||||
|
||||
func (s DeleteSearchService) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "DELETE",
|
||||
URLPathFunc: searchServiceDefaultURLPath(s.ResourceGroupName, s.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package search
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type GetSearchServiceResponse struct {
|
||||
ID *string `mapstructure:"id"`
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
Location string `json:"-" riviera:"location"`
|
||||
Tags map[string]*string `json:"-" riviera:"tags"`
|
||||
Sku *Sku `json:"sku,omitempty"`
|
||||
ReplicaCount *string `json:"replicaCount,omitempty"`
|
||||
PartitionCount *string `json:"partitionCount,omitempty"`
|
||||
Status *string `mapstructure:"status"`
|
||||
StatusDetails *string `mapstructure:"statusDetails"`
|
||||
ProvisioningStatus *string `mapstructure:"provisioningStatus"`
|
||||
}
|
||||
|
||||
type GetSearchService struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
}
|
||||
|
||||
func (s GetSearchService) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "GET",
|
||||
URLPathFunc: searchServiceDefaultURLPath(s.ResourceGroupName, s.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &GetSearchServiceResponse{}
|
||||
},
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue