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

Feature/add project shared vpc resources selectors #210

Merged
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
30 changes: 30 additions & 0 deletions apis/compute/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions apis/compute/v1beta1/zz_generated.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions apis/compute/v1beta1/zz_sharedvpchostproject_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions apis/compute/v1beta1/zz_sharedvpcserviceproject_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions config/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (

// ExtractResourceIDFuncPath holds the GCP resource ID extractor func name
ExtractResourceIDFuncPath = "github.com/upbound/provider-gcp/config/common.ExtractResourceID()"
ExtractProjectIDFuncPath = "github.com/upbound/provider-gcp/config/common.ExtractProjectID()"
)

var (
Expand Down Expand Up @@ -74,3 +75,13 @@ func ExtractResourceID() reference.ExtractValueFn {
return tr.GetID()
}
}

func ExtractProjectID() reference.ExtractValueFn {
return func(mr resource.Managed) string {
tr, ok := mr.(jresource.Terraformed)
if !ok {
return ""
}
return strings.TrimPrefix(tr.GetID(), "projects/")
}
}
18 changes: 18 additions & 0 deletions config/compute/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ func Configure(p *config.Provider) { //nolint: gocyclo
}
})

p.AddResourceConfigurator("google_compute_shared_vpc_host_project", func(r *config.Resource) {
r.References["project"] = config.Reference{
Type: "github.com/upbound/provider-gcp/apis/cloudplatform/v1beta1.Project",
Extractor: common.ExtractProjectIDFuncPath,
}
})

p.AddResourceConfigurator("google_compute_shared_vpc_service_project", func(r *config.Resource) {
r.References["host_project"] = config.Reference{
Type: "github.com/upbound/provider-gcp/apis/cloudplatform/v1beta1.Project",
Extractor: common.ExtractProjectIDFuncPath,
}
r.References["service_project"] = config.Reference{
Type: "github.com/upbound/provider-gcp/apis/cloudplatform/v1beta1.Project",
Extractor: common.ExtractProjectIDFuncPath,
}
})

p.AddResourceConfigurator("google_compute_subnetwork", func(r *config.Resource) {
r.References["network"] = config.Reference{
Type: "Network",
Expand Down
20 changes: 15 additions & 5 deletions examples-generated/compute/sharedvpchostproject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ metadata:
name: host
spec:
forProvider:
project: host-project-id
projectSelector:
matchLabels:
testing.upbound.io/example-name: example

---

Expand All @@ -22,8 +24,12 @@ metadata:
name: service1
spec:
forProvider:
hostProject: host-project-id
serviceProject: service-project-id-1
hostProjectSelector:
matchLabels:
testing.upbound.io/example-name: host
serviceProjectSelector:
matchLabels:
testing.upbound.io/example-name: example

---

Expand All @@ -37,8 +43,12 @@ metadata:
name: service2
spec:
forProvider:
hostProject: host-project-id
serviceProject: service-project-id-2
hostProjectSelector:
matchLabels:
testing.upbound.io/example-name: host
serviceProjectSelector:
matchLabels:
testing.upbound.io/example-name: example

---

8 changes: 6 additions & 2 deletions examples-generated/compute/sharedvpcserviceproject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ metadata:
name: service1
spec:
forProvider:
hostProject: host-project-id
serviceProject: service-project-id-1
hostProjectSelector:
matchLabels:
testing.upbound.io/example-name: example
serviceProjectSelector:
matchLabels:
testing.upbound.io/example-name: example

---

3 changes: 1 addition & 2 deletions examples/compute/sharedvpchostproject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ kind: SharedVPCHostProject
metadata:
annotations:
meta.upbound.io/example-id: compute/v1beta1/sharedvpchostproject
upjet.upbound.io/manual-intervention: "Required organizational level permissions"
labels:
testing.upbound.io/example-name: host
name: host
spec:
forProvider:
project: host-project-id
project: ${data.cloudplatform_project.projectId}

---

Expand Down
8 changes: 5 additions & 3 deletions examples/compute/sharedvpcserviceproject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ kind: SharedVPCServiceProject
metadata:
annotations:
meta.upbound.io/example-id: compute/v1beta1/sharedvpcserviceproject
upjet.upbound.io/manual-intervention: "Only supports this permission at project or organizational level currently"
upjet.upbound.io/manual-intervention: "This resource depends on an existed service project"
labels:
testing.upbound.io/example-name: service1
name: service1
spec:
forProvider:
hostProject: host-project-id
serviceProject: service-project-id-1
hostProject: ${data.cloudplatform_project.projectId}
serviceProjectSelector:
matchLabels:
testing.upbound.io/example-name: example
Loading