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_spring_cloud_configuration_service - support for the ca_certificate_id property #22814

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ func resourceSpringCloudConfigurationService() *pluginsdk.Resource {
ValidateFunc: validation.StringIsNotEmpty,
},

"ca_certificate_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validate.SpringCloudCertificateID,
},

"host_key": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -258,7 +264,7 @@ func expandConfigurationServiceConfigurationServiceGitRepositoryArray(input []in
results := make([]appplatform.ConfigurationServiceGitRepository, 0)
for _, item := range input {
v := item.(map[string]interface{})
results = append(results, appplatform.ConfigurationServiceGitRepository{
repo := appplatform.ConfigurationServiceGitRepository{
Name: utils.String(v["name"].(string)),
Patterns: utils.ExpandStringSlice(v["patterns"].(*pluginsdk.Set).List()),
URI: utils.String(v["uri"].(string)),
Expand All @@ -270,7 +276,11 @@ func expandConfigurationServiceConfigurationServiceGitRepositoryArray(input []in
HostKeyAlgorithm: utils.String(v["host_key_algorithm"].(string)),
PrivateKey: utils.String(v["private_key"].(string)),
StrictHostKeyChecking: utils.Bool(v["strict_host_key_checking"].(bool)),
})
}
if caCertificatedId := v["ca_certificate_id"].(string); caCertificatedId != "" {
repo.CaCertResourceID = utils.String(caCertificatedId)
}
results = append(results, repo)
}
return &results
}
Expand Down Expand Up @@ -330,7 +340,16 @@ func flattenConfigurationServiceConfigurationServiceGitRepositoryArray(input *[]
username = value.(string)
}
}

var caCertificateId string
if item.CaCertResourceID != nil {
certificatedId, err := parse.SpringCloudCertificateIDInsensitively(*item.CaCertResourceID)
if err == nil {
caCertificateId = certificatedId.ID()
}
}
results = append(results, map[string]interface{}{
"ca_certificate_id": caCertificateId,
"name": name,
"label": label,
"patterns": utils.FlattenStringSlice(item.Patterns),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ func TestAccSpringCloudConfigurationService_generation(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(), {
data.ImportStep(),
{
Config: r.generation(data, "Gen2"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
Expand All @@ -122,6 +123,20 @@ func TestAccSpringCloudConfigurationService_generation(t *testing.T) {
})
}

func TestAccSpringCloudConfigurationService_caCertificateId(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_spring_cloud_configuration_service", "test")
r := SpringCloudConfigurationServiceResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.caCertificateId(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (r SpringCloudConfigurationServiceResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.SpringCloudConfigurationServiceID(state.ID)
if err != nil {
Expand Down Expand Up @@ -238,3 +253,126 @@ resource "azurerm_spring_cloud_configuration_service" "test" {
}
`, template, generation)
}

func (r SpringCloudConfigurationServiceResource) caCertificateId(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s


data "azurerm_client_config" "current" {
}

data "azuread_service_principal" "test" {
display_name = "Azure Spring Cloud Resource Provider"
}

resource "azurerm_key_vault" "test" {
name = "acctest-kv-%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
tenant_id = data.azurerm_client_config.current.tenant_id
sku_name = "standard"

access_policy {
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = data.azurerm_client_config.current.object_id

secret_permissions = [
"Set",
]

certificate_permissions = [
"Create",
"Delete",
"Get",
"Purge",
"Update",
]
}

access_policy {
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = data.azuread_service_principal.test.object_id

secret_permissions = [
"Get",
"List",
]

certificate_permissions = [
"Get",
"List",
]
}
}

resource "azurerm_key_vault_certificate" "test" {
name = "acctest-cert-%[2]d"
key_vault_id = azurerm_key_vault.test.id

certificate_policy {
issuer_parameters {
name = "Self"
}

key_properties {
exportable = true
key_size = 2048
key_type = "RSA"
reuse_key = true
}

lifetime_action {
action {
action_type = "AutoRenew"
}

trigger {
days_before_expiry = 30
}
}

secret_properties {
content_type = "application/x-pkcs12"
}

x509_certificate_properties {
key_usage = [
"cRLSign",
"dataEncipherment",
"digitalSignature",
"keyAgreement",
"keyCertSign",
"keyEncipherment",
]

subject = "CN=contoso.com"
validity_in_months = 12
}
}
}


resource "azurerm_spring_cloud_certificate" "test" {
name = "acctest-scc-%[2]d"
resource_group_name = azurerm_spring_cloud_service.test.resource_group_name
service_name = azurerm_spring_cloud_service.test.name
key_vault_certificate_id = azurerm_key_vault_certificate.test.id
exclude_private_key = true
}

resource "azurerm_spring_cloud_configuration_service" "test" {
name = "default"
spring_cloud_service_id = azurerm_spring_cloud_service.test.id
generation = "Gen2"
repository {
name = "fake"
label = "master"
patterns = ["app/dev"]
uri = "https://github.com/Azure-Samples/piggymetrics"
ca_certificate_id = azurerm_spring_cloud_certificate.test.id
}
}
`, template, data.RandomIntOfLength(10))
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ A `repository` block supports the following:

* `uri` - (Required) Specifies the URI of the repository.

* `ca_certificate_id` - (Optional) Specifies the ID of the Certificate Authority used when retrieving the Git Repository via HTTPS.

* `host_key` - (Optional) Specifies the SSH public key of git repository.

* `host_key_algorithm` - (Optional) Specifies the SSH key algorithm of git repository.
Expand Down