diff --git a/apis/containerservice/v1alpha1/zz_generated.deepcopy.go b/apis/containerservice/v1alpha1/zz_generated.deepcopy.go index 1bf38483a..4a2e72dce 100644 --- a/apis/containerservice/v1alpha1/zz_generated.deepcopy.go +++ b/apis/containerservice/v1alpha1/zz_generated.deepcopy.go @@ -53,6 +53,16 @@ func (in *AciConnectorLinuxParameters) DeepCopyInto(out *AciConnectorLinuxParame *out = new(string) **out = **in } + if in.SubnetNameRef != nil { + in, out := &in.SubnetNameRef, &out.SubnetNameRef + *out = new(v1.Reference) + **out = **in + } + if in.SubnetNameSelector != nil { + in, out := &in.SubnetNameSelector, &out.SubnetNameSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AciConnectorLinuxParameters. diff --git a/apis/containerservice/v1alpha1/zz_generated.resolvers.go b/apis/containerservice/v1alpha1/zz_generated.resolvers.go index 16811daec..bce9bb108 100644 --- a/apis/containerservice/v1alpha1/zz_generated.resolvers.go +++ b/apis/containerservice/v1alpha1/zz_generated.resolvers.go @@ -34,6 +34,26 @@ func (mg *KubernetesCluster) ResolveReferences(ctx context.Context, c client.Rea var rsp reference.ResolutionResponse var err error + for i3 := 0; i3 < len(mg.Spec.ForProvider.AddonProfile); i3++ { + for i4 := 0; i4 < len(mg.Spec.ForProvider.AddonProfile[i3].AciConnectorLinux); i4++ { + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.AddonProfile[i3].AciConnectorLinux[i4].SubnetName), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.AddonProfile[i3].AciConnectorLinux[i4].SubnetNameRef, + Selector: mg.Spec.ForProvider.AddonProfile[i3].AciConnectorLinux[i4].SubnetNameSelector, + To: reference.To{ + List: &v1alpha1.SubnetList{}, + Managed: &v1alpha1.Subnet{}, + }, + }) + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.AddonProfile[i3].AciConnectorLinux[i4].SubnetName") + } + mg.Spec.ForProvider.AddonProfile[i3].AciConnectorLinux[i4].SubnetName = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.AddonProfile[i3].AciConnectorLinux[i4].SubnetNameRef = rsp.ResolvedReference + + } + } for i3 := 0; i3 < len(mg.Spec.ForProvider.AddonProfile); i3++ { for i4 := 0; i4 < len(mg.Spec.ForProvider.AddonProfile[i3].IngressApplicationGateway); i4++ { rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ diff --git a/apis/containerservice/v1alpha1/zz_kubernetescluster_types.go b/apis/containerservice/v1alpha1/zz_kubernetescluster_types.go index 074e492be..c850934e9 100755 --- a/apis/containerservice/v1alpha1/zz_kubernetescluster_types.go +++ b/apis/containerservice/v1alpha1/zz_kubernetescluster_types.go @@ -33,8 +33,15 @@ type AciConnectorLinuxParameters struct { // +kubebuilder:validation:Required Enabled *bool `json:"enabled" tf:"enabled,omitempty"` + // +crossplane:generate:reference:type=github.com/crossplane-contrib/provider-jet-azure/apis/network/v1alpha1.Subnet // +kubebuilder:validation:Optional SubnetName *string `json:"subnetName,omitempty" tf:"subnet_name,omitempty"` + + // +kubebuilder:validation:Optional + SubnetNameRef *v1.Reference `json:"subnetNameRef,omitempty" tf:"-"` + + // +kubebuilder:validation:Optional + SubnetNameSelector *v1.Selector `json:"subnetNameSelector,omitempty" tf:"-"` } type AddonProfileObservation struct { diff --git a/apis/iothub/v1alpha1/zz_endpointeventhub_types.go b/apis/iothub/v1alpha1/zz_endpointeventhub_types.go index ec80ea42b..a202d00cb 100755 --- a/apis/iothub/v1alpha1/zz_endpointeventhub_types.go +++ b/apis/iothub/v1alpha1/zz_endpointeventhub_types.go @@ -40,8 +40,15 @@ type EndpointEventhubParameters struct { // +kubebuilder:validation:Required Name *string `json:"name" tf:"name,omitempty"` - // +kubebuilder:validation:Required - ResourceGroupName *string `json:"resourceGroupName" tf:"resource_group_name,omitempty"` + // +crossplane:generate:reference:type=github.com/crossplane-contrib/provider-jet-azure/apis/azure/v1alpha1.ResourceGroup + // +kubebuilder:validation:Optional + ResourceGroupName *string `json:"resourceGroupName,omitempty" tf:"resource_group_name,omitempty"` + + // +kubebuilder:validation:Optional + ResourceGroupNameRef *v1.Reference `json:"resourceGroupNameRef,omitempty" tf:"-"` + + // +kubebuilder:validation:Optional + ResourceGroupNameSelector *v1.Selector `json:"resourceGroupNameSelector,omitempty" tf:"-"` } // EndpointEventhubSpec defines the desired state of EndpointEventhub diff --git a/apis/iothub/v1alpha1/zz_endpointservicebusqueue_types.go b/apis/iothub/v1alpha1/zz_endpointservicebusqueue_types.go index 384824e5d..c2ff38389 100755 --- a/apis/iothub/v1alpha1/zz_endpointservicebusqueue_types.go +++ b/apis/iothub/v1alpha1/zz_endpointservicebusqueue_types.go @@ -40,8 +40,15 @@ type EndpointServicebusQueueParameters struct { // +kubebuilder:validation:Required Name *string `json:"name" tf:"name,omitempty"` - // +kubebuilder:validation:Required - ResourceGroupName *string `json:"resourceGroupName" tf:"resource_group_name,omitempty"` + // +crossplane:generate:reference:type=github.com/crossplane-contrib/provider-jet-azure/apis/azure/v1alpha1.ResourceGroup + // +kubebuilder:validation:Optional + ResourceGroupName *string `json:"resourceGroupName,omitempty" tf:"resource_group_name,omitempty"` + + // +kubebuilder:validation:Optional + ResourceGroupNameRef *v1.Reference `json:"resourceGroupNameRef,omitempty" tf:"-"` + + // +kubebuilder:validation:Optional + ResourceGroupNameSelector *v1.Selector `json:"resourceGroupNameSelector,omitempty" tf:"-"` } // EndpointServicebusQueueSpec defines the desired state of EndpointServicebusQueue diff --git a/apis/iothub/v1alpha1/zz_endpointservicebustopic_types.go b/apis/iothub/v1alpha1/zz_endpointservicebustopic_types.go index 771678ff4..d00a99a3a 100755 --- a/apis/iothub/v1alpha1/zz_endpointservicebustopic_types.go +++ b/apis/iothub/v1alpha1/zz_endpointservicebustopic_types.go @@ -40,8 +40,15 @@ type EndpointServicebusTopicParameters struct { // +kubebuilder:validation:Required Name *string `json:"name" tf:"name,omitempty"` - // +kubebuilder:validation:Required - ResourceGroupName *string `json:"resourceGroupName" tf:"resource_group_name,omitempty"` + // +crossplane:generate:reference:type=github.com/crossplane-contrib/provider-jet-azure/apis/azure/v1alpha1.ResourceGroup + // +kubebuilder:validation:Optional + ResourceGroupName *string `json:"resourceGroupName,omitempty" tf:"resource_group_name,omitempty"` + + // +kubebuilder:validation:Optional + ResourceGroupNameRef *v1.Reference `json:"resourceGroupNameRef,omitempty" tf:"-"` + + // +kubebuilder:validation:Optional + ResourceGroupNameSelector *v1.Selector `json:"resourceGroupNameSelector,omitempty" tf:"-"` } // EndpointServicebusTopicSpec defines the desired state of EndpointServicebusTopic diff --git a/apis/iothub/v1alpha1/zz_endpointstoragecontainer_types.go b/apis/iothub/v1alpha1/zz_endpointstoragecontainer_types.go index f87fd33f9..a6faae70d 100755 --- a/apis/iothub/v1alpha1/zz_endpointstoragecontainer_types.go +++ b/apis/iothub/v1alpha1/zz_endpointstoragecontainer_types.go @@ -55,8 +55,15 @@ type EndpointStorageContainerParameters struct { // +kubebuilder:validation:Required Name *string `json:"name" tf:"name,omitempty"` - // +kubebuilder:validation:Required - ResourceGroupName *string `json:"resourceGroupName" tf:"resource_group_name,omitempty"` + // +crossplane:generate:reference:type=github.com/crossplane-contrib/provider-jet-azure/apis/azure/v1alpha1.ResourceGroup + // +kubebuilder:validation:Optional + ResourceGroupName *string `json:"resourceGroupName,omitempty" tf:"resource_group_name,omitempty"` + + // +kubebuilder:validation:Optional + ResourceGroupNameRef *v1.Reference `json:"resourceGroupNameRef,omitempty" tf:"-"` + + // +kubebuilder:validation:Optional + ResourceGroupNameSelector *v1.Selector `json:"resourceGroupNameSelector,omitempty" tf:"-"` } // EndpointStorageContainerSpec defines the desired state of EndpointStorageContainer diff --git a/apis/iothub/v1alpha1/zz_enrichment_types.go b/apis/iothub/v1alpha1/zz_enrichment_types.go index aa5d0074c..329340959 100755 --- a/apis/iothub/v1alpha1/zz_enrichment_types.go +++ b/apis/iothub/v1alpha1/zz_enrichment_types.go @@ -40,8 +40,15 @@ type EnrichmentParameters_2 struct { // +kubebuilder:validation:Required Key *string `json:"key" tf:"key,omitempty"` - // +kubebuilder:validation:Required - ResourceGroupName *string `json:"resourceGroupName" tf:"resource_group_name,omitempty"` + // +crossplane:generate:reference:type=github.com/crossplane-contrib/provider-jet-azure/apis/azure/v1alpha1.ResourceGroup + // +kubebuilder:validation:Optional + ResourceGroupName *string `json:"resourceGroupName,omitempty" tf:"resource_group_name,omitempty"` + + // +kubebuilder:validation:Optional + ResourceGroupNameRef *v1.Reference `json:"resourceGroupNameRef,omitempty" tf:"-"` + + // +kubebuilder:validation:Optional + ResourceGroupNameSelector *v1.Selector `json:"resourceGroupNameSelector,omitempty" tf:"-"` // +kubebuilder:validation:Required Value *string `json:"value" tf:"value,omitempty"` diff --git a/apis/iothub/v1alpha1/zz_fallbackroute_types.go b/apis/iothub/v1alpha1/zz_fallbackroute_types.go index 8f20b3d31..6686f5c85 100755 --- a/apis/iothub/v1alpha1/zz_fallbackroute_types.go +++ b/apis/iothub/v1alpha1/zz_fallbackroute_types.go @@ -43,8 +43,15 @@ type FallbackRouteParameters_2 struct { // +kubebuilder:validation:Required IothubName *string `json:"iothubName" tf:"iothub_name,omitempty"` - // +kubebuilder:validation:Required - ResourceGroupName *string `json:"resourceGroupName" tf:"resource_group_name,omitempty"` + // +crossplane:generate:reference:type=github.com/crossplane-contrib/provider-jet-azure/apis/azure/v1alpha1.ResourceGroup + // +kubebuilder:validation:Optional + ResourceGroupName *string `json:"resourceGroupName,omitempty" tf:"resource_group_name,omitempty"` + + // +kubebuilder:validation:Optional + ResourceGroupNameRef *v1.Reference `json:"resourceGroupNameRef,omitempty" tf:"-"` + + // +kubebuilder:validation:Optional + ResourceGroupNameSelector *v1.Selector `json:"resourceGroupNameSelector,omitempty" tf:"-"` } // FallbackRouteSpec defines the desired state of FallbackRoute diff --git a/apis/iothub/v1alpha1/zz_generated.deepcopy.go b/apis/iothub/v1alpha1/zz_generated.deepcopy.go index 1be372663..856bda447 100644 --- a/apis/iothub/v1alpha1/zz_generated.deepcopy.go +++ b/apis/iothub/v1alpha1/zz_generated.deepcopy.go @@ -865,6 +865,16 @@ func (in *EndpointEventhubParameters) DeepCopyInto(out *EndpointEventhubParamete *out = new(string) **out = **in } + if in.ResourceGroupNameRef != nil { + in, out := &in.ResourceGroupNameRef, &out.ResourceGroupNameRef + *out = new(v1.Reference) + **out = **in + } + if in.ResourceGroupNameSelector != nil { + in, out := &in.ResourceGroupNameSelector, &out.ResourceGroupNameSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EndpointEventhubParameters. @@ -1100,6 +1110,16 @@ func (in *EndpointServicebusQueueParameters) DeepCopyInto(out *EndpointServicebu *out = new(string) **out = **in } + if in.ResourceGroupNameRef != nil { + in, out := &in.ResourceGroupNameRef, &out.ResourceGroupNameRef + *out = new(v1.Reference) + **out = **in + } + if in.ResourceGroupNameSelector != nil { + in, out := &in.ResourceGroupNameSelector, &out.ResourceGroupNameSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EndpointServicebusQueueParameters. @@ -1244,6 +1264,16 @@ func (in *EndpointServicebusTopicParameters) DeepCopyInto(out *EndpointServicebu *out = new(string) **out = **in } + if in.ResourceGroupNameRef != nil { + in, out := &in.ResourceGroupNameRef, &out.ResourceGroupNameRef + *out = new(v1.Reference) + **out = **in + } + if in.ResourceGroupNameSelector != nil { + in, out := &in.ResourceGroupNameSelector, &out.ResourceGroupNameSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EndpointServicebusTopicParameters. @@ -1413,6 +1443,16 @@ func (in *EndpointStorageContainerParameters) DeepCopyInto(out *EndpointStorageC *out = new(string) **out = **in } + if in.ResourceGroupNameRef != nil { + in, out := &in.ResourceGroupNameRef, &out.ResourceGroupNameRef + *out = new(v1.Reference) + **out = **in + } + if in.ResourceGroupNameSelector != nil { + in, out := &in.ResourceGroupNameSelector, &out.ResourceGroupNameSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EndpointStorageContainerParameters. @@ -1618,6 +1658,16 @@ func (in *EnrichmentParameters_2) DeepCopyInto(out *EnrichmentParameters_2) { *out = new(string) **out = **in } + if in.ResourceGroupNameRef != nil { + in, out := &in.ResourceGroupNameRef, &out.ResourceGroupNameRef + *out = new(v1.Reference) + **out = **in + } + if in.ResourceGroupNameSelector != nil { + in, out := &in.ResourceGroupNameSelector, &out.ResourceGroupNameSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } if in.Value != nil { in, out := &in.Value, &out.Value *out = new(string) @@ -1838,6 +1888,16 @@ func (in *FallbackRouteParameters_2) DeepCopyInto(out *FallbackRouteParameters_2 *out = new(string) **out = **in } + if in.ResourceGroupNameRef != nil { + in, out := &in.ResourceGroupNameRef, &out.ResourceGroupNameRef + *out = new(v1.Reference) + **out = **in + } + if in.ResourceGroupNameSelector != nil { + in, out := &in.ResourceGroupNameSelector, &out.ResourceGroupNameSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FallbackRouteParameters_2. @@ -2489,6 +2549,16 @@ func (in *RouteParameters_2) DeepCopyInto(out *RouteParameters_2) { *out = new(string) **out = **in } + if in.ResourceGroupNameRef != nil { + in, out := &in.ResourceGroupNameRef, &out.ResourceGroupNameRef + *out = new(v1.Reference) + **out = **in + } + if in.ResourceGroupNameSelector != nil { + in, out := &in.ResourceGroupNameSelector, &out.ResourceGroupNameSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } if in.Source != nil { in, out := &in.Source, &out.Source *out = new(string) diff --git a/apis/iothub/v1alpha1/zz_generated.resolvers.go b/apis/iothub/v1alpha1/zz_generated.resolvers.go index 7c016e53a..d87455393 100644 --- a/apis/iothub/v1alpha1/zz_generated.resolvers.go +++ b/apis/iothub/v1alpha1/zz_generated.resolvers.go @@ -178,6 +178,162 @@ func (mg *DPSSharedAccessPolicy) ResolveReferences(ctx context.Context, c client return nil } +// ResolveReferences of this EndpointEventhub. +func (mg *EndpointEventhub) ResolveReferences(ctx context.Context, c client.Reader) error { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.ResourceGroupName), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.ResourceGroupNameRef, + Selector: mg.Spec.ForProvider.ResourceGroupNameSelector, + To: reference.To{ + List: &v1alpha1.ResourceGroupList{}, + Managed: &v1alpha1.ResourceGroup{}, + }, + }) + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.ResourceGroupName") + } + mg.Spec.ForProvider.ResourceGroupName = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.ResourceGroupNameRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this EndpointServicebusQueue. +func (mg *EndpointServicebusQueue) ResolveReferences(ctx context.Context, c client.Reader) error { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.ResourceGroupName), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.ResourceGroupNameRef, + Selector: mg.Spec.ForProvider.ResourceGroupNameSelector, + To: reference.To{ + List: &v1alpha1.ResourceGroupList{}, + Managed: &v1alpha1.ResourceGroup{}, + }, + }) + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.ResourceGroupName") + } + mg.Spec.ForProvider.ResourceGroupName = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.ResourceGroupNameRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this EndpointServicebusTopic. +func (mg *EndpointServicebusTopic) ResolveReferences(ctx context.Context, c client.Reader) error { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.ResourceGroupName), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.ResourceGroupNameRef, + Selector: mg.Spec.ForProvider.ResourceGroupNameSelector, + To: reference.To{ + List: &v1alpha1.ResourceGroupList{}, + Managed: &v1alpha1.ResourceGroup{}, + }, + }) + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.ResourceGroupName") + } + mg.Spec.ForProvider.ResourceGroupName = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.ResourceGroupNameRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this EndpointStorageContainer. +func (mg *EndpointStorageContainer) ResolveReferences(ctx context.Context, c client.Reader) error { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.ResourceGroupName), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.ResourceGroupNameRef, + Selector: mg.Spec.ForProvider.ResourceGroupNameSelector, + To: reference.To{ + List: &v1alpha1.ResourceGroupList{}, + Managed: &v1alpha1.ResourceGroup{}, + }, + }) + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.ResourceGroupName") + } + mg.Spec.ForProvider.ResourceGroupName = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.ResourceGroupNameRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this Enrichment. +func (mg *Enrichment) ResolveReferences(ctx context.Context, c client.Reader) error { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.ResourceGroupName), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.ResourceGroupNameRef, + Selector: mg.Spec.ForProvider.ResourceGroupNameSelector, + To: reference.To{ + List: &v1alpha1.ResourceGroupList{}, + Managed: &v1alpha1.ResourceGroup{}, + }, + }) + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.ResourceGroupName") + } + mg.Spec.ForProvider.ResourceGroupName = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.ResourceGroupNameRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this FallbackRoute. +func (mg *FallbackRoute) ResolveReferences(ctx context.Context, c client.Reader) error { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.ResourceGroupName), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.ResourceGroupNameRef, + Selector: mg.Spec.ForProvider.ResourceGroupNameSelector, + To: reference.To{ + List: &v1alpha1.ResourceGroupList{}, + Managed: &v1alpha1.ResourceGroup{}, + }, + }) + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.ResourceGroupName") + } + mg.Spec.ForProvider.ResourceGroupName = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.ResourceGroupNameRef = rsp.ResolvedReference + + return nil +} + // ResolveReferences of this IOTHub. func (mg *IOTHub) ResolveReferences(ctx context.Context, c client.Reader) error { r := reference.NewAPIResolver(c, mg) @@ -240,6 +396,32 @@ func (mg *IOTHub) ResolveReferences(ctx context.Context, c client.Reader) error return nil } +// ResolveReferences of this Route. +func (mg *Route) ResolveReferences(ctx context.Context, c client.Reader) error { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.ResourceGroupName), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.ResourceGroupNameRef, + Selector: mg.Spec.ForProvider.ResourceGroupNameSelector, + To: reference.To{ + List: &v1alpha1.ResourceGroupList{}, + Managed: &v1alpha1.ResourceGroup{}, + }, + }) + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.ResourceGroupName") + } + mg.Spec.ForProvider.ResourceGroupName = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.ResourceGroupNameRef = rsp.ResolvedReference + + return nil +} + // ResolveReferences of this SharedAccessPolicy. func (mg *SharedAccessPolicy) ResolveReferences(ctx context.Context, c client.Reader) error { r := reference.NewAPIResolver(c, mg) diff --git a/apis/iothub/v1alpha1/zz_route_types.go b/apis/iothub/v1alpha1/zz_route_types.go index bc46ba24f..ee7fd5ab8 100755 --- a/apis/iothub/v1alpha1/zz_route_types.go +++ b/apis/iothub/v1alpha1/zz_route_types.go @@ -46,8 +46,15 @@ type RouteParameters_2 struct { // +kubebuilder:validation:Required Name *string `json:"name" tf:"name,omitempty"` - // +kubebuilder:validation:Required - ResourceGroupName *string `json:"resourceGroupName" tf:"resource_group_name,omitempty"` + // +crossplane:generate:reference:type=github.com/crossplane-contrib/provider-jet-azure/apis/azure/v1alpha1.ResourceGroup + // +kubebuilder:validation:Optional + ResourceGroupName *string `json:"resourceGroupName,omitempty" tf:"resource_group_name,omitempty"` + + // +kubebuilder:validation:Optional + ResourceGroupNameRef *v1.Reference `json:"resourceGroupNameRef,omitempty" tf:"-"` + + // +kubebuilder:validation:Optional + ResourceGroupNameSelector *v1.Selector `json:"resourceGroupNameSelector,omitempty" tf:"-"` // +kubebuilder:validation:Required Source *string `json:"source" tf:"source,omitempty"` diff --git a/apis/network/v1alpha1/zz_generated.deepcopy.go b/apis/network/v1alpha1/zz_generated.deepcopy.go index 286318bf1..d0279e197 100644 --- a/apis/network/v1alpha1/zz_generated.deepcopy.go +++ b/apis/network/v1alpha1/zz_generated.deepcopy.go @@ -347,6 +347,16 @@ func (in *FrontendIPConfigurationParameters) DeepCopyInto(out *FrontendIPConfigu *out = new(string) **out = **in } + if in.SubnetIDRef != nil { + in, out := &in.SubnetIDRef, &out.SubnetIDRef + *out = new(v1.Reference) + **out = **in + } + if in.SubnetIDSelector != nil { + in, out := &in.SubnetIDSelector, &out.SubnetIDSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } if in.Zones != nil { in, out := &in.Zones, &out.Zones *out = make([]*string, len(*in)) diff --git a/apis/network/v1alpha1/zz_generated.resolvers.go b/apis/network/v1alpha1/zz_generated.resolvers.go index 984152eb4..6f074a34c 100644 --- a/apis/network/v1alpha1/zz_generated.resolvers.go +++ b/apis/network/v1alpha1/zz_generated.resolvers.go @@ -33,6 +33,24 @@ func (mg *LoadBalancer) ResolveReferences(ctx context.Context, c client.Reader) var rsp reference.ResolutionResponse var err error + for i3 := 0; i3 < len(mg.Spec.ForProvider.FrontendIPConfiguration); i3++ { + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.FrontendIPConfiguration[i3].SubnetID), + Extract: rconfig.ExtractResourceID(), + Reference: mg.Spec.ForProvider.FrontendIPConfiguration[i3].SubnetIDRef, + Selector: mg.Spec.ForProvider.FrontendIPConfiguration[i3].SubnetIDSelector, + To: reference.To{ + List: &SubnetList{}, + Managed: &Subnet{}, + }, + }) + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.FrontendIPConfiguration[i3].SubnetID") + } + mg.Spec.ForProvider.FrontendIPConfiguration[i3].SubnetID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.FrontendIPConfiguration[i3].SubnetIDRef = rsp.ResolvedReference + + } rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.ResourceGroupName), Extract: reference.ExternalName(), diff --git a/apis/network/v1alpha1/zz_loadbalancer_types.go b/apis/network/v1alpha1/zz_loadbalancer_types.go index a93152f92..22edbc88e 100755 --- a/apis/network/v1alpha1/zz_loadbalancer_types.go +++ b/apis/network/v1alpha1/zz_loadbalancer_types.go @@ -58,9 +58,17 @@ type FrontendIPConfigurationParameters struct { // +kubebuilder:validation:Optional PublicIPPrefixID *string `json:"publicIpPrefixId,omitempty" tf:"public_ip_prefix_id,omitempty"` + // +crossplane:generate:reference:type=Subnet + // +crossplane:generate:reference:extractor=github.com/crossplane-contrib/provider-jet-azure/apis/rconfig.ExtractResourceID() // +kubebuilder:validation:Optional SubnetID *string `json:"subnetId,omitempty" tf:"subnet_id,omitempty"` + // +kubebuilder:validation:Optional + SubnetIDRef *v1.Reference `json:"subnetIdRef,omitempty" tf:"-"` + + // +kubebuilder:validation:Optional + SubnetIDSelector *v1.Selector `json:"subnetIdSelector,omitempty" tf:"-"` + // +kubebuilder:validation:Optional Zones []*string `json:"zones,omitempty" tf:"zones,omitempty"` } diff --git a/config/common/common.go b/config/common/common.go index 14ea5cc5a..cc9c8cc06 100644 --- a/config/common/common.go +++ b/config/common/common.go @@ -20,10 +20,15 @@ import ( "context" "fmt" "path/filepath" + "regexp" "strings" - tjconfig "github.com/crossplane-contrib/terrajet/pkg/config" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/pkg/errors" + + tjconfig "github.com/crossplane-contrib/terrajet/pkg/config" + + "github.com/crossplane-contrib/provider-jet-azure/apis/rconfig" ) const ( @@ -31,6 +36,11 @@ const ( ErrFmtNoAttribute = `"attribute not found: %s` // ErrFmtUnexpectedType is an error string for attribute map values of unexpected type ErrFmtUnexpectedType = `unexpected type for attribute %s: Expecting a string` + + // nameReferenceKind represents name reference kind + nameReferenceKind = "name" + // idReferenceKind represents ID reference kind + idReferenceKind = "id" ) // GetNameFromFullyQualifiedID extracts external-name from Azure ID @@ -93,3 +103,97 @@ func GetFullyQualifiedIDFn(serviceProvider string, keyPairs ...string) tjconfig. return path, nil } } + +// In the regular expressions used when determining the references, we can observe many rules that have common strings. +// Some of these may be more special than others. For example, "ex_subnet$" is a more special case than "subnet$". +// By putting the more specific rules before the general rules in array, processing and capturing the specific +// rules first will be possible. Since there is no fixed index for key-value pairs in maps, it is not possible to place +// rules from specific to general. Therefore, array is used here. +var referenceRules = [][]string{ + {"resource_group$", "/azure/v1alpha1.ResourceGroup"}, + {"subnet$", "/network/v1alpha1.Subnet"}, +} + +// AddCommonReferences adds some common reference fields. +// This is a part of resource generation pipeline. +func AddCommonReferences(r *tjconfig.Resource) error { + return addCommonReferences(r.References, r.TerraformResource, r.ShortGroup, []string{}) +} + +func addCommonReferences(references tjconfig.References, resource *schema.Resource, shortGroup string, nestedFieldNames []string) error { + for fieldName, s := range resource.Schema { + if s.Elem != nil { + e, ok := s.Elem.(*schema.Resource) + if ok { + if err := addCommonReferences(references, e, shortGroup, append(nestedFieldNames, fieldName)); err != nil { + return err + } + continue + } + } + + referenceName := strings.Join(append(nestedFieldNames, fieldName), ".") + referenceNameWithoutKind, referenceKind := splitReferenceKindFromReferenceName(referenceName) + if referenceKind != "" { + referenceType, err := searchReference(referenceNameWithoutKind) + if err != nil { + return err + } + if referenceType != "" { + if references == nil { + references = make(map[string]tjconfig.Reference) + } + if _, ok := references[referenceName]; !ok { + referenceType = prepareReferenceType(shortGroup, referenceType) + addReference(references, referenceKind, referenceName, referenceType) + } + } + } + } + return nil +} + +func splitReferenceKindFromReferenceName(fieldName string) (string, string) { + p := strings.Split(fieldName, "_") + if len(p) < 2 { + return "", "" + } + return strings.Join(p[:len(p)-1], "_"), p[len(p)-1] +} + +func searchReference(fieldName string) (string, error) { + for _, rule := range referenceRules { + r, err := regexp.Compile(rule[0]) + if err != nil { + return "", err + } + if r.MatchString(fieldName) { + return rule[1], nil + } + } + return "", nil +} + +func prepareReferenceType(shortGroup, referenceType string) string { + p := strings.Split(referenceType, "/") + if shortGroup == p[1] { + referenceType = strings.Split(p[2], ".")[1] + } else { + referenceType = rconfig.APISPackagePath + referenceType + } + return referenceType +} + +func addReference(references tjconfig.References, referenceKind, referenceName, referenceType string) { + switch referenceKind { + case nameReferenceKind: + references[referenceName] = tjconfig.Reference{ + Type: referenceType, + } + case idReferenceKind: + references[referenceName] = tjconfig.Reference{ + Type: referenceType, + Extractor: rconfig.ExtractResourceIDFuncPath, + } + } +} diff --git a/config/provider.go b/config/provider.go index a33e25311..a76f61094 100644 --- a/config/provider.go +++ b/config/provider.go @@ -21,6 +21,8 @@ import ( tf "github.com/hashicorp/terraform-provider-azurerm/xpprovider" + "github.com/crossplane-contrib/provider-jet-azure/config/common" + tjconfig "github.com/crossplane-contrib/terrajet/pkg/config" "github.com/crossplane-contrib/provider-jet-azure/config/api" @@ -153,6 +155,15 @@ func GetProvider() *tjconfig.Provider { } pc.ConfigureResources() + + // This function runs after the special configurations were applied. However, if some references were configured in + // the configuration files, the reference generator does not override them. + for _, r := range pc.Resources { + if err := common.AddCommonReferences(r); err != nil { + panic(err) + } + } + return pc } diff --git a/package/crds/containerservice.azure.jet.crossplane.io_kubernetesclusters.yaml b/package/crds/containerservice.azure.jet.crossplane.io_kubernetesclusters.yaml index 3449562e6..bb9399cee 100644 --- a/package/crds/containerservice.azure.jet.crossplane.io_kubernetesclusters.yaml +++ b/package/crds/containerservice.azure.jet.crossplane.io_kubernetesclusters.yaml @@ -72,6 +72,30 @@ spec: type: boolean subnetName: type: string + subnetNameRef: + description: A Reference to a named object. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + subnetNameSelector: + description: A Selector selects an object. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object + with the same controller reference as the selecting + object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with + matching labels is selected. + type: object + type: object required: - enabled type: object diff --git a/package/crds/iothub.azure.jet.crossplane.io_endpointeventhubs.yaml b/package/crds/iothub.azure.jet.crossplane.io_endpointeventhubs.yaml index 909bbcd87..bdf64c027 100644 --- a/package/crds/iothub.azure.jet.crossplane.io_endpointeventhubs.yaml +++ b/package/crds/iothub.azure.jet.crossplane.io_endpointeventhubs.yaml @@ -86,11 +86,33 @@ spec: type: string resourceGroupName: type: string + resourceGroupNameRef: + description: A Reference to a named object. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + resourceGroupNameSelector: + description: A Selector selects an object. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + type: object required: - connectionStringSecretRef - iothubName - name - - resourceGroupName type: object providerConfigRef: default: diff --git a/package/crds/iothub.azure.jet.crossplane.io_endpointservicebusqueues.yaml b/package/crds/iothub.azure.jet.crossplane.io_endpointservicebusqueues.yaml index 7cc3d3a2c..774a39398 100644 --- a/package/crds/iothub.azure.jet.crossplane.io_endpointservicebusqueues.yaml +++ b/package/crds/iothub.azure.jet.crossplane.io_endpointservicebusqueues.yaml @@ -88,11 +88,33 @@ spec: type: string resourceGroupName: type: string + resourceGroupNameRef: + description: A Reference to a named object. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + resourceGroupNameSelector: + description: A Selector selects an object. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + type: object required: - connectionStringSecretRef - iothubName - name - - resourceGroupName type: object providerConfigRef: default: diff --git a/package/crds/iothub.azure.jet.crossplane.io_endpointservicebustopics.yaml b/package/crds/iothub.azure.jet.crossplane.io_endpointservicebustopics.yaml index 0b0252b9e..8e57abe64 100644 --- a/package/crds/iothub.azure.jet.crossplane.io_endpointservicebustopics.yaml +++ b/package/crds/iothub.azure.jet.crossplane.io_endpointservicebustopics.yaml @@ -88,11 +88,33 @@ spec: type: string resourceGroupName: type: string + resourceGroupNameRef: + description: A Reference to a named object. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + resourceGroupNameSelector: + description: A Selector selects an object. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + type: object required: - connectionStringSecretRef - iothubName - name - - resourceGroupName type: object providerConfigRef: default: diff --git a/package/crds/iothub.azure.jet.crossplane.io_endpointstoragecontainers.yaml b/package/crds/iothub.azure.jet.crossplane.io_endpointstoragecontainers.yaml index 8dffa902e..bfdeb3761 100644 --- a/package/crds/iothub.azure.jet.crossplane.io_endpointstoragecontainers.yaml +++ b/package/crds/iothub.azure.jet.crossplane.io_endpointstoragecontainers.yaml @@ -100,12 +100,34 @@ spec: type: string resourceGroupName: type: string + resourceGroupNameRef: + description: A Reference to a named object. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + resourceGroupNameSelector: + description: A Selector selects an object. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + type: object required: - connectionStringSecretRef - containerName - iothubName - name - - resourceGroupName type: object providerConfigRef: default: diff --git a/package/crds/iothub.azure.jet.crossplane.io_enrichments.yaml b/package/crds/iothub.azure.jet.crossplane.io_enrichments.yaml index 4ca4cdef8..45905ebaa 100644 --- a/package/crds/iothub.azure.jet.crossplane.io_enrichments.yaml +++ b/package/crds/iothub.azure.jet.crossplane.io_enrichments.yaml @@ -72,13 +72,35 @@ spec: type: string resourceGroupName: type: string + resourceGroupNameRef: + description: A Reference to a named object. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + resourceGroupNameSelector: + description: A Selector selects an object. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + type: object value: type: string required: - endpointNames - iothubName - key - - resourceGroupName - value type: object providerConfigRef: diff --git a/package/crds/iothub.azure.jet.crossplane.io_fallbackroutes.yaml b/package/crds/iothub.azure.jet.crossplane.io_fallbackroutes.yaml index d9ddaad45..56054ca25 100644 --- a/package/crds/iothub.azure.jet.crossplane.io_fallbackroutes.yaml +++ b/package/crds/iothub.azure.jet.crossplane.io_fallbackroutes.yaml @@ -74,11 +74,33 @@ spec: type: string resourceGroupName: type: string + resourceGroupNameRef: + description: A Reference to a named object. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + resourceGroupNameSelector: + description: A Selector selects an object. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + type: object required: - enabled - endpointNames - iothubName - - resourceGroupName type: object providerConfigRef: default: diff --git a/package/crds/iothub.azure.jet.crossplane.io_routes.yaml b/package/crds/iothub.azure.jet.crossplane.io_routes.yaml index 7deb4b1d3..b2d326fb1 100644 --- a/package/crds/iothub.azure.jet.crossplane.io_routes.yaml +++ b/package/crds/iothub.azure.jet.crossplane.io_routes.yaml @@ -76,6 +76,29 @@ spec: type: string resourceGroupName: type: string + resourceGroupNameRef: + description: A Reference to a named object. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + resourceGroupNameSelector: + description: A Selector selects an object. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + type: object source: type: string required: @@ -83,7 +106,6 @@ spec: - endpointNames - iothubName - name - - resourceGroupName - source type: object providerConfigRef: diff --git a/package/crds/network.azure.jet.crossplane.io_loadbalancers.yaml b/package/crds/network.azure.jet.crossplane.io_loadbalancers.yaml index e7b960568..7f157af94 100644 --- a/package/crds/network.azure.jet.crossplane.io_loadbalancers.yaml +++ b/package/crds/network.azure.jet.crossplane.io_loadbalancers.yaml @@ -81,6 +81,30 @@ spec: type: string subnetId: type: string + subnetIdRef: + description: A Reference to a named object. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + subnetIdSelector: + description: A Selector selects an object. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with + the same controller reference as the selecting object + is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching + labels is selected. + type: object + type: object zones: items: type: string