Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"os"
"path/filepath"

"github.com/crossplane-contrib/terrajet/pkg/config"

"github.com/crossplane-contrib/terrajet/pkg/terraform"

"github.com/crossplane/crossplane-runtime/pkg/logging"
Expand All @@ -29,6 +31,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/crossplane-contrib/provider-tf-aws/apis"
_ "github.com/crossplane-contrib/provider-tf-aws/config"
"github.com/crossplane-contrib/provider-tf-aws/internal/clients"
"github.com/crossplane-contrib/provider-tf-aws/internal/controller"
)
Expand Down Expand Up @@ -65,7 +68,7 @@ func main() {
SyncPeriod: syncPeriod,
})
kingpin.FatalIfError(err, "Cannot create controller manager")
ws := terraform.NewWorkspaceStore(log)
ws := terraform.NewWorkspaceStore(&config.Store, log)
setup := clients.TerraformSetupBuilder(*terraformVersion, *providerSource, *providerVersion)

rl := ratelimiter.NewGlobal(ratelimiter.DefaultGlobalRPS)
Expand Down
14 changes: 3 additions & 11 deletions config/autoscaling/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ import (

func init() {
config.Store.SetForResource("aws_autoscaling_group", config.Resource{
Kind: "AutoscalingGroup",
ExternalName: config.ExternalName{
ConfigureFunctionPath: common.PathExternalNameAsName,
OmittedFields: []string{
"name",
"name_prefix",
},
},
Kind: "AutoscalingGroup",
ExternalName: config.NameAsIdentifier,
References: map[string]config.Reference{
"vpc_zone_identifier": {
Type: "github.com/crossplane-contrib/provider-tf-aws/apis/ec2/v1alpha1.Subnet",
Expand All @@ -27,9 +21,7 @@ func init() {
UseAsync: true,
})
config.Store.SetForResource("aws_autoscaling_attachment", config.Resource{
ExternalName: config.ExternalName{
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"autoscaling_group_name": {
Type: "AutoscalingGroup",
Expand Down
8 changes: 0 additions & 8 deletions config/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,11 @@ const (
)

var (
// PathExternalNameAsName is the golang path to ExternalNameAsName function
// in this package.
PathExternalNameAsName = SelfPackagePath + ".ExternalNameAsName"
// PathARNExtractor is the golang path to ARNExtractor function
// in this package.
PathARNExtractor = SelfPackagePath + ".ARNExtractor()"
)

// ExternalNameAsName is used by the resources whose schema includes a name field.
func ExternalNameAsName(base map[string]interface{}, externalName string) {
base["name"] = externalName
}

// ARNExtractor extracts ARN of the resources from "status.atProvider.arn" which
// is quite common among all AWS resources.
func ARNExtractor() reference.ExtractValueFn {
Expand Down
9 changes: 4 additions & 5 deletions config/ebs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ limitations under the License.

package ebs

import "github.com/crossplane-contrib/terrajet/pkg/config"
import (
"github.com/crossplane-contrib/terrajet/pkg/config"
)

func init() {
config.Store.SetForResource("aws_ebs_volume", config.Resource{
ExternalName: config.ExternalName{
// Set to true explicitly since the value is calculated by AWS.
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"kms_key_id": {
Type: "github.com/crossplane-contrib/provider-tf-aws/apis/kms/v1alpha1.Key",
Expand Down
98 changes: 24 additions & 74 deletions config/ec2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import (

func init() {
config.Store.SetForResource("aws_instance", config.Resource{
ExternalName: config.ExternalName{
// Set to true explicitly since the value is calculated by AWS.
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"subnet_id": {
Type: "Subnet",
Expand Down Expand Up @@ -60,10 +57,8 @@ func init() {
},
})
config.Store.SetForResource("aws_eip", config.Resource{
Kind: "ElasticIP",
ExternalName: config.ExternalName{
DisableNameInitializer: true,
},
Kind: "ElasticIP",
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"instance": {
Type: "Instance",
Expand All @@ -74,15 +69,11 @@ func init() {
})

config.Store.SetForResource("aws_ec2_transit_gateway", config.Resource{
ExternalName: config.ExternalName{
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
})

config.Store.SetForResource("aws_ec2_transit_gateway_route", config.Resource{
ExternalName: config.ExternalName{
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"transit_gateway_attachment_id": {
Type: "TransitGatewayVpcAttachment",
Expand All @@ -94,19 +85,15 @@ func init() {
})

config.Store.SetForResource("aws_ec2_transit_gateway_route_table", config.Resource{
ExternalName: config.ExternalName{
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"transit_gateway_id": {
Type: "TransitGateway",
},
},
})
config.Store.SetForResource("aws_ec2_transit_gateway_route_table_association", config.Resource{
ExternalName: config.ExternalName{
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"transit_gateway_attachment_id": {
Type: "TransitGatewayVpcAttachment",
Expand All @@ -117,9 +104,7 @@ func init() {
},
})
config.Store.SetForResource("aws_ec2_transit_gateway_vpc_attachment", config.Resource{
ExternalName: config.ExternalName{
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"subnet_ids": {
Type: "Subnet",
Expand All @@ -133,9 +118,7 @@ func init() {
},
})
config.Store.SetForResource("aws_ec2_transit_gateway_vpc_attachment_accepter", config.Resource{
ExternalName: config.ExternalName{
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"transit_gateway_attachment_id": {
Type: "TransitGatewayVpcAttachment",
Expand All @@ -151,9 +134,7 @@ func init() {
// LaunchTemplateParameters
Kind: "EC2LaunchTemplate",

ExternalName: config.ExternalName{
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,

References: map[string]config.Reference{
"security_group_names": {
Expand Down Expand Up @@ -184,17 +165,11 @@ func init() {
},
})
config.Store.SetForResource("aws_vpc", config.Resource{
Kind: "VPC",
ExternalName: config.ExternalName{
// Set to true explicitly since the value is calculated by AWS.
DisableNameInitializer: true,
},
Kind: "VPC",
ExternalName: config.IdentifierFromProvider,
})
config.Store.SetForResource("aws_vpc_endpoint", config.Resource{
ExternalName: config.ExternalName{
// Set to true explicitly since the value is calculated by AWS.
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"vpc_id": {
Type: "VPC",
Expand All @@ -211,10 +186,7 @@ func init() {
},
})
config.Store.SetForResource("aws_subnet", config.Resource{
ExternalName: config.ExternalName{
// Set to true explicitly since the value is calculated by AWS.
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"vpc_id": {
Type: "VPC",
Expand All @@ -229,11 +201,8 @@ func init() {
},
})
config.Store.SetForResource("aws_network_interface", config.Resource{
Kind: "EC2NetworkInterface",
ExternalName: config.ExternalName{
// Set to true explicitly since the value is calculated by AWS.
DisableNameInitializer: true,
},
Kind: "EC2NetworkInterface",
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"vpc_id": {
Type: "VPC",
Expand All @@ -255,10 +224,7 @@ func init() {
},
})
config.Store.SetForResource("aws_security_group", config.Resource{
ExternalName: config.ExternalName{
// Set to true explicitly since the value is calculated by AWS.
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"vpc_id": {
Type: "VPC",
Expand All @@ -272,22 +238,16 @@ func init() {
},
})
config.Store.SetForResource("aws_vpc_ipv4_cidr_block_association", config.Resource{
Kind: "IPv4CIDRBlockAssociation",
ExternalName: config.ExternalName{
// Set to true explicitly since the value is calculated by AWS.
DisableNameInitializer: true,
},
Kind: "IPv4CIDRBlockAssociation",
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"vpc_id": {
Type: "VPC",
},
},
})
config.Store.SetForResource("aws_vpc_peering_connection", config.Resource{
ExternalName: config.ExternalName{
// Set to true explicitly since the value is calculated by AWS.
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"vpc_id": {
Type: "VPC",
Expand All @@ -298,9 +258,7 @@ func init() {
},
})
config.Store.SetForResource("aws_route", config.Resource{
ExternalName: config.ExternalName{
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"route_table_id": {
Type: "RouteTable",
Expand All @@ -324,10 +282,7 @@ func init() {
UseAsync: true,
})
config.Store.SetForResource("aws_route_table", config.Resource{
ExternalName: config.ExternalName{
// Set to true explicitly since the value is calculated by AWS.
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"vpc_id": {
Type: "VPC",
Expand All @@ -347,10 +302,7 @@ func init() {
},
})
config.Store.SetForResource("aws_route_table_association", config.Resource{
ExternalName: config.ExternalName{
// Set to true explicitly since the value is calculated by AWS.
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"subnet_id": {
Type: "Subnet",
Expand All @@ -361,9 +313,7 @@ func init() {
},
})
config.Store.SetForResource("aws_ec2_transit_gateway_route_table_propagation", config.Resource{
ExternalName: config.ExternalName{
DisableNameInitializer: true,
},
ExternalName: config.IdentifierFromProvider,
References: map[string]config.Reference{
"transit_gateway_attachment_id": {
Type: "TransitGatewayVpcAttachment",
Expand Down
22 changes: 4 additions & 18 deletions config/ecr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,10 @@ import (
"github.com/crossplane-contrib/provider-tf-aws/config/common"
)

const (
// SelfPackagePath is the golang path for this package.
SelfPackagePath = "github.com/crossplane-contrib/provider-tf-aws/config/ecr"
)

// PublicRepositoryExternalName is used to set repository name from external name
func PublicRepositoryExternalName(base map[string]interface{}, externalName string) {
base["repository_name"] = externalName
}

func init() {

config.Store.SetForResource("aws_ecr_repository", config.Resource{
ExternalName: config.ExternalName{
ConfigureFunctionPath: common.PathExternalNameAsName,
OmittedFields: []string{
"name",
},
},

ExternalName: config.NameAsIdentifier,
References: map[string]config.Reference{
"encryption_configuration[*].kms_key": {
Type: "github.com/crossplane-contrib/provider-tf-aws/apis/kms/v1alpha1.Key",
Expand All @@ -41,7 +25,9 @@ func init() {

config.Store.SetForResource("aws_ecrpublic_repository", config.Resource{
ExternalName: config.ExternalName{
ConfigureFunctionPath: SelfPackagePath + ".PublicRepositoryExternalName",
SetIdentifierArgumentFn: func(base map[string]interface{}, name string) {
base["repository_name"] = name
},
OmittedFields: []string{
"repository_name",
},
Expand Down
Loading