Skip to content

Commit

Permalink
[#175358307] fail cf update to subsume plan, fail subsume without req…
Browse files Browse the repository at this point in the history
…uired resource ids (#119)
  • Loading branch information
Ernie Billing authored Oct 22, 2020
1 parent d0440be commit 3b1f92f
Show file tree
Hide file tree
Showing 25 changed files with 58 additions and 66 deletions.
20 changes: 12 additions & 8 deletions acceptance-tests/azure/cf-test-masb-sql-db-subsume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,20 @@ if create_service azure-sqldb StandardS0 "${MASB_SQLDB_INSTANCE_NAME}" "${MASB_D
} \
}"

if update_service_plan "${SUBSUMED_INSTANCE_NAME}" large "${UPDATE_CONFIG}"; then
echo "subsumed masb sqldb instance update successful"
if "${SCRIPT_DIR}/../cf-run-spring-music-test.sh" "${SUBSUMED_INSTANCE_NAME}"; then
echo "subsumed masb sqldb instance update test successful"
RESULT=0
if update_service_plan "${SUBSUMED_INSTANCE_NAME}" subsume "${UPDATE_CONFIG}"; then
echo "should not have been able to update to subsume plan"
else
if update_service_plan "${SUBSUMED_INSTANCE_NAME}" large "${UPDATE_CONFIG}"; then
echo "subsumed masb sqldb instance update successful"
if "${SCRIPT_DIR}/../cf-run-spring-music-test.sh" "${SUBSUMED_INSTANCE_NAME}"; then
echo "subsumed masb sqldb instance update test successful"
RESULT=0
else
echo "updated subsumed masb sqldb instance test failed"
fi
else
echo "updated subsumed masb sqldb instance test failed"
echo "failed to update subsumed masb sqldb instance"
fi
else
echo "failed to update subsumed masb sqldb instance"
fi
else
echo "subsumed masb sqldb instance test failed"
Expand Down
2 changes: 2 additions & 0 deletions acceptance-tests/azure/cf-test-negative-responses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ for s in ${MISSING_PARAMS_STANDARD[@]}; do
${SCRIPT_DIR}/../cf-create-service-should-fail.sh ${s} standard
done

${SCRIPT_DIR}/../cf-create-service-should-fail.sh ${s} subsume '{"server_credentials":{},"server":"s"}'

echo "$0 SUCCEEDED"
5 changes: 5 additions & 0 deletions azure-brokerpak/azure-mssql-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ plans:
description: 'Subsume control of an existing SQL Database'
display_name: "Subsume"
properties:
subsume: true
provision:
import_inputs:
- field_name: azure_db_id
Expand All @@ -76,6 +77,10 @@ provision:
"azurerm_mssql_database.azure_sql_db.long_term_retention_policy",
"azurerm_mssql_database.azure_sql_db.extended_auditing_policy"]
plan_inputs:
- field_name: subsume
type: boolean
default: false
details: Subsume existing DB
user_inputs:
- field_name: cores
type: number
Expand Down
4 changes: 2 additions & 2 deletions azure-brokerpak/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ terraform_binaries:
version: 0.12.26
source: https://github.com/hashicorp/terraform/archive/v0.12.26.zip
- name: terraform-provider-azurerm
version: 2.31.1
source: https://github.com/terraform-providers/terraform-provider-azurerm/archive/v2.31.1.zip
version: 2.33.0
source: https://github.com/terraform-providers/terraform-provider-azurerm/archive/v2.33.0.zip
- name: terraform-provider-random
version: 2.2.1
source: https://releases.hashicorp.com/terraform-provider-random/2.2.1/terraform-provider-random_2.2.1_linux_amd64.zip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ variable labels { type = map }
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ variable azure_client_secret { type = string }
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ variable labels { type = map }
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
2 changes: 1 addition & 1 deletion azure-brokerpak/terraform/azure-mongodb/azure-mongodb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ variable labels { type = map }
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ variable failover_grace_minutes { type = number }
variable short_term_retention_days { type = number }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
2 changes: 1 addition & 1 deletion azure-brokerpak/terraform/azure-mssql-db/azure-provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable azure_tenant_id { type = string }
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
29 changes: 0 additions & 29 deletions azure-brokerpak/terraform/azure-mssql-db/provision-mssql-db.tf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ variable read_write_endpoint_failover_policy { type = string }
variable failover_grace_minutes { type = number }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ variable authorized_network {type = string}
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
2 changes: 1 addition & 1 deletion azure-brokerpak/terraform/azure-mssql/provision-mssql.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ variable authorized_network {type = string}
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
2 changes: 1 addition & 1 deletion azure-brokerpak/terraform/azure-mysql/provision-mysql.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ variable tls_min_version { type = string }
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ variable use_tls { type = bool }
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
2 changes: 1 addition & 1 deletion azure-brokerpak/terraform/azure-redis/redis-provision.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ variable tls_min_version { type = string }
variable maxmemory_policy { type = string }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ variable labels { type = map }
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ variable skip_provider_registration { type = bool }
variable authorized_networks { type = list(string) }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable azure_tenant_id { type = string }
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable azure_tenant_id { type = string }
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable azure_tenant_id { type = string }
variable skip_provider_registration { type = bool }

provider "azurerm" {
version = "~> 2.31.0"
version = "~> 2.33.0"
features {}

subscription_id = var.azure_subscription_id
Expand Down
10 changes: 8 additions & 2 deletions pkg/providers/tf/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ type TfServiceDefinitionV1Action struct {

var _ validation.Validatable = (*TfServiceDefinitionV1Action)(nil)

func (action *TfServiceDefinitionV1Action) IsTfImport() bool {
return len(action.ImportVariables) > 0
func (action *TfServiceDefinitionV1Action) IsTfImport(provisionContext *varcontext.VarContext) bool {
subsume := "subsume"
for _, planInput := range action.PlanInputs {
if planInput.FieldName == subsume && provisionContext.HasKey(subsume) && provisionContext.GetBool(subsume){
return true
}
}
return false
}

func loadTemplate(templatePath string) (string, error) {
Expand Down
14 changes: 6 additions & 8 deletions pkg/providers/tf/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (provider *terraformProvider) Provision(ctx context.Context, provisionConte
var tfID string
var err error

if provider.serviceDefinition.ProvisionSettings.IsTfImport() {
if provider.serviceDefinition.ProvisionSettings.IsTfImport(provisionContext) {
tfID, err = provider.importCreate(ctx, provisionContext, provider.serviceDefinition.ProvisionSettings)
if err != nil {
return models.ServiceInstanceDetails{}, err
Expand All @@ -78,6 +78,10 @@ func (provider *terraformProvider) Update(ctx context.Context, provisionContext
"context": provisionContext.ToMap(),
})

if provider.serviceDefinition.ProvisionSettings.IsTfImport(provisionContext) {
return models.ServiceInstanceDetails{}, fmt.Errorf("Cannot update to subsume plan")
}

tfId := provisionContext.GetString("tf_id")
if err := provisionContext.Error(); err != nil {
return models.ServiceInstanceDetails{}, err
Expand Down Expand Up @@ -110,8 +114,6 @@ func (provider *terraformProvider) Bind(ctx context.Context, bindContext *varcon
}

func (provider *terraformProvider) importCreate(ctx context.Context, vars *varcontext.VarContext, action TfServiceDefinitionV1Action) (string, error) {


varsMap := vars.ToMap()

var parameterMappings []wrapper.ParameterMapping
Expand All @@ -131,7 +133,7 @@ func (provider *terraformProvider) importCreate(ctx context.Context, vars *varco
}
}

if len(importParams) > 0 && len(importParams) != len(action.ImportVariables) {
if len(importParams) != len(action.ImportVariables) {
importFields := action.ImportVariables[0].Name
for i := 1; i < len(action.ImportVariables); i++ {
importFields = fmt.Sprintf("%s, %s", importFields, action.ImportVariables[i].Name)
Expand All @@ -140,10 +142,6 @@ func (provider *terraformProvider) importCreate(ctx context.Context, vars *varco
return "", fmt.Errorf("Must provide values for all import parameters: %s", importFields)
}

if len(importParams) == 0 {
return provider.create(ctx, vars, action)
}

tfId := vars.GetString("tf_id")
if err := vars.Error(); err != nil {
return "", err
Expand Down
6 changes: 6 additions & 0 deletions pkg/varcontext/varcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,9 @@ func (vc *VarContext) Error() error {
vc.errors.ErrorFormat = utils.SingleLineErrorFormatter
return vc.errors
}

func (vc *VarContext) HasKey(key string) bool {
_, ok := vc.context[key]

return ok
}

0 comments on commit 3b1f92f

Please sign in to comment.