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

Revert instance diff changes #333

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8ef1aa2
Add server-side apply merge strategy markers
negz Nov 12, 2023
bed1fa2
Post release commit after v1.0.0
ulucinar Nov 16, 2023
0752be6
Make main-tf contents exported
therealmitchconnors Jun 27, 2023
c40331d
fix signature
therealmitchconnors Nov 20, 2023
5150500
Fix kubebuilder topological markers: use "=" instead of ":" between t…
ulucinar Dec 1, 2023
ca2cfe6
Merge pull request #301 from negz/scribble
ulucinar Dec 5, 2023
f99dee3
Pass default and configured timeouts to InstanceState for using the t…
sergenyalcin Dec 5, 2023
a978820
Merge pull request #309 from sergenyalcin/set-timeouts-instancestate
sergenyalcin Dec 5, 2023
25a4aa5
Add exported function description
therealmitchconnors Nov 29, 2023
7431179
Call the registered schema.CustomizeDiffFunc functions in the Terrafo…
ulucinar Dec 12, 2023
77613fd
Merge pull request #311 from ulucinar/enable-customizediff
ulucinar Dec 12, 2023
085ff0a
Ignore specific error that returned by expandWildcard function
sergenyalcin Dec 12, 2023
a46199f
Merge pull request #223 from therealmitchconnors/main
ulucinar Dec 12, 2023
0fc0a07
Add config.Resource.ServerSideApplyMergeStrategies to be able to conf…
ulucinar Dec 1, 2023
cf1b346
Merge pull request #312 from sergenyalcin/handle--notfound-error-type
sergenyalcin Dec 13, 2023
b674f3d
Cache the Terraform instance state returned from schema.Resource.Apply
ulucinar Dec 14, 2023
9543be9
Merge pull request #313 from ulucinar/capture-id
ulucinar Dec 18, 2023
807fb9d
Merge pull request #308 from ulucinar/ssa-object-lists
ulucinar Dec 21, 2023
eb239f4
Add reference fields to the InitProvider
sergenyalcin Dec 21, 2023
ac7c6a1
Pass full state to GetExternalNameFn function to access field other t…
sergenyalcin Dec 21, 2023
f548c79
- Check if the id is empty
sergenyalcin Dec 22, 2023
0bc8185
Merge pull request #316 from sergenyalcin/pass-allstate-to-getexterna…
sergenyalcin Dec 22, 2023
b15649b
Alias diag import
ulucinar Dec 21, 2023
74159f8
Return the cty.Value of InstanceState from noForkExternal.fromInstanc…
ulucinar Dec 21, 2023
f0de67a
Set the RawPlan for a new terraform.InstanceState returned from an ob…
ulucinar Dec 22, 2023
1d547af
Merge pull request #317 from ulucinar/fix-customize-diff
ulucinar Dec 22, 2023
ccb0611
Set diff state's Attributes to nil if the resource does not exist
ulucinar Dec 22, 2023
81e2620
Merge pull request #318 from ulucinar/fix-diff-state
ulucinar Dec 25, 2023
6a56e73
Fix nonintentional if case
sergenyalcin Dec 26, 2023
fb8acdb
Merge pull request #315 from sergenyalcin/support-references-for-init…
sergenyalcin Dec 26, 2023
f33d01b
Revert "Merge pull request #318 from ulucinar/fix-diff-state"
mbbush Jan 23, 2024
cd53d7a
Revert "Merge pull request #317 from ulucinar/fix-customize-diff"
mbbush Jan 23, 2024
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
23 changes: 12 additions & 11 deletions pkg/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,18 @@ func DefaultResource(name string, terraformSchema *schema.Resource, terraformReg
}

r := &Resource{
Name: name,
TerraformResource: terraformSchema,
MetaResource: terraformRegistry,
ShortGroup: group,
Kind: kind,
Version: "v1alpha1",
ExternalName: NameAsIdentifier,
References: map[string]Reference{},
Sensitive: NopSensitive,
UseAsync: true,
SchemaElementOptions: make(map[string]*SchemaElementOption),
Name: name,
TerraformResource: terraformSchema,
MetaResource: terraformRegistry,
ShortGroup: group,
Kind: kind,
Version: "v1alpha1",
ExternalName: NameAsIdentifier,
References: make(References),
Sensitive: NopSensitive,
UseAsync: true,
SchemaElementOptions: make(SchemaElementOptions),
ServerSideApplyMergeStrategies: make(ServerSideApplyMergeStrategies),
}
for _, f := range opts {
f(r)
Expand Down
95 changes: 50 additions & 45 deletions pkg/config/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ func TestDefaultResource(t *testing.T) {
name: "aws_ec2_instance",
},
want: &Resource{
Name: "aws_ec2_instance",
ShortGroup: "ec2",
Kind: "Instance",
Version: "v1alpha1",
ExternalName: NameAsIdentifier,
References: map[string]Reference{},
Sensitive: NopSensitive,
UseAsync: true,
SchemaElementOptions: SchemaElementOptions{},
Name: "aws_ec2_instance",
ShortGroup: "ec2",
Kind: "Instance",
Version: "v1alpha1",
ExternalName: NameAsIdentifier,
References: map[string]Reference{},
Sensitive: NopSensitive,
UseAsync: true,
SchemaElementOptions: SchemaElementOptions{},
ServerSideApplyMergeStrategies: ServerSideApplyMergeStrategies{},
},
},
"TwoSectionsName": {
Expand All @@ -50,15 +51,16 @@ func TestDefaultResource(t *testing.T) {
name: "aws_instance",
},
want: &Resource{
Name: "aws_instance",
ShortGroup: "aws",
Kind: "Instance",
Version: "v1alpha1",
ExternalName: NameAsIdentifier,
References: map[string]Reference{},
Sensitive: NopSensitive,
UseAsync: true,
SchemaElementOptions: SchemaElementOptions{},
Name: "aws_instance",
ShortGroup: "aws",
Kind: "Instance",
Version: "v1alpha1",
ExternalName: NameAsIdentifier,
References: map[string]Reference{},
Sensitive: NopSensitive,
UseAsync: true,
SchemaElementOptions: SchemaElementOptions{},
ServerSideApplyMergeStrategies: ServerSideApplyMergeStrategies{},
},
},
"NameWithPrefixAcronym": {
Expand All @@ -67,15 +69,16 @@ func TestDefaultResource(t *testing.T) {
name: "aws_db_sql_server",
},
want: &Resource{
Name: "aws_db_sql_server",
ShortGroup: "db",
Kind: "SQLServer",
Version: "v1alpha1",
ExternalName: NameAsIdentifier,
References: map[string]Reference{},
Sensitive: NopSensitive,
UseAsync: true,
SchemaElementOptions: SchemaElementOptions{},
Name: "aws_db_sql_server",
ShortGroup: "db",
Kind: "SQLServer",
Version: "v1alpha1",
ExternalName: NameAsIdentifier,
References: map[string]Reference{},
Sensitive: NopSensitive,
UseAsync: true,
SchemaElementOptions: SchemaElementOptions{},
ServerSideApplyMergeStrategies: ServerSideApplyMergeStrategies{},
},
},
"NameWithSuffixAcronym": {
Expand All @@ -84,15 +87,16 @@ func TestDefaultResource(t *testing.T) {
name: "aws_db_server_id",
},
want: &Resource{
Name: "aws_db_server_id",
ShortGroup: "db",
Kind: "ServerID",
Version: "v1alpha1",
ExternalName: NameAsIdentifier,
References: map[string]Reference{},
Sensitive: NopSensitive,
UseAsync: true,
SchemaElementOptions: SchemaElementOptions{},
Name: "aws_db_server_id",
ShortGroup: "db",
Kind: "ServerID",
Version: "v1alpha1",
ExternalName: NameAsIdentifier,
References: map[string]Reference{},
Sensitive: NopSensitive,
UseAsync: true,
SchemaElementOptions: SchemaElementOptions{},
ServerSideApplyMergeStrategies: ServerSideApplyMergeStrategies{},
},
},
"NameWithMultipleAcronyms": {
Expand All @@ -101,15 +105,16 @@ func TestDefaultResource(t *testing.T) {
name: "aws_db_sql_server_id",
},
want: &Resource{
Name: "aws_db_sql_server_id",
ShortGroup: "db",
Kind: "SQLServerID",
Version: "v1alpha1",
ExternalName: NameAsIdentifier,
References: map[string]Reference{},
Sensitive: NopSensitive,
UseAsync: true,
SchemaElementOptions: SchemaElementOptions{},
Name: "aws_db_sql_server_id",
ShortGroup: "db",
Kind: "SQLServerID",
Version: "v1alpha1",
ExternalName: NameAsIdentifier,
References: map[string]Reference{},
Sensitive: NopSensitive,
UseAsync: true,
SchemaElementOptions: SchemaElementOptions{},
ServerSideApplyMergeStrategies: ServerSideApplyMergeStrategies{},
},
},
}
Expand Down
108 changes: 108 additions & 0 deletions pkg/config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,54 @@ import (
"github.com/crossplane/upjet/pkg/registry"
)

// A ListType is a type of list.
type ListType string

// Types of lists.
const (
// ListTypeAtomic means the entire list is replaced during merge. At any
// point in time, a single manager owns the list.
ListTypeAtomic ListType = "atomic"

// ListTypeSet can be granularly merged, and different managers can own
// different elements in the list. The list can include only scalar
// elements.
ListTypeSet ListType = "set"

// ListTypeMap can be granularly merged, and different managers can own
// different elements in the list. The list can include only nested types
// (i.e. objects).
ListTypeMap ListType = "map"
)

// A MapType is a type of map.
type MapType string

// Types of maps.
const (
// MapTypeAtomic means that the map can only be entirely replaced by a
// single manager.
MapTypeAtomic MapType = "atomic"

// MapTypeGranular means that the map supports separate managers updating
// individual fields.
MapTypeGranular MapType = "granular"
)

// A StructType is a type of struct.
type StructType string

// Struct types.
const (
// StructTypeAtomic means that the struct can only be entirely replaced by a
// single manager.
StructTypeAtomic StructType = "atomic"

// StructTypeGranular means that the struct supports separate managers
// updating individual fields.
StructTypeGranular StructType = "granular"
)

// SetIdentifierArgumentsFn sets the name of the resource in Terraform attributes map,
// i.e. Main HCL file.
type SetIdentifierArgumentsFn func(base map[string]any, externalName string)
Expand Down Expand Up @@ -266,6 +314,60 @@ func setExternalTagsWithPaved(externalTags map[string]string, paved *fieldpath.P
return pavedByte, nil
}

type InjectedKey struct {
Key string
DefaultValue string
}

// ListMapKeys is the list map keys when the server-side apply merge strategy
// islistType=map.
type ListMapKeys struct {
// InjectedKey can be used to inject the specified index key
// into the generated CRD schema for the list object when
// the SSA merge strategy for the parent list is `map`.
// If a non-zero `InjectedKey` is specified, then a field of type string with
// the specified name is injected into the Terraform schema and used as
// a list map key together with any other existing keys specified in `Keys`.
InjectedKey InjectedKey
// Keys is the set of list map keys to be used while SSA merges list items.
// If InjectedKey is non-zero, then it's automatically put into Keys and
// you must not specify the InjectedKey in Keys explicitly.
Keys []string
}

// ListMergeStrategy configures the corresponding field as list
// and configures its server-side apply merge strategy.
type ListMergeStrategy struct {
// ListMapKeys is the list map keys when the SSA merge strategy is
// `listType=map`. The keys specified here must be a set of scalar Terraform
// argument names to be used as the list map keys for the object list.
ListMapKeys ListMapKeys
// MergeStrategy is the SSA merge strategy for an object list. Valid values
// are: `atomic`, `set` and `map`
MergeStrategy ListType
}

// MergeStrategy configures the server-side apply merge strategy for the
// corresponding field. One and only one of the pointer members can be set
// and the specified merge strategy configuration must match the field's
// type, e.g., you cannot set MapMergeStrategy for a field of type list.
type MergeStrategy struct {
ListMergeStrategy ListMergeStrategy
MapMergeStrategy MapType
StructMergeStrategy StructType
}

// ServerSideApplyMergeStrategies configures the server-side apply merge strategy
// for the field at the specified path as the map key. The key is
// a Terraform configuration argument path such as a.b.c, without any
// index notation (i.e., array/map components do not need indices).
// It's an error to set a configuration option which does not match
// the object type at the specified path or to leave the corresponding
// configuration entry empty. For example, if the field at path a.b.c is
// a list, then ListMergeStrategy must be set and it should be the only
// configuration entry set.
type ServerSideApplyMergeStrategies map[string]MergeStrategy

// Resource is the set of information that you can override at different steps
// of the code generation pipeline.
type Resource struct {
Expand Down Expand Up @@ -338,6 +440,12 @@ type Resource struct {
// Terraform InstanceDiff is computed during reconciliation.
TerraformCustomDiff CustomDiff

// ServerSideApplyMergeStrategies configures the server-side apply merge
// strategy for the fields at the given map keys. The map key is
// a Terraform configuration argument path such as a.b.c, without any
// index notation (i.e., array/map components do not need indices).
ServerSideApplyMergeStrategies ServerSideApplyMergeStrategies

// useNoForkClient indicates that a no-fork external client should
// be generated instead of the Terraform CLI-forking client.
useNoForkClient bool
Expand Down
Loading