Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3] Skip flattening if properties would clash #3016

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,125 changes: 1,023 additions & 1,102 deletions provider/cmd/pulumi-resource-azure-native/schema.json

Large diffs are not rendered by default.

54 changes: 30 additions & 24 deletions provider/pkg/gen/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ func (m *moduleGenerator) genProperties(resolvedSchema *openapi.Schema, isOutput
sdkName = ToLowerCamel(sdkName)

// Flattened properties aren't modelled in the SDK explicitly: their sub-properties are merged directly to the parent.
// If the type is marked as a dictionary, ignore the extension and proceed with modeling this property explicitly.
// We can't flatten dictionaries in a type-safe manner.
// There are two exceptions to this rule, for which we skip the merging:
// 1. If the type is marked as a dictionary, ignore the extension and proceed with modeling this property explicitly.
// We can't flatten dictionaries in a type-safe manner.
// 2. Sometimes the Azure spec misuses the "x-ms-client-flatten" extension in cases where flattening would cause two
// properties to conflict because the outer and the inner type both have a property with the same name.
isDict := resolvedProperty.AdditionalProperties != nil
//TODO: Remove when https://github.com/Azure/azure-rest-api-specs/pull/14550 is rolled back
workaroundDelegatedNetworkBreakingChange := property.Ref.String() == "#/definitions/OrchestratorResourceProperties" ||
Expand All @@ -97,36 +100,39 @@ func (m *moduleGenerator) genProperties(resolvedSchema *openapi.Schema, isOutput
return nil, err
}

// Check that none of the inner properties already exists on the outer type. This
// causes a conflict when flattening, and will probably need to be handled in v3.
// Check that none of the inner properties already exists on the outer type.
hasConflict := false
for propName := range bag.properties {
if _, has := result.properties[propName]; has {
if _, hasConflict = result.properties[propName]; hasConflict {
m.flattenedPropertyConflicts[fmt.Sprintf("%s.%s", name, propName)] = struct{}{}
break
}
}

// Adjust every property to mark them as flattened.
newProperties := map[string]resources.AzureAPIProperty{}
for n, value := range bag.properties {
// The order of containers is important, so we prepend the outermost name.
value.Containers = append([]string{name}, value.Containers...)
newProperties[n] = value
}
bag.properties = newProperties
if !hasConflict {
// Adjust every property to mark them as flattened.
newProperties := map[string]resources.AzureAPIProperty{}
for n, value := range bag.properties {
// The order of containers is important, so we prepend the outermost name.
value.Containers = append([]string{name}, value.Containers...)
newProperties[n] = value
}
bag.properties = newProperties

newRequiredContainers := make(RequiredContainers, len(bag.requiredContainers))
for i, containers := range bag.requiredContainers {
newRequiredContainers[i] = append([]string{name}, containers...)
}
for _, requiredName := range resolvedSchema.Required {
if requiredName == name {
newRequiredContainers = append(newRequiredContainers, []string{name})
newRequiredContainers := make(RequiredContainers, len(bag.requiredContainers))
for i, containers := range bag.requiredContainers {
newRequiredContainers[i] = append([]string{name}, containers...)
}
}
bag.requiredContainers = newRequiredContainers
for _, requiredName := range resolvedSchema.Required {
if requiredName == name {
newRequiredContainers = append(newRequiredContainers, []string{name})
}
}
bag.requiredContainers = newRequiredContainers

result.merge(bag)
continue
result.merge(bag)
continue
}
}

// Skip read-only properties for input types and write-only properties for output types.
Expand Down
5 changes: 5 additions & 0 deletions provider/pkg/openapi/defaults/defaultResourcesState.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ var defaultResourcesStateRaw = map[string]map[string]interface{}{
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/ProactiveDetectionConfigs/{ConfigurationId}": {
"enabled": false,
},
"/{resourceId}/providers/Microsoft.Security/defenderForStorageSettings/{settingName}": {
"isEnabled": false,
// https://learn.microsoft.com/en-us/azure/storage/common/azure-defender-storage-configure?tabs=enable-subscription#rest-api-1
"overrideSubscriptionLevelSettings": true,
},
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ServiceBus/namespaces/{namespaceName}/networkRuleSets/default": {
"defaultAction": "Deny",
},
Expand Down
3 changes: 3 additions & 0 deletions reports/allResourceVersionsByResource.json
Original file line number Diff line number Diff line change
Expand Up @@ -18002,6 +18002,9 @@
"CustomEntityStoreAssignment": [
"2021-07-01-preview"
],
"DefenderForStorage": [
"2022-12-01-preview"
],
"DevOpsConfiguration": [
"2023-09-01-preview"
],
Expand Down
3 changes: 3 additions & 0 deletions reports/allResourcesByVersion.json
Original file line number Diff line number Diff line change
Expand Up @@ -17463,6 +17463,9 @@
"2022-11-20-preview": [
"APICollection"
],
"2022-12-01-preview": [
"DefenderForStorage"
],
"2023-01-01-preview": [
"SecurityOperator"
],
Expand Down
12 changes: 4 additions & 8 deletions reports/flattenedPropertyConflicts.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,16 @@
},
"azure-native:security/v20221201preview:DefenderForStorage": {
"malwareScanning.isEnabled": {},
"sensitiveDataDiscovery.isEnabled": {},
"sensitiveDataDiscovery.operationStatus": {}
"sensitiveDataDiscovery.isEnabled": {}
},
"azure-native:security:DefenderForStorage": {
"malwareScanning.isEnabled": {},
"sensitiveDataDiscovery.isEnabled": {},
"sensitiveDataDiscovery.operationStatus": {}
"sensitiveDataDiscovery.isEnabled": {}
},
"azure-native:vmwarecloudsimple/v20190401:DedicatedCloudNode": {
"properties.id": {},
"properties.name": {}
"properties.id": {}
},
"azure-native:vmwarecloudsimple:DedicatedCloudNode": {
"properties.id": {},
"properties.name": {}
"properties.id": {}
}
}
1 change: 1 addition & 0 deletions reports/pending.json
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@
"2022-07-01-preview",
"2022-08-01-preview",
"2022-11-20-preview",
"2022-12-01-preview",
"2023-01-01-preview",
"2023-02-01-preview",
"2023-03-01-preview",
Expand Down
46 changes: 11 additions & 35 deletions sdk/dotnet/Authorization/AccessReviewHistoryDefinitionById.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ public partial class AccessReviewHistoryDefinitionById : global::Pulumi.CustomRe
[Output("displayName")]
public Output<string?> DisplayName { get; private set; } = null!;

/// <summary>
/// The DateTime when the review is scheduled to end. Required if type is endDate
/// </summary>
[Output("endDate")]
public Output<string?> EndDate { get; private set; } = null!;

/// <summary>
/// Set of access review history instances for this history definition.
/// </summary>
Expand All @@ -58,12 +52,6 @@ public partial class AccessReviewHistoryDefinitionById : global::Pulumi.CustomRe
[Output("name")]
public Output<string> Name { get; private set; } = null!;

/// <summary>
/// The number of times to repeat the access review. Required and must be positive if type is numbered.
/// </summary>
[Output("numberOfOccurrences")]
public Output<int?> NumberOfOccurrences { get; private set; } = null!;

/// <summary>
/// The identity id
/// </summary>
Expand All @@ -82,6 +70,12 @@ public partial class AccessReviewHistoryDefinitionById : global::Pulumi.CustomRe
[Output("principalType")]
public Output<string> PrincipalType { get; private set; } = null!;

/// <summary>
/// Access Review History Definition recurrence settings.
/// </summary>
[Output("range")]
public Output<Outputs.AccessReviewRecurrenceRangeResponse?> Range { get; private set; } = null!;

/// <summary>
/// Date time used when selecting review data, all reviews included in data end on or before this date. For use only with one-time/non-recurring reports.
/// </summary>
Expand All @@ -100,12 +94,6 @@ public partial class AccessReviewHistoryDefinitionById : global::Pulumi.CustomRe
[Output("scopes")]
public Output<ImmutableArray<Outputs.AccessReviewScopeResponse>> Scopes { get; private set; } = null!;

/// <summary>
/// The DateTime when the review is scheduled to be start. This could be a date in the future. Required on create.
/// </summary>
[Output("startDate")]
public Output<string?> StartDate { get; private set; } = null!;

/// <summary>
/// This read-only field specifies the of the requested review history data. This is either requested, in-progress, done or error.
/// </summary>
Expand Down Expand Up @@ -192,12 +180,6 @@ public sealed class AccessReviewHistoryDefinitionByIdArgs : global::Pulumi.Resou
[Input("displayName")]
public Input<string>? DisplayName { get; set; }

/// <summary>
/// The DateTime when the review is scheduled to end. Required if type is endDate
/// </summary>
[Input("endDate")]
public Input<string>? EndDate { get; set; }

/// <summary>
/// The id of the access review history definition.
/// </summary>
Expand All @@ -223,10 +205,10 @@ public InputList<Inputs.AccessReviewHistoryInstanceArgs> Instances
public Input<int>? Interval { get; set; }

/// <summary>
/// The number of times to repeat the access review. Required and must be positive if type is numbered.
/// Access Review History Definition recurrence settings.
/// </summary>
[Input("numberOfOccurrences")]
public Input<int>? NumberOfOccurrences { get; set; }
[Input("range")]
public Input<Inputs.AccessReviewRecurrenceRangeArgs>? Range { get; set; }

[Input("scopes")]
private InputList<Inputs.AccessReviewScopeArgs>? _scopes;
Expand All @@ -241,16 +223,10 @@ public InputList<Inputs.AccessReviewScopeArgs> Scopes
}

/// <summary>
/// The DateTime when the review is scheduled to be start. This could be a date in the future. Required on create.
/// </summary>
[Input("startDate")]
public Input<string>? StartDate { get; set; }

/// <summary>
/// The recurrence range type. The possible values are: endDate, noEnd, numbered.
/// The recurrence type : weekly, monthly, etc.
/// </summary>
[Input("type")]
public InputUnion<string, Pulumi.AzureNative.Authorization.AccessReviewRecurrenceRangeType>? Type { get; set; }
public InputUnion<string, Pulumi.AzureNative.Authorization.AccessReviewRecurrencePatternType>? Type { get; set; }

public AccessReviewHistoryDefinitionByIdArgs()
{
Expand Down
Loading
Loading