-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new resource and data source for spring cloud and spring cloud co…
…nfig server
- Loading branch information
Showing
32 changed files
with
6,891 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
azappplatform "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/appplatform" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmSpringCloud() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmSpringCloudRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: azappplatform.ValidateSpringCloudName, | ||
}, | ||
|
||
"location": azure.SchemaLocationForDataSource(), | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
|
||
"service_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"version": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"tags": tags.SchemaDataSource(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmSpringCloudRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).AppPlatform.ServicesClient | ||
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d) | ||
defer cancel() | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Error: Spring Cloud %q (Resource Group %q) was not found", name, resourceGroup) | ||
} | ||
return fmt.Errorf("Error reading Spring Cloud %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("resource_group_name", resourceGroup) | ||
if location := resp.Location; location != nil { | ||
d.Set("location", azure.NormalizeLocation(*location)) | ||
} | ||
if clusterResourceProperties := resp.Properties; clusterResourceProperties != nil { | ||
d.Set("service_id", clusterResourceProperties.ServiceID) | ||
d.Set("version", int(*clusterResourceProperties.Version)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmSpringCloudConfigServer() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmSpringCloudConfigServerRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"spring_cloud_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: azure.ValidateResourceID, | ||
}, | ||
|
||
"uri": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"host_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"host_key_algorithm": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"label": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"password": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
"private_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"repositories": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"uri": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"host_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"host_key_algorithm": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"label": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"password": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
"pattern": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"private_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"search_paths": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"strict_host_key_checking": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"username": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"search_paths": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"strict_host_key_checking": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"username": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmSpringCloudConfigServerRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).AppPlatform.ServicesClient | ||
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d) | ||
defer cancel() | ||
|
||
springCloudId := d.Get("spring_cloud_id").(string) | ||
id, err := azure.ParseAzureResourceID(springCloudId) | ||
if err != nil { | ||
return err | ||
} | ||
resourceGroup := id.ResourceGroup | ||
springCloudName := id.Path["Spring"] | ||
|
||
resp, err := client.Get(ctx, resourceGroup, springCloudName) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Error: Spring Cloud %q (Resource Group %q) was not found", springCloudName, resourceGroup) | ||
} | ||
return fmt.Errorf("Error reading Spring Cloud %q (Resource Group %q): %+v", springCloudName, resourceGroup, err) | ||
} | ||
|
||
d.SetId(springCloudId) | ||
|
||
if resp.Properties != nil && resp.Properties.ConfigServerProperties != nil && resp.Properties.ConfigServerProperties.ConfigServer != nil { | ||
if props := resp.Properties.ConfigServerProperties.ConfigServer.GitProperty; props != nil { | ||
d.Set("host_key", props.HostKey) | ||
d.Set("host_key_algorithm", props.HostKeyAlgorithm) | ||
d.Set("label", props.Label) | ||
d.Set("password", props.Password) | ||
d.Set("private_key", props.PrivateKey) | ||
d.Set("strict_host_key_checking", props.StrictHostKeyChecking) | ||
d.Set("uri", props.URI) | ||
d.Set("username", props.Username) | ||
d.Set("search_paths", props.SearchPaths) | ||
if err := d.Set("repositories", flattenArmSpringCloudGitPatternRepository(props.Repositories)); err != nil { | ||
return fmt.Errorf("Error setting `repositories`: %+v", err) | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" | ||
) | ||
|
||
func TestAccDataSourceAzureRMSpringCloudConfigServer_complete(t *testing.T) { | ||
dataSourceName := "data.azurerm_spring_cloud_config_server.test" | ||
ri := tf.AccRandTimeInt() | ||
location := testLocation() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceSpringCloudConfigServer_complete(ri, location), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "id"), | ||
resource.TestCheckResourceAttr(dataSourceName, "uri", "https://github.com/Azure-Samples/piggymetrics"), | ||
resource.TestCheckResourceAttr(dataSourceName, "label", "config"), | ||
resource.TestCheckResourceAttr(dataSourceName, "search_paths.#", "2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "search_paths.0", "dir1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "search_paths.1", "dir2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.#", "2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.0.name", "repo1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.0.uri", "https://github.com/Azure-Samples/piggymetrics"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.0.label", "config"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.0.search_paths.#", "2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.0.search_paths.0", "dir1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.0.search_paths.1", "dir2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.1.name", "repo2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.1.uri", "https://github.com/Azure-Samples/piggymetrics"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.1.label", "config"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.1.search_paths.#", "2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.1.search_paths.0", "dir1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "repositories.1.search_paths.1", "dir2"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceSpringCloudConfigServer_complete(rInt int, location string) string { | ||
config := testAccAzureRMSpringCloudConfigServer_complete(rInt, location) | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_spring_cloud_config_server" "test" { | ||
spring_cloud_id = azurerm_spring_cloud.test.id | ||
} | ||
`, config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" | ||
) | ||
|
||
func TestAccDataSourceAzureRMSpringCloud_complete(t *testing.T) { | ||
dataSourceName := "data.azurerm_spring_cloud.test" | ||
ri := tf.AccRandTimeInt() | ||
location := testLocation() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceSpringCloud_complete(ri, location), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "id"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "service_id"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "version"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.env", "test"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.version", "1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceSpringCloud_complete(rInt int, location string) string { | ||
config := testAccAzureRMSpringCloud_complete(rInt, location) | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_spring_cloud" "test" { | ||
name = azurerm_spring_cloud.test.name | ||
resource_group_name = azurerm_spring_cloud.test.resource_group_name | ||
} | ||
`, config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/Azure/azure-sdk-for-go/services/preview/appplatform/mgmt/2019-05-01-preview/appplatform" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common" | ||
) | ||
|
||
type Client struct { | ||
ServicesClient *appplatform.ServicesClient | ||
} | ||
|
||
func NewClient(o *common.ClientOptions) *Client { | ||
ServicesClient := appplatform.NewServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) | ||
o.ConfigureClient(&ServicesClient.Client, o.ResourceManagerAuthorizer) | ||
|
||
return &Client{ | ||
ServicesClient: &ServicesClient, | ||
} | ||
} |
Oops, something went wrong.