diff --git a/internal/services/springcloud/migration/active_deployment_migration_v0_to_v1.go b/internal/services/springcloud/migration/active_deployment_migration_v0_to_v1.go new file mode 100644 index 000000000000..b869d9fa3438 --- /dev/null +++ b/internal/services/springcloud/migration/active_deployment_migration_v0_to_v1.go @@ -0,0 +1,41 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudActiveDeploymentV0ToV1 struct{} + +func (s SpringCloudActiveDeploymentV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "spring_cloud_app_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "deployment_name": { + Type: pluginsdk.TypeString, + Required: true, + }, + } +} + +func (s SpringCloudActiveDeploymentV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudAppIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/api_portal_custom_domain_migration_v0_to_v1.go b/internal/services/springcloud/migration/api_portal_custom_domain_migration_v0_to_v1.go new file mode 100644 index 000000000000..7678bcec2c74 --- /dev/null +++ b/internal/services/springcloud/migration/api_portal_custom_domain_migration_v0_to_v1.go @@ -0,0 +1,47 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudApiPortalCustomDomainV0ToV1 struct{} + +func (s SpringCloudApiPortalCustomDomainV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_api_portal_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "thumbprint": { + Type: pluginsdk.TypeString, + Optional: true, + }, + } +} + +func (s SpringCloudApiPortalCustomDomainV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudAPIPortalCustomDomainIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/api_portal_migration_v0_to_v1.go b/internal/services/springcloud/migration/api_portal_migration_v0_to_v1.go new file mode 100644 index 000000000000..a8076fabd317 --- /dev/null +++ b/internal/services/springcloud/migration/api_portal_migration_v0_to_v1.go @@ -0,0 +1,103 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudApiPortalV0ToV1 struct{} + +func (s SpringCloudApiPortalV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_service_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "gateway_ids": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "https_only_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "instance_count": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 1, + }, + + "public_network_access_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "sso": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "client_id": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "client_secret": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "issuer_uri": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "scope": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + }, + }, + }, + + "url": { + Type: pluginsdk.TypeString, + Computed: true, + }, + } +} + +func (s SpringCloudApiPortalV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudAPIPortalIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/app_cosmosdb_association_migration_v0_to_v1.go b/internal/services/springcloud/migration/app_cosmosdb_association_migration_v0_to_v1.go new file mode 100644 index 000000000000..ee51543dbdd6 --- /dev/null +++ b/internal/services/springcloud/migration/app_cosmosdb_association_migration_v0_to_v1.go @@ -0,0 +1,91 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudAppCosmosDbAssociationV0ToV1 struct{} + +func (s SpringCloudAppCosmosDbAssociationV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_app_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "cosmosdb_account_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "api_type": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "cosmosdb_access_key": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "cosmosdb_cassandra_keyspace_name": { + Type: pluginsdk.TypeString, + Optional: true, + ConflictsWith: []string{"cosmosdb_gremlin_database_name", "cosmosdb_gremlin_graph_name", "cosmosdb_mongo_database_name", "cosmosdb_sql_database_name"}, + }, + + "cosmosdb_gremlin_database_name": { + Type: pluginsdk.TypeString, + Optional: true, + RequiredWith: []string{"cosmosdb_gremlin_graph_name"}, + ConflictsWith: []string{"cosmosdb_cassandra_keyspace_name", "cosmosdb_mongo_database_name", "cosmosdb_sql_database_name"}, + }, + + "cosmosdb_gremlin_graph_name": { + Type: pluginsdk.TypeString, + Optional: true, + RequiredWith: []string{"cosmosdb_gremlin_database_name"}, + ConflictsWith: []string{"cosmosdb_cassandra_keyspace_name", "cosmosdb_mongo_database_name", "cosmosdb_sql_database_name"}, + }, + + "cosmosdb_mongo_database_name": { + Type: pluginsdk.TypeString, + Optional: true, + ConflictsWith: []string{"cosmosdb_cassandra_keyspace_name", "cosmosdb_gremlin_database_name", "cosmosdb_gremlin_graph_name", "cosmosdb_sql_database_name"}, + }, + + "cosmosdb_sql_database_name": { + Type: pluginsdk.TypeString, + Optional: true, + ConflictsWith: []string{"cosmosdb_cassandra_keyspace_name", "cosmosdb_gremlin_database_name", "cosmosdb_gremlin_graph_name", "cosmosdb_mongo_database_name"}, + }, + } +} + +func (s SpringCloudAppCosmosDbAssociationV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudAppAssociationIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/app_migration_v0_to_v1.go b/internal/services/springcloud/migration/app_migration_v0_to_v1.go new file mode 100644 index 000000000000..d65e189e31ab --- /dev/null +++ b/internal/services/springcloud/migration/app_migration_v0_to_v1.go @@ -0,0 +1,213 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudAppV0ToV1 struct{} + +func (s SpringCloudAppV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "resource_group_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "service_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "addon_json": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + + "identity": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": { + Type: schema.TypeString, + Required: true, + }, + "identity_ids": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "principal_id": { + Type: schema.TypeString, + Computed: true, + }, + "tenant_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + + "custom_persistent_disk": { + Type: pluginsdk.TypeList, + Optional: true, + MinItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "storage_name": { + Type: schema.TypeString, + Required: true, + }, + + "mount_path": { + Type: schema.TypeString, + Required: true, + }, + + "share_name": { + Type: schema.TypeString, + Required: true, + }, + + "mount_options": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + + "read_only_enabled": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + }, + }, + }, + + "is_public": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "https_only": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "ingress_settings": { + Type: pluginsdk.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "backend_protocol": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "read_timeout_in_seconds": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 300, + }, + + "send_timeout_in_seconds": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 60, + }, + + "session_affinity": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "session_cookie_max_age": { + Type: pluginsdk.TypeInt, + Optional: true, + }, + }, + }, + }, + + "persistent_disk": { + Type: pluginsdk.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "size_in_gb": { + Type: pluginsdk.TypeInt, + Required: true, + }, + + "mount_path": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "/persistent", + }, + }, + }, + }, + + "public_endpoint_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "tls_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "fqdn": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "url": { + Type: pluginsdk.TypeString, + Computed: true, + }, + } +} + +func (s SpringCloudAppV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudAppIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/app_mysql_association_migration_v0_to_v1.go b/internal/services/springcloud/migration/app_mysql_association_migration_v0_to_v1.go new file mode 100644 index 000000000000..a702c687754a --- /dev/null +++ b/internal/services/springcloud/migration/app_mysql_association_migration_v0_to_v1.go @@ -0,0 +1,64 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudAppMySqlAssociationV0ToV1 struct{} + +func (s SpringCloudAppMySqlAssociationV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_app_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "mysql_server_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "database_name": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "username": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "password": { + Type: pluginsdk.TypeString, + Required: true, + Sensitive: true, + }, + } +} + +func (s SpringCloudAppMySqlAssociationV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudAppAssociationIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/app_redis_association_migration_v0_to_v1.go b/internal/services/springcloud/migration/app_redis_association_migration_v0_to_v1.go new file mode 100644 index 000000000000..362585afb1f9 --- /dev/null +++ b/internal/services/springcloud/migration/app_redis_association_migration_v0_to_v1.go @@ -0,0 +1,59 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudAppRedisAssociationV0ToV1 struct{} + +func (s SpringCloudAppRedisAssociationV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_app_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "redis_cache_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "redis_access_key": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "ssl_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: true, + }, + } +} + +func (s SpringCloudAppRedisAssociationV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudAppAssociationIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/build_deployment_migration_v0_to_v1.go b/internal/services/springcloud/migration/build_deployment_migration_v0_to_v1.go new file mode 100644 index 000000000000..a3394f06c7ce --- /dev/null +++ b/internal/services/springcloud/migration/build_deployment_migration_v0_to_v1.go @@ -0,0 +1,89 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudBuildDeploymentV0ToV1 struct{} + +func (s SpringCloudBuildDeploymentV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_app_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "build_result_id": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "addon_json": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + + "environment_variables": { + Type: pluginsdk.TypeMap, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "instance_count": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 1, + }, + + "quota": { + Type: pluginsdk.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "cpu": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + + "memory": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + } +} + +func (s SpringCloudBuildDeploymentV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudDeploymentIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/build_service_builder_migration_v0_to_v1.go b/internal/services/springcloud/migration/build_service_builder_migration_v0_to_v1.go new file mode 100644 index 000000000000..a94d791c0384 --- /dev/null +++ b/internal/services/springcloud/migration/build_service_builder_migration_v0_to_v1.go @@ -0,0 +1,84 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudBuildServiceBuilderV0ToV1 struct{} + +func (s SpringCloudBuildServiceBuilderV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_service_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "build_pack_group": { + Type: pluginsdk.TypeSet, + Required: true, + MinItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "build_pack_ids": { + Type: pluginsdk.TypeList, + Optional: true, + MinItems: 1, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + }, + }, + }, + + "stack": { + Type: pluginsdk.TypeList, + Required: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "id": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "version": { + Type: pluginsdk.TypeString, + Required: true, + }, + }, + }, + }, + } +} + +func (s SpringCloudBuildServiceBuilderV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudBuildServiceBuilderIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/certificate_migration_v0_to_v1.go b/internal/services/springcloud/migration/certificate_migration_v0_to_v1.go new file mode 100644 index 000000000000..8ac0e261c572 --- /dev/null +++ b/internal/services/springcloud/migration/certificate_migration_v0_to_v1.go @@ -0,0 +1,68 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudCertificateV0ToV1 struct{} + +func (s SpringCloudCertificateV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "resource_group_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "service_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "certificate_content": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + AtLeastOneOf: []string{"key_vault_certificate_id", "certificate_content"}, + }, + + "key_vault_certificate_id": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + AtLeastOneOf: []string{"key_vault_certificate_id", "certificate_content"}, + }, + + "thumbprint": { + Type: pluginsdk.TypeString, + Computed: true, + }, + } +} + +func (s SpringCloudCertificateV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudCertificateIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/cloud_storage_migration_v0_to_v1.go b/internal/services/springcloud/migration/cloud_storage_migration_v0_to_v1.go new file mode 100644 index 000000000000..8378692e87d3 --- /dev/null +++ b/internal/services/springcloud/migration/cloud_storage_migration_v0_to_v1.go @@ -0,0 +1,52 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudCloudStorageV0ToV1 struct{} + +func (s SpringCloudCloudStorageV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_service_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "storage_account_name": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "storage_account_key": { + Type: pluginsdk.TypeString, + Required: true, + }, + } +} + +func (s SpringCloudCloudStorageV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudStorageIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/configuration_service_migration_v0_to_v1.go b/internal/services/springcloud/migration/configuration_service_migration_v0_to_v1.go new file mode 100644 index 000000000000..f750ee60d30b --- /dev/null +++ b/internal/services/springcloud/migration/configuration_service_migration_v0_to_v1.go @@ -0,0 +1,111 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudConfigurationServiceV0ToV1 struct{} + +func (s SpringCloudConfigurationServiceV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_service_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "repository": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "label": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "patterns": { + Type: pluginsdk.TypeSet, + Required: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "uri": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "host_key": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "host_key_algorithm": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "password": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "private_key": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "search_paths": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "strict_host_key_checking": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "username": { + Type: pluginsdk.TypeString, + Optional: true, + }, + }, + }, + }, + } +} + +func (s SpringCloudConfigurationServiceV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudConfigurationServiceIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/container_deployment_migration_v0_to_v1.go b/internal/services/springcloud/migration/container_deployment_migration_v0_to_v1.go new file mode 100644 index 000000000000..8390717ce3d2 --- /dev/null +++ b/internal/services/springcloud/migration/container_deployment_migration_v0_to_v1.go @@ -0,0 +1,115 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudContainerDeploymentV0ToV1 struct{} + +func (s SpringCloudContainerDeploymentV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_app_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "image": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "server": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "addon_json": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + + "arguments": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "commands": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "environment_variables": { + Type: pluginsdk.TypeMap, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "instance_count": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 1, + }, + + "language_framework": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "quota": { + Type: pluginsdk.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "cpu": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + + "memory": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + } +} + +func (s SpringCloudContainerDeploymentV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudDeploymentIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/custom_domain_migration_v0_to_v1.go b/internal/services/springcloud/migration/custom_domain_migration_v0_to_v1.go new file mode 100644 index 000000000000..a65514111a55 --- /dev/null +++ b/internal/services/springcloud/migration/custom_domain_migration_v0_to_v1.go @@ -0,0 +1,55 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudCustomDomainV0ToV1 struct{} + +func (s SpringCloudCustomDomainV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_app_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "certificate_name": { + Type: pluginsdk.TypeString, + Optional: true, + RequiredWith: []string{"thumbprint"}, + }, + + "thumbprint": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + RequiredWith: []string{"certificate_name"}, + }, + } +} + +func (s SpringCloudCustomDomainV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudCustomDomainIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/gateway_custom_domain_migration_v0_to_v1.go b/internal/services/springcloud/migration/gateway_custom_domain_migration_v0_to_v1.go new file mode 100644 index 000000000000..7433826cd407 --- /dev/null +++ b/internal/services/springcloud/migration/gateway_custom_domain_migration_v0_to_v1.go @@ -0,0 +1,47 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudGatewayCustomDomainV0ToV1 struct{} + +func (s SpringCloudGatewayCustomDomainV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_gateway_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "thumbprint": { + Type: pluginsdk.TypeString, + Optional: true, + }, + } +} + +func (s SpringCloudGatewayCustomDomainV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudGatewayCustomDomainIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/gateway_migration_v0_to_v1.go b/internal/services/springcloud/migration/gateway_migration_v0_to_v1.go new file mode 100644 index 000000000000..6cd4a80a326c --- /dev/null +++ b/internal/services/springcloud/migration/gateway_migration_v0_to_v1.go @@ -0,0 +1,202 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudGatewayV0ToV1 struct{} + +func (s SpringCloudGatewayV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_service_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "api_metadata": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "description": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "documentation_url": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "server_url": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "title": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "version": { + Type: pluginsdk.TypeString, + Optional: true, + }, + }, + }, + }, + + "cors": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "credentials_allowed": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "allowed_headers": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "allowed_methods": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "allowed_origins": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "exposed_headers": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "max_age_seconds": { + Type: pluginsdk.TypeInt, + Optional: true, + }, + }, + }, + }, + + "https_only": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "instance_count": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 1, + }, + + "public_network_access_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "quota": { + Type: pluginsdk.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "cpu": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "1", + }, + + "memory": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "2Gi", + }, + }, + }, + }, + + "sso": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "client_id": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "client_secret": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "issuer_uri": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "scope": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + }, + }, + }, + + "url": { + Type: pluginsdk.TypeString, + Computed: true, + }, + } +} + +func (s SpringCloudGatewayV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudGatewayIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/gateway_route_config_migration_v0_to_v1.go b/internal/services/springcloud/migration/gateway_route_config_migration_v0_to_v1.go new file mode 100644 index 000000000000..ba234dff1daf --- /dev/null +++ b/internal/services/springcloud/migration/gateway_route_config_migration_v0_to_v1.go @@ -0,0 +1,128 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudGatewayRouteConfigV0ToV1 struct{} + +func (s SpringCloudGatewayRouteConfigV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_gateway_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "open_api": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "uri": { + Type: pluginsdk.TypeString, + Optional: true, + }, + }, + }, + }, + + "protocol": { + Type: pluginsdk.TypeString, + Required: false, + }, + + "spring_cloud_app_id": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "route": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "description": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "filters": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "order": { + Type: pluginsdk.TypeInt, + Optional: true, + }, + + "predicates": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "sso_validation_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "title": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "token_relay": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "uri": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "classification_tags": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + }, + }, + }, + } +} + +func (s SpringCloudGatewayRouteConfigV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudGatewayRouteConfigIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/java_deployment_migration_v0_to_v1.go b/internal/services/springcloud/migration/java_deployment_migration_v0_to_v1.go new file mode 100644 index 000000000000..9351f522999d --- /dev/null +++ b/internal/services/springcloud/migration/java_deployment_migration_v0_to_v1.go @@ -0,0 +1,88 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudJavaDeploymentV0ToV1 struct{} + +func (s SpringCloudJavaDeploymentV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "spring_cloud_app_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "environment_variables": { + Type: pluginsdk.TypeMap, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "instance_count": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 1, + }, + + "jvm_options": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "quota": { + Type: pluginsdk.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "cpu": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + + "memory": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + + "runtime_version": { + Type: pluginsdk.TypeString, + Optional: true, + }, + } +} + +func (s SpringCloudJavaDeploymentV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudDeploymentIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/migration/spring_cloud_migration_v0_to_v1.go b/internal/services/springcloud/migration/spring_cloud_migration_v0_to_v1.go new file mode 100644 index 000000000000..02e839ae6ab2 --- /dev/null +++ b/internal/services/springcloud/migration/spring_cloud_migration_v0_to_v1.go @@ -0,0 +1,378 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type SpringCloudV0ToV1 struct{} + +func (s SpringCloudV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "location": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "resource_group_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "sku_name": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "S0", + ForceNew: true, + }, + + "build_agent_pool_size": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "log_stream_public_endpoint_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "network": { + Type: pluginsdk.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "app_subnet_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "service_runtime_subnet_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "cidr_ranges": { + Type: pluginsdk.TypeList, + Required: true, + ForceNew: true, + MinItems: 3, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "app_network_resource_group": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + + "read_timeout_seconds": { + Type: pluginsdk.TypeInt, + Optional: true, + }, + + "service_runtime_network_resource_group": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + }, + }, + + "config_server_git_setting": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "uri": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "label": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "search_paths": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "http_basic_auth": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "username": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "password": { + Type: pluginsdk.TypeString, + Required: true, + Sensitive: true, + }, + }, + }, + }, + + "ssh_auth": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "private_key": { + Type: pluginsdk.TypeString, + Required: true, + Sensitive: true, + }, + + "host_key": { + Type: pluginsdk.TypeString, + Optional: true, + Sensitive: true, + }, + + "host_key_algorithm": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "strict_host_key_checking_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: true, + }, + }, + }, + }, + + "repository": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "uri": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "label": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "pattern": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "search_paths": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "http_basic_auth": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "username": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "password": { + Type: pluginsdk.TypeString, + Required: true, + Sensitive: true, + }, + }, + }, + }, + + "ssh_auth": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "private_key": { + Type: pluginsdk.TypeString, + Required: true, + Sensitive: true, + }, + + "host_key": { + Type: pluginsdk.TypeString, + Optional: true, + Sensitive: true, + }, + + "host_key_algorithm": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "strict_host_key_checking_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: true, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + + "trace": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "connection_string": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "sample_rate": { + Type: pluginsdk.TypeFloat, + Optional: true, + Default: 10, + }, + }, + }, + }, + + "service_registry_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "outbound_public_ip_addresses": { + Type: pluginsdk.TypeList, + Computed: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "required_network_traffic_rules": { + Type: pluginsdk.TypeList, + Computed: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "protocol": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "port": { + Type: pluginsdk.TypeInt, + Computed: true, + }, + + "ip_addresses": { + Type: pluginsdk.TypeList, + Computed: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "fqdns": { + Type: pluginsdk.TypeList, + Computed: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "direction": { + Type: pluginsdk.TypeString, + Computed: true, + }, + }, + }, + }, + + "zone_redundant": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "tags": { + Type: pluginsdk.TypeMap, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "service_registry_id": { + Type: pluginsdk.TypeString, + Computed: true, + }, + } +} + +func (s SpringCloudV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SpringCloudServiceIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_api_portal.go b/internal/services/springcloud/parse/spring_cloud_api_portal.go index f709c1d875b2..d4e6c4afb6a6 100644 --- a/internal/services/springcloud/parse/spring_cloud_api_portal.go +++ b/internal/services/springcloud/parse/spring_cloud_api_portal.go @@ -36,7 +36,7 @@ func (id SpringCloudAPIPortalId) String() string { } func (id SpringCloudAPIPortalId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/apiPortals/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/apiPortals/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.ApiPortalName) } @@ -60,7 +60,7 @@ func SpringCloudAPIPortalID(input string) (*SpringCloudAPIPortalId, error) { return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.ApiPortalName, err = id.PopSegment("apiPortals"); err != nil { @@ -73,3 +73,59 @@ func SpringCloudAPIPortalID(input string) (*SpringCloudAPIPortalId, error) { return &resourceId, nil } + +// SpringCloudAPIPortalIDInsensitively parses an SpringCloudAPIPortal ID into an SpringCloudAPIPortalId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudAPIPortalID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudAPIPortalIDInsensitively(input string) (*SpringCloudAPIPortalId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudAPIPortalId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'apiPortals' segment + apiPortalsKey := "apiPortals" + for key := range id.Path { + if strings.EqualFold(key, apiPortalsKey) { + apiPortalsKey = key + break + } + } + if resourceId.ApiPortalName, err = id.PopSegment(apiPortalsKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_api_portal_custom_domain.go b/internal/services/springcloud/parse/spring_cloud_api_portal_custom_domain.go index d06955e0f611..893d143c3372 100644 --- a/internal/services/springcloud/parse/spring_cloud_api_portal_custom_domain.go +++ b/internal/services/springcloud/parse/spring_cloud_api_portal_custom_domain.go @@ -39,7 +39,7 @@ func (id SpringCloudAPIPortalCustomDomainId) String() string { } func (id SpringCloudAPIPortalCustomDomainId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/apiPortals/%s/domains/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/apiPortals/%s/domains/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.ApiPortalName, id.DomainName) } @@ -63,7 +63,7 @@ func SpringCloudAPIPortalCustomDomainID(input string) (*SpringCloudAPIPortalCust return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.ApiPortalName, err = id.PopSegment("apiPortals"); err != nil { @@ -79,3 +79,71 @@ func SpringCloudAPIPortalCustomDomainID(input string) (*SpringCloudAPIPortalCust return &resourceId, nil } + +// SpringCloudAPIPortalCustomDomainIDInsensitively parses an SpringCloudAPIPortalCustomDomain ID into an SpringCloudAPIPortalCustomDomainId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudAPIPortalCustomDomainID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudAPIPortalCustomDomainIDInsensitively(input string) (*SpringCloudAPIPortalCustomDomainId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudAPIPortalCustomDomainId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'apiPortals' segment + apiPortalsKey := "apiPortals" + for key := range id.Path { + if strings.EqualFold(key, apiPortalsKey) { + apiPortalsKey = key + break + } + } + if resourceId.ApiPortalName, err = id.PopSegment(apiPortalsKey); err != nil { + return nil, err + } + + // find the correct casing for the 'domains' segment + domainsKey := "domains" + for key := range id.Path { + if strings.EqualFold(key, domainsKey) { + domainsKey = key + break + } + } + if resourceId.DomainName, err = id.PopSegment(domainsKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_api_portal_custom_domain_test.go b/internal/services/springcloud/parse/spring_cloud_api_portal_custom_domain_test.go index 4e15e624ae1e..7ff19736ddb9 100644 --- a/internal/services/springcloud/parse/spring_cloud_api_portal_custom_domain_test.go +++ b/internal/services/springcloud/parse/spring_cloud_api_portal_custom_domain_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudAPIPortalCustomDomainId{} func TestSpringCloudAPIPortalCustomDomainIDFormatter(t *testing.T) { actual := NewSpringCloudAPIPortalCustomDomainID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "service1", "apiPortal1", "domain1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1/domains/domain1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1/domains/domain1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,37 +63,37 @@ func TestSpringCloudAPIPortalCustomDomainID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing ApiPortalName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Error: true, }, { // missing value for ApiPortalName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/", Error: true, }, { // missing DomainName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1/", Error: true, }, { // missing value for DomainName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1/domains/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1/domains/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1/domains/domain1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1/domains/domain1", Expected: &SpringCloudAPIPortalCustomDomainId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resourceGroup1", @@ -142,3 +142,158 @@ func TestSpringCloudAPIPortalCustomDomainID(t *testing.T) { } } } + +func TestSpringCloudAPIPortalCustomDomainIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudAPIPortalCustomDomainId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing ApiPortalName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", + Error: true, + }, + + { + // missing value for ApiPortalName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/", + Error: true, + }, + + { + // missing DomainName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1/", + Error: true, + }, + + { + // missing value for DomainName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1/domains/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1/domains/domain1", + Expected: &SpringCloudAPIPortalCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + ApiPortalName: "apiPortal1", + DomainName: "domain1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiportals/apiPortal1/domains/domain1", + Expected: &SpringCloudAPIPortalCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + ApiPortalName: "apiPortal1", + DomainName: "domain1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SPRING/service1/APIPORTALS/apiPortal1/DOMAINS/domain1", + Expected: &SpringCloudAPIPortalCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + ApiPortalName: "apiPortal1", + DomainName: "domain1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SpRiNg/service1/ApIpOrTaLs/apiPortal1/DoMaInS/domain1", + Expected: &SpringCloudAPIPortalCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + ApiPortalName: "apiPortal1", + DomainName: "domain1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudAPIPortalCustomDomainIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.ApiPortalName != v.Expected.ApiPortalName { + t.Fatalf("Expected %q but got %q for ApiPortalName", v.Expected.ApiPortalName, actual.ApiPortalName) + } + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_api_portal_test.go b/internal/services/springcloud/parse/spring_cloud_api_portal_test.go index f6a4aa926e98..9ed45a116796 100644 --- a/internal/services/springcloud/parse/spring_cloud_api_portal_test.go +++ b/internal/services/springcloud/parse/spring_cloud_api_portal_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudAPIPortalId{} func TestSpringCloudAPIPortalIDFormatter(t *testing.T) { actual := NewSpringCloudAPIPortalID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "service1", "apiPortal1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,25 +63,25 @@ func TestSpringCloudAPIPortalID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing ApiPortalName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Error: true, }, { // missing value for ApiPortalName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1", Expected: &SpringCloudAPIPortalId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resourceGroup1", @@ -126,3 +126,139 @@ func TestSpringCloudAPIPortalID(t *testing.T) { } } } + +func TestSpringCloudAPIPortalIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudAPIPortalId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing ApiPortalName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", + Error: true, + }, + + { + // missing value for ApiPortalName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1", + Expected: &SpringCloudAPIPortalId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + ApiPortalName: "apiPortal1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiportals/apiPortal1", + Expected: &SpringCloudAPIPortalId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + ApiPortalName: "apiPortal1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SPRING/service1/APIPORTALS/apiPortal1", + Expected: &SpringCloudAPIPortalId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + ApiPortalName: "apiPortal1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SpRiNg/service1/ApIpOrTaLs/apiPortal1", + Expected: &SpringCloudAPIPortalId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + ApiPortalName: "apiPortal1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudAPIPortalIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.ApiPortalName != v.Expected.ApiPortalName { + t.Fatalf("Expected %q but got %q for ApiPortalName", v.Expected.ApiPortalName, actual.ApiPortalName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_app.go b/internal/services/springcloud/parse/spring_cloud_app.go index 7b38ca19b78a..dd983b423f84 100644 --- a/internal/services/springcloud/parse/spring_cloud_app.go +++ b/internal/services/springcloud/parse/spring_cloud_app.go @@ -36,7 +36,7 @@ func (id SpringCloudAppId) String() string { } func (id SpringCloudAppId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/apps/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/apps/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.AppName) } @@ -60,7 +60,7 @@ func SpringCloudAppID(input string) (*SpringCloudAppId, error) { return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.AppName, err = id.PopSegment("apps"); err != nil { @@ -73,3 +73,59 @@ func SpringCloudAppID(input string) (*SpringCloudAppId, error) { return &resourceId, nil } + +// SpringCloudAppIDInsensitively parses an SpringCloudApp ID into an SpringCloudAppId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudAppID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudAppIDInsensitively(input string) (*SpringCloudAppId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudAppId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'apps' segment + appsKey := "apps" + for key := range id.Path { + if strings.EqualFold(key, appsKey) { + appsKey = key + break + } + } + if resourceId.AppName, err = id.PopSegment(appsKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_app_association.go b/internal/services/springcloud/parse/spring_cloud_app_association.go index d42ec34c981c..9925c3db47db 100644 --- a/internal/services/springcloud/parse/spring_cloud_app_association.go +++ b/internal/services/springcloud/parse/spring_cloud_app_association.go @@ -39,7 +39,7 @@ func (id SpringCloudAppAssociationId) String() string { } func (id SpringCloudAppAssociationId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/apps/%s/bindings/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/apps/%s/bindings/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.AppName, id.BindingName) } @@ -63,7 +63,7 @@ func SpringCloudAppAssociationID(input string) (*SpringCloudAppAssociationId, er return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.AppName, err = id.PopSegment("apps"); err != nil { @@ -79,3 +79,71 @@ func SpringCloudAppAssociationID(input string) (*SpringCloudAppAssociationId, er return &resourceId, nil } + +// SpringCloudAppAssociationIDInsensitively parses an SpringCloudAppAssociation ID into an SpringCloudAppAssociationId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudAppAssociationID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudAppAssociationIDInsensitively(input string) (*SpringCloudAppAssociationId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudAppAssociationId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'apps' segment + appsKey := "apps" + for key := range id.Path { + if strings.EqualFold(key, appsKey) { + appsKey = key + break + } + } + if resourceId.AppName, err = id.PopSegment(appsKey); err != nil { + return nil, err + } + + // find the correct casing for the 'bindings' segment + bindingsKey := "bindings" + for key := range id.Path { + if strings.EqualFold(key, bindingsKey) { + bindingsKey = key + break + } + } + if resourceId.BindingName, err = id.PopSegment(bindingsKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_app_association_test.go b/internal/services/springcloud/parse/spring_cloud_app_association_test.go index a99314940fe9..c5a390ba6177 100644 --- a/internal/services/springcloud/parse/spring_cloud_app_association_test.go +++ b/internal/services/springcloud/parse/spring_cloud_app_association_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudAppAssociationId{} func TestSpringCloudAppAssociationIDFormatter(t *testing.T) { actual := NewSpringCloudAppAssociationID("12345678-1234-9876-4563-123456789012", "resGroup1", "spring1", "app1", "bind1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/bindings/bind1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/bindings/bind1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,37 +63,37 @@ func TestSpringCloudAppAssociationID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", Error: true, }, { // missing value for AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/", Error: true, }, { // missing BindingName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/", Error: true, }, { // missing value for BindingName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/bindings/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/bindings/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/bindings/bind1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/bindings/bind1", Expected: &SpringCloudAppAssociationId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resGroup1", @@ -142,3 +142,158 @@ func TestSpringCloudAppAssociationID(t *testing.T) { } } } + +func TestSpringCloudAppAssociationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudAppAssociationId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing AppName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", + Error: true, + }, + + { + // missing value for AppName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/", + Error: true, + }, + + { + // missing BindingName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/", + Error: true, + }, + + { + // missing value for BindingName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/bindings/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/bindings/bind1", + Expected: &SpringCloudAppAssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + BindingName: "bind1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/bindings/bind1", + Expected: &SpringCloudAppAssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + BindingName: "bind1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SPRING/spring1/APPS/app1/BINDINGS/bind1", + Expected: &SpringCloudAppAssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + BindingName: "bind1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SpRiNg/spring1/ApPs/app1/BiNdInGs/bind1", + Expected: &SpringCloudAppAssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + BindingName: "bind1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudAppAssociationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.AppName != v.Expected.AppName { + t.Fatalf("Expected %q but got %q for AppName", v.Expected.AppName, actual.AppName) + } + if actual.BindingName != v.Expected.BindingName { + t.Fatalf("Expected %q but got %q for BindingName", v.Expected.BindingName, actual.BindingName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_app_test.go b/internal/services/springcloud/parse/spring_cloud_app_test.go index 7b005a7390de..7c951ea7f927 100644 --- a/internal/services/springcloud/parse/spring_cloud_app_test.go +++ b/internal/services/springcloud/parse/spring_cloud_app_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudAppId{} func TestSpringCloudAppIDFormatter(t *testing.T) { actual := NewSpringCloudAppID("12345678-1234-9876-4563-123456789012", "resGroup1", "spring1", "app1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,25 +63,25 @@ func TestSpringCloudAppID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", Error: true, }, { // missing value for AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1", Expected: &SpringCloudAppId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resGroup1", @@ -126,3 +126,139 @@ func TestSpringCloudAppID(t *testing.T) { } } } + +func TestSpringCloudAppIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudAppId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing AppName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", + Error: true, + }, + + { + // missing value for AppName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1", + Expected: &SpringCloudAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1", + Expected: &SpringCloudAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SPRING/spring1/APPS/app1", + Expected: &SpringCloudAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SpRiNg/spring1/ApPs/app1", + Expected: &SpringCloudAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudAppIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.AppName != v.Expected.AppName { + t.Fatalf("Expected %q but got %q for AppName", v.Expected.AppName, actual.AppName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_application_live_view.go b/internal/services/springcloud/parse/spring_cloud_application_live_view.go index a498b4a4de0c..d28e56822c80 100644 --- a/internal/services/springcloud/parse/spring_cloud_application_live_view.go +++ b/internal/services/springcloud/parse/spring_cloud_application_live_view.go @@ -36,7 +36,7 @@ func (id SpringCloudApplicationLiveViewId) String() string { } func (id SpringCloudApplicationLiveViewId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/applicationLiveViews/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/applicationLiveViews/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.ApplicationLiveViewName) } @@ -60,7 +60,7 @@ func SpringCloudApplicationLiveViewID(input string) (*SpringCloudApplicationLive return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.ApplicationLiveViewName, err = id.PopSegment("applicationLiveViews"); err != nil { diff --git a/internal/services/springcloud/parse/spring_cloud_application_live_view_test.go b/internal/services/springcloud/parse/spring_cloud_application_live_view_test.go index 9ce33a8927f4..81bb0cb43bb0 100644 --- a/internal/services/springcloud/parse/spring_cloud_application_live_view_test.go +++ b/internal/services/springcloud/parse/spring_cloud_application_live_view_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudApplicationLiveViewId{} func TestSpringCloudApplicationLiveViewIDFormatter(t *testing.T) { actual := NewSpringCloudApplicationLiveViewID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "service1", "default").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/applicationLiveViews/default" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/applicationLiveViews/default" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,25 +63,25 @@ func TestSpringCloudApplicationLiveViewID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing ApplicationLiveViewName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Error: true, }, { // missing value for ApplicationLiveViewName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/applicationLiveViews/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/applicationLiveViews/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/applicationLiveViews/default", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/applicationLiveViews/default", Expected: &SpringCloudApplicationLiveViewId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resourceGroup1", diff --git a/internal/services/springcloud/parse/spring_cloud_build_pack_binding.go b/internal/services/springcloud/parse/spring_cloud_build_pack_binding.go index 6d8d142d2a7a..4ceb5d0dcb1a 100644 --- a/internal/services/springcloud/parse/spring_cloud_build_pack_binding.go +++ b/internal/services/springcloud/parse/spring_cloud_build_pack_binding.go @@ -42,7 +42,7 @@ func (id SpringCloudBuildPackBindingId) String() string { } func (id SpringCloudBuildPackBindingId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/buildServices/%s/builders/%s/buildPackBindings/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/buildServices/%s/builders/%s/buildPackBindings/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.BuildServiceName, id.BuilderName, id.BuildPackBindingName) } @@ -66,7 +66,7 @@ func SpringCloudBuildPackBindingID(input string) (*SpringCloudBuildPackBindingId return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.BuildServiceName, err = id.PopSegment("buildServices"); err != nil { @@ -111,15 +111,15 @@ func SpringCloudBuildPackBindingIDInsensitively(input string) (*SpringCloudBuild return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - // find the correct casing for the 'Spring' segment - SpringKey := "Spring" + // find the correct casing for the 'spring' segment + springKey := "spring" for key := range id.Path { - if strings.EqualFold(key, SpringKey) { - SpringKey = key + if strings.EqualFold(key, springKey) { + springKey = key break } } - if resourceId.SpringName, err = id.PopSegment(SpringKey); err != nil { + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { return nil, err } diff --git a/internal/services/springcloud/parse/spring_cloud_build_pack_binding_test.go b/internal/services/springcloud/parse/spring_cloud_build_pack_binding_test.go index 0f48df20f0a4..7f9c27a38d6d 100644 --- a/internal/services/springcloud/parse/spring_cloud_build_pack_binding_test.go +++ b/internal/services/springcloud/parse/spring_cloud_build_pack_binding_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudBuildPackBindingId{} func TestSpringCloudBuildPackBindingIDFormatter(t *testing.T) { actual := NewSpringCloudBuildPackBindingID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "service1", "buildService1", "builder1", "buildPackBinding1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/buildPackBinding1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/buildPackBinding1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,49 +63,49 @@ func TestSpringCloudBuildPackBindingID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing BuildServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Error: true, }, { // missing value for BuildServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/", Error: true, }, { // missing BuilderName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/", Error: true, }, { // missing value for BuilderName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/", Error: true, }, { // missing BuildPackBindingName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1/", Error: true, }, { // missing value for BuildPackBindingName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/buildPackBinding1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/buildPackBinding1", Expected: &SpringCloudBuildPackBindingId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resourceGroup1", @@ -204,49 +204,49 @@ func TestSpringCloudBuildPackBindingIDInsensitively(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing BuildServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Error: true, }, { // missing value for BuildServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/", Error: true, }, { // missing BuilderName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/", Error: true, }, { // missing value for BuilderName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/", Error: true, }, { // missing BuildPackBindingName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1/", Error: true, }, { // missing value for BuildPackBindingName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/buildPackBinding1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/buildPackBinding1", Expected: &SpringCloudBuildPackBindingId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resourceGroup1", diff --git a/internal/services/springcloud/parse/spring_cloud_build_service_builder.go b/internal/services/springcloud/parse/spring_cloud_build_service_builder.go index b7702b020d3f..36679808f811 100644 --- a/internal/services/springcloud/parse/spring_cloud_build_service_builder.go +++ b/internal/services/springcloud/parse/spring_cloud_build_service_builder.go @@ -39,7 +39,7 @@ func (id SpringCloudBuildServiceBuilderId) String() string { } func (id SpringCloudBuildServiceBuilderId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/buildServices/%s/builders/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/buildServices/%s/builders/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.BuildServiceName, id.BuilderName) } @@ -63,7 +63,7 @@ func SpringCloudBuildServiceBuilderID(input string) (*SpringCloudBuildServiceBui return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.BuildServiceName, err = id.PopSegment("buildServices"); err != nil { @@ -79,3 +79,71 @@ func SpringCloudBuildServiceBuilderID(input string) (*SpringCloudBuildServiceBui return &resourceId, nil } + +// SpringCloudBuildServiceBuilderIDInsensitively parses an SpringCloudBuildServiceBuilder ID into an SpringCloudBuildServiceBuilderId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudBuildServiceBuilderID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudBuildServiceBuilderIDInsensitively(input string) (*SpringCloudBuildServiceBuilderId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudBuildServiceBuilderId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'buildServices' segment + buildServicesKey := "buildServices" + for key := range id.Path { + if strings.EqualFold(key, buildServicesKey) { + buildServicesKey = key + break + } + } + if resourceId.BuildServiceName, err = id.PopSegment(buildServicesKey); err != nil { + return nil, err + } + + // find the correct casing for the 'builders' segment + buildersKey := "builders" + for key := range id.Path { + if strings.EqualFold(key, buildersKey) { + buildersKey = key + break + } + } + if resourceId.BuilderName, err = id.PopSegment(buildersKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_build_service_builder_test.go b/internal/services/springcloud/parse/spring_cloud_build_service_builder_test.go index 9c8169ab0bad..52669bcffe41 100644 --- a/internal/services/springcloud/parse/spring_cloud_build_service_builder_test.go +++ b/internal/services/springcloud/parse/spring_cloud_build_service_builder_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudBuildServiceBuilderId{} func TestSpringCloudBuildServiceBuilderIDFormatter(t *testing.T) { actual := NewSpringCloudBuildServiceBuilderID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "service1", "buildService1", "builder1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,37 +63,37 @@ func TestSpringCloudBuildServiceBuilderID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing BuildServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Error: true, }, { // missing value for BuildServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/", Error: true, }, { // missing BuilderName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/", Error: true, }, { // missing value for BuilderName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1", Expected: &SpringCloudBuildServiceBuilderId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resourceGroup1", @@ -142,3 +142,158 @@ func TestSpringCloudBuildServiceBuilderID(t *testing.T) { } } } + +func TestSpringCloudBuildServiceBuilderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudBuildServiceBuilderId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing BuildServiceName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", + Error: true, + }, + + { + // missing value for BuildServiceName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/", + Error: true, + }, + + { + // missing BuilderName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/", + Error: true, + }, + + { + // missing value for BuilderName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1", + Expected: &SpringCloudBuildServiceBuilderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + BuildServiceName: "buildService1", + BuilderName: "builder1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildservices/buildService1/builders/builder1", + Expected: &SpringCloudBuildServiceBuilderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + BuildServiceName: "buildService1", + BuilderName: "builder1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SPRING/service1/BUILDSERVICES/buildService1/BUILDERS/builder1", + Expected: &SpringCloudBuildServiceBuilderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + BuildServiceName: "buildService1", + BuilderName: "builder1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SpRiNg/service1/BuIlDsErViCeS/buildService1/BuIlDeRs/builder1", + Expected: &SpringCloudBuildServiceBuilderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + BuildServiceName: "buildService1", + BuilderName: "builder1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudBuildServiceBuilderIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.BuildServiceName != v.Expected.BuildServiceName { + t.Fatalf("Expected %q but got %q for BuildServiceName", v.Expected.BuildServiceName, actual.BuildServiceName) + } + if actual.BuilderName != v.Expected.BuilderName { + t.Fatalf("Expected %q but got %q for BuilderName", v.Expected.BuilderName, actual.BuilderName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_certificate.go b/internal/services/springcloud/parse/spring_cloud_certificate.go index 70fffb3210c7..7b2a15e8145e 100644 --- a/internal/services/springcloud/parse/spring_cloud_certificate.go +++ b/internal/services/springcloud/parse/spring_cloud_certificate.go @@ -36,7 +36,7 @@ func (id SpringCloudCertificateId) String() string { } func (id SpringCloudCertificateId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/certificates/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/certificates/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.CertificateName) } @@ -60,7 +60,7 @@ func SpringCloudCertificateID(input string) (*SpringCloudCertificateId, error) { return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.CertificateName, err = id.PopSegment("certificates"); err != nil { @@ -73,3 +73,59 @@ func SpringCloudCertificateID(input string) (*SpringCloudCertificateId, error) { return &resourceId, nil } + +// SpringCloudCertificateIDInsensitively parses an SpringCloudCertificate ID into an SpringCloudCertificateId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudCertificateID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudCertificateIDInsensitively(input string) (*SpringCloudCertificateId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudCertificateId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'certificates' segment + certificatesKey := "certificates" + for key := range id.Path { + if strings.EqualFold(key, certificatesKey) { + certificatesKey = key + break + } + } + if resourceId.CertificateName, err = id.PopSegment(certificatesKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_certificate_test.go b/internal/services/springcloud/parse/spring_cloud_certificate_test.go index 23eeac142452..86c28680ab66 100644 --- a/internal/services/springcloud/parse/spring_cloud_certificate_test.go +++ b/internal/services/springcloud/parse/spring_cloud_certificate_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudCertificateId{} func TestSpringCloudCertificateIDFormatter(t *testing.T) { actual := NewSpringCloudCertificateID("12345678-1234-9876-4563-123456789012", "resGroup1", "spring1", "cert1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/certificates/cert1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/certificates/cert1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,25 +63,25 @@ func TestSpringCloudCertificateID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing CertificateName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", Error: true, }, { // missing value for CertificateName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/certificates/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/certificates/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/certificates/cert1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/certificates/cert1", Expected: &SpringCloudCertificateId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resGroup1", @@ -126,3 +126,139 @@ func TestSpringCloudCertificateID(t *testing.T) { } } } + +func TestSpringCloudCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudCertificateId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing CertificateName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", + Error: true, + }, + + { + // missing value for CertificateName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/certificates/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/certificates/cert1", + Expected: &SpringCloudCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + CertificateName: "cert1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/certificates/cert1", + Expected: &SpringCloudCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + CertificateName: "cert1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SPRING/spring1/CERTIFICATES/cert1", + Expected: &SpringCloudCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + CertificateName: "cert1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SpRiNg/spring1/CeRtIfIcAtEs/cert1", + Expected: &SpringCloudCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + CertificateName: "cert1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudCertificateIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_configuration_service.go b/internal/services/springcloud/parse/spring_cloud_configuration_service.go index 07c81febb594..727830a40988 100644 --- a/internal/services/springcloud/parse/spring_cloud_configuration_service.go +++ b/internal/services/springcloud/parse/spring_cloud_configuration_service.go @@ -36,7 +36,7 @@ func (id SpringCloudConfigurationServiceId) String() string { } func (id SpringCloudConfigurationServiceId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/configurationServices/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/configurationServices/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.ConfigurationServiceName) } @@ -60,7 +60,7 @@ func SpringCloudConfigurationServiceID(input string) (*SpringCloudConfigurationS return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.ConfigurationServiceName, err = id.PopSegment("configurationServices"); err != nil { @@ -73,3 +73,59 @@ func SpringCloudConfigurationServiceID(input string) (*SpringCloudConfigurationS return &resourceId, nil } + +// SpringCloudConfigurationServiceIDInsensitively parses an SpringCloudConfigurationService ID into an SpringCloudConfigurationServiceId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudConfigurationServiceID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudConfigurationServiceIDInsensitively(input string) (*SpringCloudConfigurationServiceId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudConfigurationServiceId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'configurationServices' segment + configurationServicesKey := "configurationServices" + for key := range id.Path { + if strings.EqualFold(key, configurationServicesKey) { + configurationServicesKey = key + break + } + } + if resourceId.ConfigurationServiceName, err = id.PopSegment(configurationServicesKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_configuration_service_test.go b/internal/services/springcloud/parse/spring_cloud_configuration_service_test.go index 1fe17f3fdda5..09429f137f91 100644 --- a/internal/services/springcloud/parse/spring_cloud_configuration_service_test.go +++ b/internal/services/springcloud/parse/spring_cloud_configuration_service_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudConfigurationServiceId{} func TestSpringCloudConfigurationServiceIDFormatter(t *testing.T) { actual := NewSpringCloudConfigurationServiceID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "service1", "configurationService1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/configurationServices/configurationService1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/configurationServices/configurationService1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,25 +63,25 @@ func TestSpringCloudConfigurationServiceID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing ConfigurationServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Error: true, }, { // missing value for ConfigurationServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/configurationServices/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/configurationServices/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/configurationServices/configurationService1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/configurationServices/configurationService1", Expected: &SpringCloudConfigurationServiceId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resourceGroup1", @@ -126,3 +126,139 @@ func TestSpringCloudConfigurationServiceID(t *testing.T) { } } } + +func TestSpringCloudConfigurationServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudConfigurationServiceId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing ConfigurationServiceName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", + Error: true, + }, + + { + // missing value for ConfigurationServiceName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/configurationServices/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/configurationServices/configurationService1", + Expected: &SpringCloudConfigurationServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + ConfigurationServiceName: "configurationService1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/configurationservices/configurationService1", + Expected: &SpringCloudConfigurationServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + ConfigurationServiceName: "configurationService1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SPRING/service1/CONFIGURATIONSERVICES/configurationService1", + Expected: &SpringCloudConfigurationServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + ConfigurationServiceName: "configurationService1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SpRiNg/service1/CoNfIgUrAtIoNsErViCeS/configurationService1", + Expected: &SpringCloudConfigurationServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + ConfigurationServiceName: "configurationService1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudConfigurationServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.ConfigurationServiceName != v.Expected.ConfigurationServiceName { + t.Fatalf("Expected %q but got %q for ConfigurationServiceName", v.Expected.ConfigurationServiceName, actual.ConfigurationServiceName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_custom_domain.go b/internal/services/springcloud/parse/spring_cloud_custom_domain.go index 5eef1661eb87..abc4514957fe 100644 --- a/internal/services/springcloud/parse/spring_cloud_custom_domain.go +++ b/internal/services/springcloud/parse/spring_cloud_custom_domain.go @@ -39,7 +39,7 @@ func (id SpringCloudCustomDomainId) String() string { } func (id SpringCloudCustomDomainId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/apps/%s/domains/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/apps/%s/domains/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.AppName, id.DomainName) } @@ -63,7 +63,7 @@ func SpringCloudCustomDomainID(input string) (*SpringCloudCustomDomainId, error) return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.AppName, err = id.PopSegment("apps"); err != nil { @@ -79,3 +79,71 @@ func SpringCloudCustomDomainID(input string) (*SpringCloudCustomDomainId, error) return &resourceId, nil } + +// SpringCloudCustomDomainIDInsensitively parses an SpringCloudCustomDomain ID into an SpringCloudCustomDomainId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudCustomDomainID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudCustomDomainIDInsensitively(input string) (*SpringCloudCustomDomainId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudCustomDomainId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'apps' segment + appsKey := "apps" + for key := range id.Path { + if strings.EqualFold(key, appsKey) { + appsKey = key + break + } + } + if resourceId.AppName, err = id.PopSegment(appsKey); err != nil { + return nil, err + } + + // find the correct casing for the 'domains' segment + domainsKey := "domains" + for key := range id.Path { + if strings.EqualFold(key, domainsKey) { + domainsKey = key + break + } + } + if resourceId.DomainName, err = id.PopSegment(domainsKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_custom_domain_test.go b/internal/services/springcloud/parse/spring_cloud_custom_domain_test.go index e9a8c09e6626..541e736abab1 100644 --- a/internal/services/springcloud/parse/spring_cloud_custom_domain_test.go +++ b/internal/services/springcloud/parse/spring_cloud_custom_domain_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudCustomDomainId{} func TestSpringCloudCustomDomainIDFormatter(t *testing.T) { actual := NewSpringCloudCustomDomainID("12345678-1234-9876-4563-123456789012", "resGroup1", "spring1", "app1", "domain.com").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/domains/domain.com" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/domains/domain.com" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,37 +63,37 @@ func TestSpringCloudCustomDomainID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", Error: true, }, { // missing value for AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/", Error: true, }, { // missing DomainName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/", Error: true, }, { // missing value for DomainName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/domains/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/domains/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/domains/domain.com", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/domains/domain.com", Expected: &SpringCloudCustomDomainId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resGroup1", @@ -142,3 +142,158 @@ func TestSpringCloudCustomDomainID(t *testing.T) { } } } + +func TestSpringCloudCustomDomainIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudCustomDomainId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing AppName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", + Error: true, + }, + + { + // missing value for AppName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/", + Error: true, + }, + + { + // missing DomainName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/", + Error: true, + }, + + { + // missing value for DomainName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/domains/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/domains/domain.com", + Expected: &SpringCloudCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + DomainName: "domain.com", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/domains/domain.com", + Expected: &SpringCloudCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + DomainName: "domain.com", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SPRING/spring1/APPS/app1/DOMAINS/domain.com", + Expected: &SpringCloudCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + DomainName: "domain.com", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SpRiNg/spring1/ApPs/app1/DoMaInS/domain.com", + Expected: &SpringCloudCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + DomainName: "domain.com", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudCustomDomainIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.AppName != v.Expected.AppName { + t.Fatalf("Expected %q but got %q for AppName", v.Expected.AppName, actual.AppName) + } + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_deployment.go b/internal/services/springcloud/parse/spring_cloud_deployment.go index 11507d57a841..8bae66a4bdb3 100644 --- a/internal/services/springcloud/parse/spring_cloud_deployment.go +++ b/internal/services/springcloud/parse/spring_cloud_deployment.go @@ -39,7 +39,7 @@ func (id SpringCloudDeploymentId) String() string { } func (id SpringCloudDeploymentId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/apps/%s/deployments/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/apps/%s/deployments/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.AppName, id.DeploymentName) } @@ -63,7 +63,7 @@ func SpringCloudDeploymentID(input string) (*SpringCloudDeploymentId, error) { return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.AppName, err = id.PopSegment("apps"); err != nil { @@ -79,3 +79,71 @@ func SpringCloudDeploymentID(input string) (*SpringCloudDeploymentId, error) { return &resourceId, nil } + +// SpringCloudDeploymentIDInsensitively parses an SpringCloudDeployment ID into an SpringCloudDeploymentId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudDeploymentID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudDeploymentIDInsensitively(input string) (*SpringCloudDeploymentId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudDeploymentId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'apps' segment + appsKey := "apps" + for key := range id.Path { + if strings.EqualFold(key, appsKey) { + appsKey = key + break + } + } + if resourceId.AppName, err = id.PopSegment(appsKey); err != nil { + return nil, err + } + + // find the correct casing for the 'deployments' segment + deploymentsKey := "deployments" + for key := range id.Path { + if strings.EqualFold(key, deploymentsKey) { + deploymentsKey = key + break + } + } + if resourceId.DeploymentName, err = id.PopSegment(deploymentsKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_deployment_test.go b/internal/services/springcloud/parse/spring_cloud_deployment_test.go index 4d2ada9be9de..93442cac89a7 100644 --- a/internal/services/springcloud/parse/spring_cloud_deployment_test.go +++ b/internal/services/springcloud/parse/spring_cloud_deployment_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudDeploymentId{} func TestSpringCloudDeploymentIDFormatter(t *testing.T) { actual := NewSpringCloudDeploymentID("12345678-1234-9876-4563-123456789012", "resGroup1", "spring1", "app1", "deploy1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/deployments/deploy1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/deployments/deploy1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,37 +63,37 @@ func TestSpringCloudDeploymentID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", Error: true, }, { // missing value for AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/", Error: true, }, { // missing DeploymentName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/", Error: true, }, { // missing value for DeploymentName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/deployments/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/deployments/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/deployments/deploy1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/deployments/deploy1", Expected: &SpringCloudDeploymentId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resGroup1", @@ -142,3 +142,158 @@ func TestSpringCloudDeploymentID(t *testing.T) { } } } + +func TestSpringCloudDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudDeploymentId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing AppName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", + Error: true, + }, + + { + // missing value for AppName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/", + Error: true, + }, + + { + // missing DeploymentName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/", + Error: true, + }, + + { + // missing value for DeploymentName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/deployments/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/deployments/deploy1", + Expected: &SpringCloudDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + DeploymentName: "deploy1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/deployments/deploy1", + Expected: &SpringCloudDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + DeploymentName: "deploy1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SPRING/spring1/APPS/app1/DEPLOYMENTS/deploy1", + Expected: &SpringCloudDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + DeploymentName: "deploy1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SpRiNg/spring1/ApPs/app1/DePlOyMeNtS/deploy1", + Expected: &SpringCloudDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + AppName: "app1", + DeploymentName: "deploy1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudDeploymentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.AppName != v.Expected.AppName { + t.Fatalf("Expected %q but got %q for AppName", v.Expected.AppName, actual.AppName) + } + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_gateway.go b/internal/services/springcloud/parse/spring_cloud_gateway.go index 38c77c8dd3e9..366d0d3cab0d 100644 --- a/internal/services/springcloud/parse/spring_cloud_gateway.go +++ b/internal/services/springcloud/parse/spring_cloud_gateway.go @@ -36,7 +36,7 @@ func (id SpringCloudGatewayId) String() string { } func (id SpringCloudGatewayId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/gateways/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/gateways/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.GatewayName) } @@ -60,7 +60,7 @@ func SpringCloudGatewayID(input string) (*SpringCloudGatewayId, error) { return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.GatewayName, err = id.PopSegment("gateways"); err != nil { @@ -73,3 +73,59 @@ func SpringCloudGatewayID(input string) (*SpringCloudGatewayId, error) { return &resourceId, nil } + +// SpringCloudGatewayIDInsensitively parses an SpringCloudGateway ID into an SpringCloudGatewayId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudGatewayID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudGatewayIDInsensitively(input string) (*SpringCloudGatewayId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudGatewayId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'gateways' segment + gatewaysKey := "gateways" + for key := range id.Path { + if strings.EqualFold(key, gatewaysKey) { + gatewaysKey = key + break + } + } + if resourceId.GatewayName, err = id.PopSegment(gatewaysKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_gateway_custom_domain.go b/internal/services/springcloud/parse/spring_cloud_gateway_custom_domain.go index 352a4215793f..c48dce89ef7a 100644 --- a/internal/services/springcloud/parse/spring_cloud_gateway_custom_domain.go +++ b/internal/services/springcloud/parse/spring_cloud_gateway_custom_domain.go @@ -39,7 +39,7 @@ func (id SpringCloudGatewayCustomDomainId) String() string { } func (id SpringCloudGatewayCustomDomainId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/gateways/%s/domains/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/gateways/%s/domains/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.GatewayName, id.DomainName) } @@ -63,7 +63,7 @@ func SpringCloudGatewayCustomDomainID(input string) (*SpringCloudGatewayCustomDo return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.GatewayName, err = id.PopSegment("gateways"); err != nil { @@ -79,3 +79,71 @@ func SpringCloudGatewayCustomDomainID(input string) (*SpringCloudGatewayCustomDo return &resourceId, nil } + +// SpringCloudGatewayCustomDomainIDInsensitively parses an SpringCloudGatewayCustomDomain ID into an SpringCloudGatewayCustomDomainId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudGatewayCustomDomainID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudGatewayCustomDomainIDInsensitively(input string) (*SpringCloudGatewayCustomDomainId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudGatewayCustomDomainId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'gateways' segment + gatewaysKey := "gateways" + for key := range id.Path { + if strings.EqualFold(key, gatewaysKey) { + gatewaysKey = key + break + } + } + if resourceId.GatewayName, err = id.PopSegment(gatewaysKey); err != nil { + return nil, err + } + + // find the correct casing for the 'domains' segment + domainsKey := "domains" + for key := range id.Path { + if strings.EqualFold(key, domainsKey) { + domainsKey = key + break + } + } + if resourceId.DomainName, err = id.PopSegment(domainsKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_gateway_custom_domain_test.go b/internal/services/springcloud/parse/spring_cloud_gateway_custom_domain_test.go index e88d888635ab..bea53c9df47e 100644 --- a/internal/services/springcloud/parse/spring_cloud_gateway_custom_domain_test.go +++ b/internal/services/springcloud/parse/spring_cloud_gateway_custom_domain_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudGatewayCustomDomainId{} func TestSpringCloudGatewayCustomDomainIDFormatter(t *testing.T) { actual := NewSpringCloudGatewayCustomDomainID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "service1", "gateway1", "domain1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/domains/domain1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/domains/domain1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,37 +63,37 @@ func TestSpringCloudGatewayCustomDomainID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing GatewayName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Error: true, }, { // missing value for GatewayName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/", Error: true, }, { // missing DomainName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/", Error: true, }, { // missing value for DomainName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/domains/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/domains/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/domains/domain1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/domains/domain1", Expected: &SpringCloudGatewayCustomDomainId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resourceGroup1", @@ -142,3 +142,158 @@ func TestSpringCloudGatewayCustomDomainID(t *testing.T) { } } } + +func TestSpringCloudGatewayCustomDomainIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudGatewayCustomDomainId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing GatewayName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", + Error: true, + }, + + { + // missing value for GatewayName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/", + Error: true, + }, + + { + // missing DomainName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/", + Error: true, + }, + + { + // missing value for DomainName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/domains/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/domains/domain1", + Expected: &SpringCloudGatewayCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + GatewayName: "gateway1", + DomainName: "domain1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/domains/domain1", + Expected: &SpringCloudGatewayCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + GatewayName: "gateway1", + DomainName: "domain1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SPRING/service1/GATEWAYS/gateway1/DOMAINS/domain1", + Expected: &SpringCloudGatewayCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + GatewayName: "gateway1", + DomainName: "domain1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SpRiNg/service1/GaTeWaYs/gateway1/DoMaInS/domain1", + Expected: &SpringCloudGatewayCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + GatewayName: "gateway1", + DomainName: "domain1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudGatewayCustomDomainIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_gateway_route_config.go b/internal/services/springcloud/parse/spring_cloud_gateway_route_config.go index 100c62df159c..77b390c8949a 100644 --- a/internal/services/springcloud/parse/spring_cloud_gateway_route_config.go +++ b/internal/services/springcloud/parse/spring_cloud_gateway_route_config.go @@ -39,7 +39,7 @@ func (id SpringCloudGatewayRouteConfigId) String() string { } func (id SpringCloudGatewayRouteConfigId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/gateways/%s/routeConfigs/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/gateways/%s/routeConfigs/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.GatewayName, id.RouteConfigName) } @@ -63,7 +63,7 @@ func SpringCloudGatewayRouteConfigID(input string) (*SpringCloudGatewayRouteConf return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.GatewayName, err = id.PopSegment("gateways"); err != nil { @@ -79,3 +79,71 @@ func SpringCloudGatewayRouteConfigID(input string) (*SpringCloudGatewayRouteConf return &resourceId, nil } + +// SpringCloudGatewayRouteConfigIDInsensitively parses an SpringCloudGatewayRouteConfig ID into an SpringCloudGatewayRouteConfigId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudGatewayRouteConfigID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudGatewayRouteConfigIDInsensitively(input string) (*SpringCloudGatewayRouteConfigId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudGatewayRouteConfigId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'gateways' segment + gatewaysKey := "gateways" + for key := range id.Path { + if strings.EqualFold(key, gatewaysKey) { + gatewaysKey = key + break + } + } + if resourceId.GatewayName, err = id.PopSegment(gatewaysKey); err != nil { + return nil, err + } + + // find the correct casing for the 'routeConfigs' segment + routeConfigsKey := "routeConfigs" + for key := range id.Path { + if strings.EqualFold(key, routeConfigsKey) { + routeConfigsKey = key + break + } + } + if resourceId.RouteConfigName, err = id.PopSegment(routeConfigsKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_gateway_route_config_test.go b/internal/services/springcloud/parse/spring_cloud_gateway_route_config_test.go index 975b6525a398..1980f55593cb 100644 --- a/internal/services/springcloud/parse/spring_cloud_gateway_route_config_test.go +++ b/internal/services/springcloud/parse/spring_cloud_gateway_route_config_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudGatewayRouteConfigId{} func TestSpringCloudGatewayRouteConfigIDFormatter(t *testing.T) { actual := NewSpringCloudGatewayRouteConfigID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "service1", "gateway1", "routeConfig1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/routeConfigs/routeConfig1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/routeConfigs/routeConfig1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,37 +63,37 @@ func TestSpringCloudGatewayRouteConfigID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing GatewayName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Error: true, }, { // missing value for GatewayName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/", Error: true, }, { // missing RouteConfigName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/", Error: true, }, { // missing value for RouteConfigName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/routeConfigs/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/routeConfigs/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/routeConfigs/routeConfig1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/routeConfigs/routeConfig1", Expected: &SpringCloudGatewayRouteConfigId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resourceGroup1", @@ -142,3 +142,158 @@ func TestSpringCloudGatewayRouteConfigID(t *testing.T) { } } } + +func TestSpringCloudGatewayRouteConfigIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudGatewayRouteConfigId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing GatewayName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", + Error: true, + }, + + { + // missing value for GatewayName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/", + Error: true, + }, + + { + // missing RouteConfigName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/", + Error: true, + }, + + { + // missing value for RouteConfigName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/routeConfigs/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/routeConfigs/routeConfig1", + Expected: &SpringCloudGatewayRouteConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + GatewayName: "gateway1", + RouteConfigName: "routeConfig1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/routeconfigs/routeConfig1", + Expected: &SpringCloudGatewayRouteConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + GatewayName: "gateway1", + RouteConfigName: "routeConfig1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SPRING/service1/GATEWAYS/gateway1/ROUTECONFIGS/routeConfig1", + Expected: &SpringCloudGatewayRouteConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + GatewayName: "gateway1", + RouteConfigName: "routeConfig1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SpRiNg/service1/GaTeWaYs/gateway1/RoUtEcOnFiGs/routeConfig1", + Expected: &SpringCloudGatewayRouteConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + GatewayName: "gateway1", + RouteConfigName: "routeConfig1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudGatewayRouteConfigIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + if actual.RouteConfigName != v.Expected.RouteConfigName { + t.Fatalf("Expected %q but got %q for RouteConfigName", v.Expected.RouteConfigName, actual.RouteConfigName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_gateway_test.go b/internal/services/springcloud/parse/spring_cloud_gateway_test.go index 9d13b56e5b45..a61d36e65eb6 100644 --- a/internal/services/springcloud/parse/spring_cloud_gateway_test.go +++ b/internal/services/springcloud/parse/spring_cloud_gateway_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudGatewayId{} func TestSpringCloudGatewayIDFormatter(t *testing.T) { actual := NewSpringCloudGatewayID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "service1", "gateway1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,25 +63,25 @@ func TestSpringCloudGatewayID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing GatewayName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Error: true, }, { // missing value for GatewayName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1", Expected: &SpringCloudGatewayId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resourceGroup1", @@ -126,3 +126,139 @@ func TestSpringCloudGatewayID(t *testing.T) { } } } + +func TestSpringCloudGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudGatewayId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing GatewayName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", + Error: true, + }, + + { + // missing value for GatewayName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1", + Expected: &SpringCloudGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + GatewayName: "gateway1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1", + Expected: &SpringCloudGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + GatewayName: "gateway1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SPRING/service1/GATEWAYS/gateway1", + Expected: &SpringCloudGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + GatewayName: "gateway1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SpRiNg/service1/GaTeWaYs/gateway1", + Expected: &SpringCloudGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + GatewayName: "gateway1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_service.go b/internal/services/springcloud/parse/spring_cloud_service.go index 1cbcd938b9e2..440cf976e6d5 100644 --- a/internal/services/springcloud/parse/spring_cloud_service.go +++ b/internal/services/springcloud/parse/spring_cloud_service.go @@ -33,7 +33,7 @@ func (id SpringCloudServiceId) String() string { } func (id SpringCloudServiceId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName) } @@ -57,7 +57,51 @@ func SpringCloudServiceID(input string) (*SpringCloudServiceId, error) { return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} + +// SpringCloudServiceIDInsensitively parses an SpringCloudService ID into an SpringCloudServiceId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudServiceID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudServiceIDInsensitively(input string) (*SpringCloudServiceId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudServiceId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { return nil, err } diff --git a/internal/services/springcloud/parse/spring_cloud_service_registry.go b/internal/services/springcloud/parse/spring_cloud_service_registry.go index fc4b04f99607..c7ee0ea03086 100644 --- a/internal/services/springcloud/parse/spring_cloud_service_registry.go +++ b/internal/services/springcloud/parse/spring_cloud_service_registry.go @@ -36,7 +36,7 @@ func (id SpringCloudServiceRegistryId) String() string { } func (id SpringCloudServiceRegistryId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/serviceRegistries/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/serviceRegistries/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.ServiceRegistryName) } @@ -60,7 +60,7 @@ func SpringCloudServiceRegistryID(input string) (*SpringCloudServiceRegistryId, return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.ServiceRegistryName, err = id.PopSegment("serviceRegistries"); err != nil { @@ -73,3 +73,59 @@ func SpringCloudServiceRegistryID(input string) (*SpringCloudServiceRegistryId, return &resourceId, nil } + +// SpringCloudServiceRegistryIDInsensitively parses an SpringCloudServiceRegistry ID into an SpringCloudServiceRegistryId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudServiceRegistryID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudServiceRegistryIDInsensitively(input string) (*SpringCloudServiceRegistryId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudServiceRegistryId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'serviceRegistries' segment + serviceRegistriesKey := "serviceRegistries" + for key := range id.Path { + if strings.EqualFold(key, serviceRegistriesKey) { + serviceRegistriesKey = key + break + } + } + if resourceId.ServiceRegistryName, err = id.PopSegment(serviceRegistriesKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_service_registry_test.go b/internal/services/springcloud/parse/spring_cloud_service_registry_test.go index eba2bd2d04e3..d24bc07cba90 100644 --- a/internal/services/springcloud/parse/spring_cloud_service_registry_test.go +++ b/internal/services/springcloud/parse/spring_cloud_service_registry_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudServiceRegistryId{} func TestSpringCloudServiceRegistryIDFormatter(t *testing.T) { actual := NewSpringCloudServiceRegistryID("12345678-1234-9876-4563-123456789012", "resGroup1", "spring1", "serviceRegistry1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/serviceRegistries/serviceRegistry1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/serviceRegistries/serviceRegistry1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,25 +63,25 @@ func TestSpringCloudServiceRegistryID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing ServiceRegistryName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", Error: true, }, { // missing value for ServiceRegistryName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/serviceRegistries/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/serviceRegistries/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/serviceRegistries/serviceRegistry1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/serviceRegistries/serviceRegistry1", Expected: &SpringCloudServiceRegistryId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resGroup1", @@ -126,3 +126,139 @@ func TestSpringCloudServiceRegistryID(t *testing.T) { } } } + +func TestSpringCloudServiceRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudServiceRegistryId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing ServiceRegistryName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", + Error: true, + }, + + { + // missing value for ServiceRegistryName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/serviceRegistries/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/serviceRegistries/serviceRegistry1", + Expected: &SpringCloudServiceRegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + ServiceRegistryName: "serviceRegistry1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/serviceregistries/serviceRegistry1", + Expected: &SpringCloudServiceRegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + ServiceRegistryName: "serviceRegistry1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SPRING/spring1/SERVICEREGISTRIES/serviceRegistry1", + Expected: &SpringCloudServiceRegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + ServiceRegistryName: "serviceRegistry1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SpRiNg/spring1/SeRvIcErEgIsTrIeS/serviceRegistry1", + Expected: &SpringCloudServiceRegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + ServiceRegistryName: "serviceRegistry1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudServiceRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.ServiceRegistryName != v.Expected.ServiceRegistryName { + t.Fatalf("Expected %q but got %q for ServiceRegistryName", v.Expected.ServiceRegistryName, actual.ServiceRegistryName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_service_test.go b/internal/services/springcloud/parse/spring_cloud_service_test.go index caeb71072550..9384009653fa 100644 --- a/internal/services/springcloud/parse/spring_cloud_service_test.go +++ b/internal/services/springcloud/parse/spring_cloud_service_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudServiceId{} func TestSpringCloudServiceIDFormatter(t *testing.T) { actual := NewSpringCloudServiceID("12345678-1234-9876-4563-123456789012", "resGroup1", "spring1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,13 +63,13 @@ func TestSpringCloudServiceID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1", Expected: &SpringCloudServiceId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resGroup1", @@ -110,3 +110,120 @@ func TestSpringCloudServiceID(t *testing.T) { } } } + +func TestSpringCloudServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudServiceId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1", + Expected: &SpringCloudServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1", + Expected: &SpringCloudServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SPRING/spring1", + Expected: &SpringCloudServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/SpRiNg/spring1", + Expected: &SpringCloudServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + SpringName: "spring1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + } +} diff --git a/internal/services/springcloud/parse/spring_cloud_storage.go b/internal/services/springcloud/parse/spring_cloud_storage.go index e6892f06557c..a1aa10ce6ed0 100644 --- a/internal/services/springcloud/parse/spring_cloud_storage.go +++ b/internal/services/springcloud/parse/spring_cloud_storage.go @@ -36,7 +36,7 @@ func (id SpringCloudStorageId) String() string { } func (id SpringCloudStorageId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/Spring/%s/storages/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AppPlatform/spring/%s/storages/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.SpringName, id.StorageName) } @@ -60,7 +60,7 @@ func SpringCloudStorageID(input string) (*SpringCloudStorageId, error) { return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } - if resourceId.SpringName, err = id.PopSegment("Spring"); err != nil { + if resourceId.SpringName, err = id.PopSegment("spring"); err != nil { return nil, err } if resourceId.StorageName, err = id.PopSegment("storages"); err != nil { @@ -73,3 +73,59 @@ func SpringCloudStorageID(input string) (*SpringCloudStorageId, error) { return &resourceId, nil } + +// SpringCloudStorageIDInsensitively parses an SpringCloudStorage ID into an SpringCloudStorageId struct, insensitively +// This should only be used to parse an ID for rewriting, the SpringCloudStorageID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SpringCloudStorageIDInsensitively(input string) (*SpringCloudStorageId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SpringCloudStorageId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + // find the correct casing for the 'spring' segment + springKey := "spring" + for key := range id.Path { + if strings.EqualFold(key, springKey) { + springKey = key + break + } + } + if resourceId.SpringName, err = id.PopSegment(springKey); err != nil { + return nil, err + } + + // find the correct casing for the 'storages' segment + storagesKey := "storages" + for key := range id.Path { + if strings.EqualFold(key, storagesKey) { + storagesKey = key + break + } + } + if resourceId.StorageName, err = id.PopSegment(storagesKey); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/springcloud/parse/spring_cloud_storage_test.go b/internal/services/springcloud/parse/spring_cloud_storage_test.go index 5e4881a0e47a..e1f65549a995 100644 --- a/internal/services/springcloud/parse/spring_cloud_storage_test.go +++ b/internal/services/springcloud/parse/spring_cloud_storage_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SpringCloudStorageId{} func TestSpringCloudStorageIDFormatter(t *testing.T) { actual := NewSpringCloudStorageID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "service1", "storage1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/storages/storage1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/storages/storage1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -63,25 +63,25 @@ func TestSpringCloudStorageID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Error: true, }, { // missing StorageName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Error: true, }, { // missing value for StorageName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/storages/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/storages/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/storages/storage1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/storages/storage1", Expected: &SpringCloudStorageId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resourceGroup1", @@ -126,3 +126,139 @@ func TestSpringCloudStorageID(t *testing.T) { } } } + +func TestSpringCloudStorageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpringCloudStorageId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/", + Error: true, + }, + + { + // missing value for SpringName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", + Error: true, + }, + + { + // missing StorageName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", + Error: true, + }, + + { + // missing value for StorageName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/storages/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/storages/storage1", + Expected: &SpringCloudStorageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + StorageName: "storage1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/storages/storage1", + Expected: &SpringCloudStorageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + StorageName: "storage1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SPRING/service1/STORAGES/storage1", + Expected: &SpringCloudStorageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + StorageName: "storage1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/SpRiNg/service1/StOrAgEs/storage1", + Expected: &SpringCloudStorageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + SpringName: "service1", + StorageName: "storage1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SpringCloudStorageIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.SpringName != v.Expected.SpringName { + t.Fatalf("Expected %q but got %q for SpringName", v.Expected.SpringName, actual.SpringName) + } + if actual.StorageName != v.Expected.StorageName { + t.Fatalf("Expected %q but got %q for StorageName", v.Expected.StorageName, actual.StorageName) + } + } +} diff --git a/internal/services/springcloud/resourceids.go b/internal/services/springcloud/resourceids.go index c887b6fa5295..a05c90454a48 100644 --- a/internal/services/springcloud/resourceids.go +++ b/internal/services/springcloud/resourceids.go @@ -1,19 +1,19 @@ package springcloud -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudApp -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudAppAssociation -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/bindings/bind1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudAPIPortal -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudAPIPortalCustomDomain -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1/domains/domain1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudApplicationLiveView -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/applicationLiveViews/default -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudBuildServiceBuilder -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudBuildPackBinding -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/buildPackBinding1 -rewrite=true -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudDeployment -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/deployments/deploy1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudCertificate -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/certificates/cert1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudCustomDomain -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/domains/domain.com -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudConfigurationService -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/configurationServices/configurationService1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudGateway -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudGatewayCustomDomain -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/domains/domain1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudGatewayRouteConfig -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/routeConfigs/routeConfig1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudService -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudServiceRegistry -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/serviceRegistries/serviceRegistry1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudStorage -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/storages/storage1 +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudApp -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudAppAssociation -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/bindings/bind1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudAPIPortal -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudAPIPortalCustomDomain -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1/domains/domain1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudApplicationLiveView -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/applicationLiveViews/default +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudBuildServiceBuilder -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudBuildPackBinding -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/buildPackBinding1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudDeployment -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/deployments/deploy1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudCertificate -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/certificates/cert1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudCustomDomain -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/domains/domain.com -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudConfigurationService -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/configurationServices/configurationService1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudGateway -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudGatewayCustomDomain -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/domains/domain1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudGatewayRouteConfig -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/routeConfigs/routeConfig1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudService -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudServiceRegistry -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/serviceRegistries/serviceRegistry1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SpringCloudStorage -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/storages/storage1 -rewrite=true diff --git a/internal/services/springcloud/spring_cloud_active_deployment_resource.go b/internal/services/springcloud/spring_cloud_active_deployment_resource.go index 932c8b872821..f7618dff6d65 100644 --- a/internal/services/springcloud/spring_cloud_active_deployment_resource.go +++ b/internal/services/springcloud/spring_cloud_active_deployment_resource.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -22,6 +23,11 @@ func resourceSpringCloudActiveDeployment() *pluginsdk.Resource { Update: resourceSpringCloudActiveDeploymentUpdate, Delete: resourceSpringCloudActiveDeploymentDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudActiveDeploymentV0ToV1{}, + }), + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.SpringCloudAppID(id) return err diff --git a/internal/services/springcloud/spring_cloud_api_portal_custom_domain_resource.go b/internal/services/springcloud/spring_cloud_api_portal_custom_domain_resource.go index 3731469b738b..a4e4d4f1c186 100644 --- a/internal/services/springcloud/spring_cloud_api_portal_custom_domain_resource.go +++ b/internal/services/springcloud/spring_cloud_api_portal_custom_domain_resource.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -22,6 +23,11 @@ func resourceSpringCloudAPIPortalCustomDomain() *pluginsdk.Resource { Update: resourceSpringCloudAPIPortalCustomDomainCreateUpdate, Delete: resourceSpringCloudAPIPortalCustomDomainDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudApiPortalCustomDomainV0ToV1{}, + }), + Timeouts: &pluginsdk.ResourceTimeout{ Create: pluginsdk.DefaultTimeout(30 * time.Minute), Read: pluginsdk.DefaultTimeout(5 * time.Minute), diff --git a/internal/services/springcloud/spring_cloud_api_portal_resource.go b/internal/services/springcloud/spring_cloud_api_portal_resource.go index ffc9ac52fe47..c34edf175b3f 100644 --- a/internal/services/springcloud/spring_cloud_api_portal_resource.go +++ b/internal/services/springcloud/spring_cloud_api_portal_resource.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -23,6 +24,11 @@ func resourceSpringCloudAPIPortal() *pluginsdk.Resource { Update: resourceSpringCloudAPIPortalCreateUpdate, Delete: resourceSpringCloudAPIPortalDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudApiPortalV0ToV1{}, + }), + Timeouts: &pluginsdk.ResourceTimeout{ Create: pluginsdk.DefaultTimeout(60 * time.Minute), Read: pluginsdk.DefaultTimeout(5 * time.Minute), diff --git a/internal/services/springcloud/spring_cloud_app_cosmosdb_association_resource.go b/internal/services/springcloud/spring_cloud_app_cosmosdb_association_resource.go index 311c153d6570..16f797439581 100644 --- a/internal/services/springcloud/spring_cloud_app_cosmosdb_association_resource.go +++ b/internal/services/springcloud/spring_cloud_app_cosmosdb_association_resource.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" cosmosValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -37,6 +38,11 @@ func resourceSpringCloudAppCosmosDBAssociation() *pluginsdk.Resource { Update: resourceSpringCloudAppCosmosDBAssociationCreateUpdate, Delete: resourceSpringCloudAppCosmosDBAssociationDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudAppCosmosDbAssociationV0ToV1{}, + }), + Importer: pluginsdk.ImporterValidatingResourceIdThen(func(id string) error { _, err := parse.SpringCloudAppAssociationID(id) return err diff --git a/internal/services/springcloud/spring_cloud_app_mysql_association_resource.go b/internal/services/springcloud/spring_cloud_app_mysql_association_resource.go index 8ee66c05b1c0..e3621920f733 100644 --- a/internal/services/springcloud/spring_cloud_app_mysql_association_resource.go +++ b/internal/services/springcloud/spring_cloud_app_mysql_association_resource.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" mysqlValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/mysql/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -29,6 +30,11 @@ func resourceSpringCloudAppMysqlAssociation() *pluginsdk.Resource { Update: resourceSpringCloudAppMysqlAssociationCreateUpdate, Delete: resourceSpringCloudAppMysqlAssociationDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudAppMySqlAssociationV0ToV1{}, + }), + Importer: pluginsdk.ImporterValidatingResourceIdThen(func(id string) error { _, err := parse.SpringCloudAppAssociationID(id) return err diff --git a/internal/services/springcloud/spring_cloud_app_redis_association_resource.go b/internal/services/springcloud/spring_cloud_app_redis_association_resource.go index 3fe50be8f78f..0b9ec905fc60 100644 --- a/internal/services/springcloud/spring_cloud_app_redis_association_resource.go +++ b/internal/services/springcloud/spring_cloud_app_redis_association_resource.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" redisValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/redis/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -27,6 +28,11 @@ func resourceSpringCloudAppRedisAssociation() *pluginsdk.Resource { Update: resourceSpringCloudAppRedisAssociationCreateUpdate, Delete: resourceSpringCloudAppRedisAssociationDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudAppRedisAssociationV0ToV1{}, + }), + Importer: pluginsdk.ImporterValidatingResourceIdThen(func(id string) error { _, err := parse.SpringCloudAppAssociationID(id) return err diff --git a/internal/services/springcloud/spring_cloud_app_resource.go b/internal/services/springcloud/spring_cloud_app_resource.go index 7ae0726e54b6..50083073a1eb 100644 --- a/internal/services/springcloud/spring_cloud_app_resource.go +++ b/internal/services/springcloud/spring_cloud_app_resource.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -28,6 +29,11 @@ func resourceSpringCloudApp() *pluginsdk.Resource { Update: resourceSpringCloudAppUpdate, Delete: resourceSpringCloudAppDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudAppV0ToV1{}, + }), + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.SpringCloudAppID(id) return err diff --git a/internal/services/springcloud/spring_cloud_build_deployment_resource.go b/internal/services/springcloud/spring_cloud_build_deployment_resource.go index 5ca9b96818c8..be0fdf597fd6 100644 --- a/internal/services/springcloud/spring_cloud_build_deployment_resource.go +++ b/internal/services/springcloud/spring_cloud_build_deployment_resource.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -23,6 +24,11 @@ func resourceSpringCloudBuildDeployment() *pluginsdk.Resource { Update: resourceSpringCloudBuildDeploymentCreateUpdate, Delete: resourceSpringCloudBuildDeploymentDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudBuildDeploymentV0ToV1{}, + }), + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.SpringCloudDeploymentID(id) return err diff --git a/internal/services/springcloud/spring_cloud_builder_resource.go b/internal/services/springcloud/spring_cloud_builder_resource.go index db17ab932a70..ece8873f7590 100644 --- a/internal/services/springcloud/spring_cloud_builder_resource.go +++ b/internal/services/springcloud/spring_cloud_builder_resource.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -30,6 +31,11 @@ func resourceSpringCloudBuildServiceBuilder() *pluginsdk.Resource { Delete: pluginsdk.DefaultTimeout(30 * time.Minute), }, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudBuildServiceBuilderV0ToV1{}, + }), + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.SpringCloudBuildServiceBuilderID(id) return err diff --git a/internal/services/springcloud/spring_cloud_certificate_resource.go b/internal/services/springcloud/spring_cloud_certificate_resource.go index 475eb21a3f53..82691163fa01 100644 --- a/internal/services/springcloud/spring_cloud_certificate_resource.go +++ b/internal/services/springcloud/spring_cloud_certificate_resource.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/clients" keyVaultParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/parse" keyVaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -26,6 +27,11 @@ func resourceSpringCloudCertificate() *pluginsdk.Resource { Read: resourceSpringCloudCertificateRead, Delete: resourceSpringCloudCertificateDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudCertificateV0ToV1{}, + }), + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.SpringCloudCertificateID(id) return err diff --git a/internal/services/springcloud/spring_cloud_configuration_service_resource.go b/internal/services/springcloud/spring_cloud_configuration_service_resource.go index c7a6c683cac9..9855c2ec0c9a 100644 --- a/internal/services/springcloud/spring_cloud_configuration_service_resource.go +++ b/internal/services/springcloud/spring_cloud_configuration_service_resource.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -23,6 +24,11 @@ func resourceSpringCloudConfigurationService() *pluginsdk.Resource { Update: resourceSpringCloudConfigurationServiceCreateUpdate, Delete: resourceSpringCloudConfigurationServiceDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudConfigurationServiceV0ToV1{}, + }), + Timeouts: &pluginsdk.ResourceTimeout{ Create: pluginsdk.DefaultTimeout(30 * time.Minute), Read: pluginsdk.DefaultTimeout(5 * time.Minute), diff --git a/internal/services/springcloud/spring_cloud_container_deployment_resource.go b/internal/services/springcloud/spring_cloud_container_deployment_resource.go index 62578b42129b..a9da9d8a1927 100644 --- a/internal/services/springcloud/spring_cloud_container_deployment_resource.go +++ b/internal/services/springcloud/spring_cloud_container_deployment_resource.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -23,6 +24,11 @@ func resourceSpringCloudContainerDeployment() *pluginsdk.Resource { Update: resourceSpringCloudContainerDeploymentCreateUpdate, Delete: resourceSpringCloudContainerDeploymentDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudContainerDeploymentV0ToV1{}, + }), + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.SpringCloudDeploymentID(id) return err diff --git a/internal/services/springcloud/spring_cloud_custom_domain_resource.go b/internal/services/springcloud/spring_cloud_custom_domain_resource.go index cd403814206f..2e76f6e56608 100644 --- a/internal/services/springcloud/spring_cloud_custom_domain_resource.go +++ b/internal/services/springcloud/spring_cloud_custom_domain_resource.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -23,6 +24,11 @@ func resourceSpringCloudCustomDomain() *pluginsdk.Resource { Update: resourceSpringCloudCustomDomainCreateUpdate, Delete: resourceSpringCloudCustomDomainDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudCustomDomainV0ToV1{}, + }), + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.SpringCloudCustomDomainID(id) return err diff --git a/internal/services/springcloud/spring_cloud_gateway_custom_domain_resource.go b/internal/services/springcloud/spring_cloud_gateway_custom_domain_resource.go index d1786e7b9045..d4d7b65b822a 100644 --- a/internal/services/springcloud/spring_cloud_gateway_custom_domain_resource.go +++ b/internal/services/springcloud/spring_cloud_gateway_custom_domain_resource.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -30,6 +31,11 @@ func resourceSpringCloudGatewayCustomDomain() *pluginsdk.Resource { Delete: pluginsdk.DefaultTimeout(30 * time.Minute), }, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudGatewayCustomDomainV0ToV1{}, + }), + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.SpringCloudGatewayCustomDomainID(id) return err diff --git a/internal/services/springcloud/spring_cloud_gateway_resource.go b/internal/services/springcloud/spring_cloud_gateway_resource.go index ab16340d77d7..bb73d37974f4 100644 --- a/internal/services/springcloud/spring_cloud_gateway_resource.go +++ b/internal/services/springcloud/spring_cloud_gateway_resource.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -23,6 +24,11 @@ func resourceSpringCloudGateway() *pluginsdk.Resource { Update: resourceSpringCloudGatewayCreateUpdate, Delete: resourceSpringCloudGatewayDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudGatewayV0ToV1{}, + }), + Timeouts: &pluginsdk.ResourceTimeout{ Create: pluginsdk.DefaultTimeout(30 * time.Minute), Read: pluginsdk.DefaultTimeout(5 * time.Minute), diff --git a/internal/services/springcloud/spring_cloud_gateway_route_config_resource.go b/internal/services/springcloud/spring_cloud_gateway_route_config_resource.go index e512e3bf4820..30a37a6d9ff8 100644 --- a/internal/services/springcloud/spring_cloud_gateway_route_config_resource.go +++ b/internal/services/springcloud/spring_cloud_gateway_route_config_resource.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/features" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -24,6 +25,11 @@ func resourceSpringCloudGatewayRouteConfig() *pluginsdk.Resource { Update: resourceSpringCloudGatewayRouteConfigCreateUpdate, Delete: resourceSpringCloudGatewayRouteConfigDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudGatewayRouteConfigV0ToV1{}, + }), + Timeouts: &pluginsdk.ResourceTimeout{ Create: pluginsdk.DefaultTimeout(30 * time.Minute), Read: pluginsdk.DefaultTimeout(5 * time.Minute), diff --git a/internal/services/springcloud/spring_cloud_java_deployment_resource.go b/internal/services/springcloud/spring_cloud_java_deployment_resource.go index f9d30ddc0157..403c68cd0020 100644 --- a/internal/services/springcloud/spring_cloud_java_deployment_resource.go +++ b/internal/services/springcloud/spring_cloud_java_deployment_resource.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -24,6 +25,11 @@ func resourceSpringCloudJavaDeployment() *pluginsdk.Resource { Update: resourceSpringCloudJavaDeploymentUpdate, Delete: resourceSpringCloudJavaDeploymentDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudJavaDeploymentV0ToV1{}, + }), + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.SpringCloudDeploymentID(id) return err diff --git a/internal/services/springcloud/spring_cloud_service_resource.go b/internal/services/springcloud/spring_cloud_service_resource.go index 85359915fdf6..c3a7c3565ecc 100644 --- a/internal/services/springcloud/spring_cloud_service_resource.go +++ b/internal/services/springcloud/spring_cloud_service_resource.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" networkValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" @@ -31,6 +32,11 @@ func resourceSpringCloudService() *pluginsdk.Resource { Update: resourceSpringCloudServiceUpdate, Delete: resourceSpringCloudServiceDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudV0ToV1{}, + }), + Timeouts: &pluginsdk.ResourceTimeout{ Create: pluginsdk.DefaultTimeout(60 * time.Minute), Read: pluginsdk.DefaultTimeout(5 * time.Minute), diff --git a/internal/services/springcloud/spring_cloud_storage_resource.go b/internal/services/springcloud/spring_cloud_storage_resource.go index 199eb24f624e..70ec6f71e31a 100644 --- a/internal/services/springcloud/spring_cloud_storage_resource.go +++ b/internal/services/springcloud/spring_cloud_storage_resource.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -23,6 +24,11 @@ func resourceSpringCloudStorage() *pluginsdk.Resource { Update: resourceSpringCloudStorageCreateUpdate, Delete: resourceSpringCloudStorageDelete, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SpringCloudCloudStorageV0ToV1{}, + }), + Timeouts: &pluginsdk.ResourceTimeout{ Create: pluginsdk.DefaultTimeout(30 * time.Minute), Read: pluginsdk.DefaultTimeout(5 * time.Minute), diff --git a/internal/services/springcloud/validate/spring_cloud_api_portal_custom_domain_id_test.go b/internal/services/springcloud/validate/spring_cloud_api_portal_custom_domain_id_test.go index ba357d758d9c..4207444290e2 100644 --- a/internal/services/springcloud/validate/spring_cloud_api_portal_custom_domain_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_api_portal_custom_domain_id_test.go @@ -48,37 +48,37 @@ func TestSpringCloudAPIPortalCustomDomainID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing ApiPortalName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Valid: false, }, { // missing value for ApiPortalName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/", Valid: false, }, { // missing DomainName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1/", Valid: false, }, { // missing value for DomainName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1/domains/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1/domains/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1/domains/domain1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1/domains/domain1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_api_portal_id_test.go b/internal/services/springcloud/validate/spring_cloud_api_portal_id_test.go index 0395024c7e92..023e71bf8667 100644 --- a/internal/services/springcloud/validate/spring_cloud_api_portal_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_api_portal_id_test.go @@ -48,25 +48,25 @@ func TestSpringCloudAPIPortalID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing ApiPortalName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Valid: false, }, { // missing value for ApiPortalName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_app_association_id_test.go b/internal/services/springcloud/validate/spring_cloud_app_association_id_test.go index 8ca173ffb4b6..e709956bbd9d 100644 --- a/internal/services/springcloud/validate/spring_cloud_app_association_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_app_association_id_test.go @@ -48,37 +48,37 @@ func TestSpringCloudAppAssociationID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", Valid: false, }, { // missing value for AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/", Valid: false, }, { // missing BindingName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/", Valid: false, }, { // missing value for BindingName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/bindings/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/bindings/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/bindings/bind1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/bindings/bind1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_app_id_test.go b/internal/services/springcloud/validate/spring_cloud_app_id_test.go index 22987c271ad0..da1c66028efa 100644 --- a/internal/services/springcloud/validate/spring_cloud_app_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_app_id_test.go @@ -48,25 +48,25 @@ func TestSpringCloudAppID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", Valid: false, }, { // missing value for AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_application_live_view_id_test.go b/internal/services/springcloud/validate/spring_cloud_application_live_view_id_test.go index f7805068255d..6aa7f176fddb 100644 --- a/internal/services/springcloud/validate/spring_cloud_application_live_view_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_application_live_view_id_test.go @@ -48,25 +48,25 @@ func TestSpringCloudApplicationLiveViewID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing ApplicationLiveViewName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Valid: false, }, { // missing value for ApplicationLiveViewName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/applicationLiveViews/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/applicationLiveViews/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/applicationLiveViews/default", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/applicationLiveViews/default", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_build_pack_binding_id_test.go b/internal/services/springcloud/validate/spring_cloud_build_pack_binding_id_test.go index 46643a258b69..0b497095a365 100644 --- a/internal/services/springcloud/validate/spring_cloud_build_pack_binding_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_build_pack_binding_id_test.go @@ -48,49 +48,49 @@ func TestSpringCloudBuildPackBindingID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing BuildServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Valid: false, }, { // missing value for BuildServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/", Valid: false, }, { // missing BuilderName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/", Valid: false, }, { // missing value for BuilderName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/", Valid: false, }, { // missing BuildPackBindingName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1/", Valid: false, }, { // missing value for BuildPackBindingName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/buildPackBinding1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1/buildPackBindings/buildPackBinding1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_build_service_builder_id_test.go b/internal/services/springcloud/validate/spring_cloud_build_service_builder_id_test.go index 0b38611f6e02..c8965be9f494 100644 --- a/internal/services/springcloud/validate/spring_cloud_build_service_builder_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_build_service_builder_id_test.go @@ -48,37 +48,37 @@ func TestSpringCloudBuildServiceBuilderID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing BuildServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Valid: false, }, { // missing value for BuildServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/", Valid: false, }, { // missing BuilderName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/", Valid: false, }, { // missing value for BuilderName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_certificate_id_test.go b/internal/services/springcloud/validate/spring_cloud_certificate_id_test.go index cc6436ef8786..9012f604f143 100644 --- a/internal/services/springcloud/validate/spring_cloud_certificate_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_certificate_id_test.go @@ -48,25 +48,25 @@ func TestSpringCloudCertificateID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing CertificateName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", Valid: false, }, { // missing value for CertificateName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/certificates/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/certificates/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/certificates/cert1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/certificates/cert1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_configuration_service_id_test.go b/internal/services/springcloud/validate/spring_cloud_configuration_service_id_test.go index 797b8a44a139..e7b213dff9e2 100644 --- a/internal/services/springcloud/validate/spring_cloud_configuration_service_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_configuration_service_id_test.go @@ -48,25 +48,25 @@ func TestSpringCloudConfigurationServiceID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing ConfigurationServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Valid: false, }, { // missing value for ConfigurationServiceName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/configurationServices/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/configurationServices/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/configurationServices/configurationService1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/configurationServices/configurationService1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_custom_domain_id_test.go b/internal/services/springcloud/validate/spring_cloud_custom_domain_id_test.go index 120fe7c1a7fe..a4b93732a94e 100644 --- a/internal/services/springcloud/validate/spring_cloud_custom_domain_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_custom_domain_id_test.go @@ -48,37 +48,37 @@ func TestSpringCloudCustomDomainID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", Valid: false, }, { // missing value for AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/", Valid: false, }, { // missing DomainName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/", Valid: false, }, { // missing value for DomainName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/domains/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/domains/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/domains/domain.com", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/domains/domain.com", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_deployment_id_test.go b/internal/services/springcloud/validate/spring_cloud_deployment_id_test.go index 3eb80af43e92..15c94a2e5c1f 100644 --- a/internal/services/springcloud/validate/spring_cloud_deployment_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_deployment_id_test.go @@ -48,37 +48,37 @@ func TestSpringCloudDeploymentID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", Valid: false, }, { // missing value for AppName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/", Valid: false, }, { // missing DeploymentName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/", Valid: false, }, { // missing value for DeploymentName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/deployments/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/deployments/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/deployments/deploy1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/deployments/deploy1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_gateway_custom_domain_id_test.go b/internal/services/springcloud/validate/spring_cloud_gateway_custom_domain_id_test.go index 4c7e51a9afb8..82d5f6c77ce0 100644 --- a/internal/services/springcloud/validate/spring_cloud_gateway_custom_domain_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_gateway_custom_domain_id_test.go @@ -48,37 +48,37 @@ func TestSpringCloudGatewayCustomDomainID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing GatewayName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Valid: false, }, { // missing value for GatewayName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/", Valid: false, }, { // missing DomainName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/", Valid: false, }, { // missing value for DomainName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/domains/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/domains/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/domains/domain1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/domains/domain1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_gateway_id_test.go b/internal/services/springcloud/validate/spring_cloud_gateway_id_test.go index d2e38258f374..53cb7d35df26 100644 --- a/internal/services/springcloud/validate/spring_cloud_gateway_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_gateway_id_test.go @@ -48,25 +48,25 @@ func TestSpringCloudGatewayID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing GatewayName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Valid: false, }, { // missing value for GatewayName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_gateway_route_config_id_test.go b/internal/services/springcloud/validate/spring_cloud_gateway_route_config_id_test.go index cc95ba528540..7ec6230bb745 100644 --- a/internal/services/springcloud/validate/spring_cloud_gateway_route_config_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_gateway_route_config_id_test.go @@ -48,37 +48,37 @@ func TestSpringCloudGatewayRouteConfigID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing GatewayName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Valid: false, }, { // missing value for GatewayName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/", Valid: false, }, { // missing RouteConfigName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/", Valid: false, }, { // missing value for RouteConfigName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/routeConfigs/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/routeConfigs/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/routeConfigs/routeConfig1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/routeConfigs/routeConfig1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_service_id_test.go b/internal/services/springcloud/validate/spring_cloud_service_id_test.go index 7260fb314e1d..b90f5fb960c6 100644 --- a/internal/services/springcloud/validate/spring_cloud_service_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_service_id_test.go @@ -48,13 +48,13 @@ func TestSpringCloudServiceID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_service_registry_id_test.go b/internal/services/springcloud/validate/spring_cloud_service_registry_id_test.go index f7160cb1f34e..35e4f292b652 100644 --- a/internal/services/springcloud/validate/spring_cloud_service_registry_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_service_registry_id_test.go @@ -48,25 +48,25 @@ func TestSpringCloudServiceRegistryID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing ServiceRegistryName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/", Valid: false, }, { // missing value for ServiceRegistryName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/serviceRegistries/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/serviceRegistries/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/serviceRegistries/serviceRegistry1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/serviceRegistries/serviceRegistry1", Valid: true, }, diff --git a/internal/services/springcloud/validate/spring_cloud_storage_id_test.go b/internal/services/springcloud/validate/spring_cloud_storage_id_test.go index 1c0a888fbccf..8a2794f52355 100644 --- a/internal/services/springcloud/validate/spring_cloud_storage_id_test.go +++ b/internal/services/springcloud/validate/spring_cloud_storage_id_test.go @@ -48,25 +48,25 @@ func TestSpringCloudStorageID(t *testing.T) { { // missing value for SpringName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/", Valid: false, }, { // missing StorageName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/", Valid: false, }, { // missing value for StorageName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/storages/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/storages/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/storages/storage1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/storages/storage1", Valid: true, }, diff --git a/website/docs/r/spring_cloud_active_deployment.html.markdown b/website/docs/r/spring_cloud_active_deployment.html.markdown index 191488357912..8932cbb50fcf 100644 --- a/website/docs/r/spring_cloud_active_deployment.html.markdown +++ b/website/docs/r/spring_cloud_active_deployment.html.markdown @@ -89,5 +89,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Active Deployment can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_active_deployment.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourcegroup1/providers/Microsoft.AppPlatform/Spring/service1/apps/app1 +terraform import azurerm_spring_cloud_active_deployment.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourcegroup1/providers/Microsoft.AppPlatform/spring/service1/apps/app1 ``` diff --git a/website/docs/r/spring_cloud_api_portal.html.markdown b/website/docs/r/spring_cloud_api_portal.html.markdown index 937f70ab406e..e0a4b05cec31 100644 --- a/website/docs/r/spring_cloud_api_portal.html.markdown +++ b/website/docs/r/spring_cloud_api_portal.html.markdown @@ -106,5 +106,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud API Portals can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_api_portal.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1 +terraform import azurerm_spring_cloud_api_portal.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1 ``` diff --git a/website/docs/r/spring_cloud_api_portal_custom_domain.html.markdown b/website/docs/r/spring_cloud_api_portal_custom_domain.html.markdown index 259d2304e55f..c742025562fe 100644 --- a/website/docs/r/spring_cloud_api_portal_custom_domain.html.markdown +++ b/website/docs/r/spring_cloud_api_portal_custom_domain.html.markdown @@ -80,5 +80,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud API Portal Domains can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_api_portal_custom_domain.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/apiPortals/apiPortal1/domains/domain1 +terraform import azurerm_spring_cloud_api_portal_custom_domain.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/apiPortals/apiPortal1/domains/domain1 ``` diff --git a/website/docs/r/spring_cloud_app.html.markdown b/website/docs/r/spring_cloud_app.html.markdown index 8ebfd9bcf847..08285e935ada 100644 --- a/website/docs/r/spring_cloud_app.html.markdown +++ b/website/docs/r/spring_cloud_app.html.markdown @@ -144,5 +144,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Application can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_app.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.AppPlatform/Spring/myservice/apps/myapp +terraform import azurerm_spring_cloud_app.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.AppPlatform/spring/myservice/apps/myapp ``` diff --git a/website/docs/r/spring_cloud_app_cosmosdb_association.html.markdown b/website/docs/r/spring_cloud_app_cosmosdb_association.html.markdown index fff3ee8e5e9a..331977868a1d 100644 --- a/website/docs/r/spring_cloud_app_cosmosdb_association.html.markdown +++ b/website/docs/r/spring_cloud_app_cosmosdb_association.html.markdown @@ -100,5 +100,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Application CosmosDB Association can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_app_cosmosdb_association.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourcegroup1/providers/Microsoft.AppPlatform/Spring/service1/apps/app1/bindings/bind1 +terraform import azurerm_spring_cloud_app_cosmosdb_association.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourcegroup1/providers/Microsoft.AppPlatform/spring/service1/apps/app1/bindings/bind1 ``` diff --git a/website/docs/r/spring_cloud_app_mysql_association.html.markdown b/website/docs/r/spring_cloud_app_mysql_association.html.markdown index badb43261770..47b57531ca19 100644 --- a/website/docs/r/spring_cloud_app_mysql_association.html.markdown +++ b/website/docs/r/spring_cloud_app_mysql_association.html.markdown @@ -100,5 +100,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Application MySQL Association can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_app_mysql_association.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourcegroup1/providers/Microsoft.AppPlatform/Spring/service1/apps/app1/bindings/bind1 +terraform import azurerm_spring_cloud_app_mysql_association.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourcegroup1/providers/Microsoft.AppPlatform/spring/service1/apps/app1/bindings/bind1 ``` diff --git a/website/docs/r/spring_cloud_app_redis_association.html.markdown b/website/docs/r/spring_cloud_app_redis_association.html.markdown index f0e6c21e5b8b..b5026c4e30a8 100644 --- a/website/docs/r/spring_cloud_app_redis_association.html.markdown +++ b/website/docs/r/spring_cloud_app_redis_association.html.markdown @@ -87,5 +87,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Application Redis Association can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_app_redis_association.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.AppPlatform/Spring/myservice/apps/myapp/bindings/bind1 +terraform import azurerm_spring_cloud_app_redis_association.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.AppPlatform/spring/myservice/apps/myapp/bindings/bind1 ``` diff --git a/website/docs/r/spring_cloud_application_live_view.html.markdown b/website/docs/r/spring_cloud_application_live_view.html.markdown index b7734c382214..5bc7f5a75be6 100644 --- a/website/docs/r/spring_cloud_application_live_view.html.markdown +++ b/website/docs/r/spring_cloud_application_live_view.html.markdown @@ -64,6 +64,6 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Application Live Views can be imported using the `resource id`, e.g. -```shell -terraform import azurerm_spring_cloud_application_live_view.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/applicationLiveViews/default +```shellg +terraform import azurerm_spring_cloud_application_live_view.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/applicationLiveViews/default ``` diff --git a/website/docs/r/spring_cloud_build_deployment.html.markdown b/website/docs/r/spring_cloud_build_deployment.html.markdown index 5e7cccc07cf0..106972311b37 100644 --- a/website/docs/r/spring_cloud_build_deployment.html.markdown +++ b/website/docs/r/spring_cloud_build_deployment.html.markdown @@ -106,5 +106,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Build Deployments can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_build_deployment.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/deployments/deploy1 +terraform import azurerm_spring_cloud_build_deployment.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/deployments/deploy1 ``` diff --git a/website/docs/r/spring_cloud_build_pack_binding.html.markdown b/website/docs/r/spring_cloud_build_pack_binding.html.markdown index a579aa24eae3..2ad6c37316b1 100644 --- a/website/docs/r/spring_cloud_build_pack_binding.html.markdown +++ b/website/docs/r/spring_cloud_build_pack_binding.html.markdown @@ -106,5 +106,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Build Pack Bindings can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_build_pack_binding.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1/Build PackBindings/Build PackBinding1 +terraform import azurerm_spring_cloud_build_pack_binding.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1/Build PackBindings/Build PackBinding1 ``` diff --git a/website/docs/r/spring_cloud_builder.html.markdown b/website/docs/r/spring_cloud_builder.html.markdown index 7e72eb9764c4..9edb646bab42 100644 --- a/website/docs/r/spring_cloud_builder.html.markdown +++ b/website/docs/r/spring_cloud_builder.html.markdown @@ -95,5 +95,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Builders can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_builder.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/buildServices/buildService1/builders/builder1 +terraform import azurerm_spring_cloud_builder.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/buildServices/buildService1/builders/builder1 ``` diff --git a/website/docs/r/spring_cloud_certificate.html.markdown b/website/docs/r/spring_cloud_certificate.html.markdown index 35baa3bcbd85..290e2f289f99 100644 --- a/website/docs/r/spring_cloud_certificate.html.markdown +++ b/website/docs/r/spring_cloud_certificate.html.markdown @@ -146,5 +146,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Certificate can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_certificate.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourcegroup1/providers/Microsoft.AppPlatform/Spring/spring1/certificates/cert1 +terraform import azurerm_spring_cloud_certificate.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourcegroup1/providers/Microsoft.AppPlatform/spring/spring1/certificates/cert1 ``` diff --git a/website/docs/r/spring_cloud_configuration_service.html.markdown b/website/docs/r/spring_cloud_configuration_service.html.markdown index 08dca472d196..ee0cc99f3fef 100644 --- a/website/docs/r/spring_cloud_configuration_service.html.markdown +++ b/website/docs/r/spring_cloud_configuration_service.html.markdown @@ -105,5 +105,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Configuration Services can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_configuration_service.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/configurationServices/configurationService1 +terraform import azurerm_spring_cloud_configuration_service.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/configurationServices/configurationService1 ``` diff --git a/website/docs/r/spring_cloud_container_deployment.html.markdown b/website/docs/r/spring_cloud_container_deployment.html.markdown index 9b37e42e20b4..6e194ca508c6 100644 --- a/website/docs/r/spring_cloud_container_deployment.html.markdown +++ b/website/docs/r/spring_cloud_container_deployment.html.markdown @@ -111,5 +111,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Container Deployments can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_container_deployment.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/deployments/deploy1 +terraform import azurerm_spring_cloud_container_deployment.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/deployments/deploy1 ``` diff --git a/website/docs/r/spring_cloud_custom_domain.html.markdown b/website/docs/r/spring_cloud_custom_domain.html.markdown index c53333f74a7b..e673a0a76a82 100644 --- a/website/docs/r/spring_cloud_custom_domain.html.markdown +++ b/website/docs/r/spring_cloud_custom_domain.html.markdown @@ -85,5 +85,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Custom Domain can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_custom_domain.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/Spring/spring1/apps/app1/domains/domain.com +terraform import azurerm_spring_cloud_custom_domain.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AppPlatform/spring/spring1/apps/app1/domains/domain.com ``` diff --git a/website/docs/r/spring_cloud_gateway.html.markdown b/website/docs/r/spring_cloud_gateway.html.markdown index 90d5d8564d00..e78aa918370d 100644 --- a/website/docs/r/spring_cloud_gateway.html.markdown +++ b/website/docs/r/spring_cloud_gateway.html.markdown @@ -170,5 +170,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Gateways can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_gateway.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1 +terraform import azurerm_spring_cloud_gateway.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1 ``` diff --git a/website/docs/r/spring_cloud_gateway_custom_domain.html.markdown b/website/docs/r/spring_cloud_gateway_custom_domain.html.markdown index 375326fa9bea..fa33b9582ce3 100644 --- a/website/docs/r/spring_cloud_gateway_custom_domain.html.markdown +++ b/website/docs/r/spring_cloud_gateway_custom_domain.html.markdown @@ -74,5 +74,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Gateway Custom Domains can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_gateway_custom_domain.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/domains/domain1 +terraform import azurerm_spring_cloud_gateway_custom_domain.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/domains/domain1 ``` diff --git a/website/docs/r/spring_cloud_gateway_route_config.html.markdown b/website/docs/r/spring_cloud_gateway_route_config.html.markdown index f665029848c2..74600e5ed3e8 100644 --- a/website/docs/r/spring_cloud_gateway_route_config.html.markdown +++ b/website/docs/r/spring_cloud_gateway_route_config.html.markdown @@ -135,5 +135,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Gateway Route Configs can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_gateway_route_config.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/gateways/gateway1/routeConfigs/routeConfig1 +terraform import azurerm_spring_cloud_gateway_route_config.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/gateways/gateway1/routeConfigs/routeConfig1 ``` diff --git a/website/docs/r/spring_cloud_java_deployment.html.markdown b/website/docs/r/spring_cloud_java_deployment.html.markdown index 83ba991f687f..45a263c93329 100644 --- a/website/docs/r/spring_cloud_java_deployment.html.markdown +++ b/website/docs/r/spring_cloud_java_deployment.html.markdown @@ -110,5 +110,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Deployment can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_java_deployment.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourcegroup1/providers/Microsoft.AppPlatform/Spring/service1/apps/app1/deployments/deploy1 +terraform import azurerm_spring_cloud_java_deployment.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourcegroup1/providers/Microsoft.AppPlatform/spring/service1/apps/app1/deployments/deploy1 ``` diff --git a/website/docs/r/spring_cloud_service.html.markdown b/website/docs/r/spring_cloud_service.html.markdown index 0ae691785d16..120c37ab797b 100644 --- a/website/docs/r/spring_cloud_service.html.markdown +++ b/website/docs/r/spring_cloud_service.html.markdown @@ -198,5 +198,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud services can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_service.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.AppPlatform/Spring/spring1 +terraform import azurerm_spring_cloud_service.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.AppPlatform/spring/spring1 ``` diff --git a/website/docs/r/spring_cloud_storage.html.markdown b/website/docs/r/spring_cloud_storage.html.markdown index 515025ce9f95..4a51c9a43432 100644 --- a/website/docs/r/spring_cloud_storage.html.markdown +++ b/website/docs/r/spring_cloud_storage.html.markdown @@ -72,5 +72,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Spring Cloud Storages can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_spring_cloud_storage.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/Spring/service1/storages/storage1 +terraform import azurerm_spring_cloud_storage.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppPlatform/spring/service1/storages/storage1 ```