-
Notifications
You must be signed in to change notification settings - Fork 134
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
feat(provider): add octavia loadbalancer log subscription #637
Draft
Rom123Soleil
wants to merge
1
commit into
ovh:master
Choose a base branch
from
Rom123Soleil:dev/add-loadbalancer-log-subscription
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
ovh/data_cloud_project_region_loadbalancer_log_subscription.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package ovh | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"log" | ||
"net/url" | ||
) | ||
|
||
func dataSourceCloudProjectRegionLoadbalancerLogSubscription() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceCloudProjectRegionLoadbalancerSubscriptionRead, | ||
Schema: map[string]*schema.Schema{ | ||
"service_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil), | ||
Description: "Service name of the resource representing the id of the cloud project.", | ||
}, | ||
"region_name": { | ||
Type: schema.TypeString, | ||
Description: "Region name of the resource representing the name of the region.", | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"loadbalancer_id": { | ||
Type: schema.TypeString, | ||
Description: "ID representing the loadbalancer of the resource", | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"subscription_id": { | ||
Type: schema.TypeString, | ||
Description: "ID representing the subscription", | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
//computed | ||
"created_at": { | ||
Type: schema.TypeString, | ||
Description: "Creation date of the subscription", | ||
Computed: true, | ||
}, | ||
"kind": { | ||
Type: schema.TypeString, | ||
Description: "Log kind name of this subscription", | ||
Computed: true, | ||
}, | ||
"ldp_service_name": { | ||
Type: schema.TypeString, | ||
Description: "Name of the destination log service", | ||
//Sensitive: true, | ||
Computed: true, | ||
}, | ||
"resource_name": { | ||
Type: schema.TypeString, | ||
Description: "Name of subscribed resource, where the logs come from", | ||
Computed: true, | ||
}, | ||
"resource_type": { | ||
Type: schema.TypeString, | ||
Description: "Type of subscribed resource, where the logs come from", | ||
Computed: true, | ||
}, | ||
"stream_id": { | ||
Type: schema.TypeString, | ||
Description: "Id of the target Log data platform stream", | ||
Computed: true, | ||
}, | ||
"updated_at": { | ||
Type: schema.TypeString, | ||
Description: "Last update date of the subscription", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCloudProjectRegionLoadbalancerSubscriptionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
config := meta.(*Config) | ||
serviceName := d.Get("service_name").(string) | ||
regionName := d.Get("region_name").(string) | ||
loadbalancerID := d.Get("loadbalancer_id").(string) | ||
subscriptionID := d.Get("subscription_id").(string) | ||
|
||
log.Printf("[DEBUG] Will read public cloud loadbalancer %s log subscription %s for region %s for project: %s", loadbalancerID, subscriptionID, regionName, serviceName) | ||
|
||
response := &CloudProjectRegionLoadbalancerLogSubscriptionResponse{} | ||
endpoint := fmt.Sprintf( | ||
"/cloud/project/%s/region/%s/loadbalancing/loadbalancer/%s/log/subscription/%s", | ||
url.PathEscape(serviceName), | ||
url.PathEscape(regionName), | ||
url.PathEscape(loadbalancerID), | ||
url.PathEscape(subscriptionID), | ||
) | ||
|
||
if err := config.OVHClient.Get(endpoint, &response); err != nil { | ||
return diag.Errorf("Error calling GET %s:\n\t %q", endpoint, err) | ||
} | ||
|
||
d.SetId(response.StreamID) | ||
d.Set("created_at", response.CreatedAt) | ||
d.Set("kind", response.Kind) | ||
d.Set("resource_name", response.Resource.Name) | ||
d.Set("resource_type", response.Resource.Type) | ||
d.Set("ldp_service_name", response.LDPServiceName) | ||
d.Set("stream_id", response.StreamID) | ||
d.Set("updated_at", response.UpdatedAt) | ||
return nil | ||
} |
1 change: 1 addition & 0 deletions
1
ovh/data_cloud_project_region_loadbalancer_log_subscription_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package ovh | ||
77 changes: 77 additions & 0 deletions
77
ovh/data_cloud_project_region_loadbalancer_log_subscriptions.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package ovh | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/ovh/terraform-provider-ovh/ovh/helpers/hashcode" | ||
"log" | ||
"net/url" | ||
"sort" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceCloudProjectRegionLoadbalancerLogSubscriptions() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceCloudProjectRegionLoadbalancerSubscriptionsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"service_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil), | ||
Description: "Service name of the resource representing the id of the cloud project.", | ||
}, | ||
"region_name": { | ||
Type: schema.TypeString, | ||
Description: "Region name of the resource representing the name of the region.", | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"loadbalancer_id": { | ||
Type: schema.TypeString, | ||
Description: "ID representing the loadbalancer of the resource", | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"kind": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Kind representing the loadbalancer.", | ||
}, | ||
//computed | ||
"subscription_ids": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCloudProjectRegionLoadbalancerSubscriptionsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
config := meta.(*Config) | ||
serviceName := d.Get("service_name").(string) | ||
regionName := d.Get("region_name").(string) | ||
loadbalancerID := d.Get("loadbalancer_id").(string) | ||
|
||
log.Printf("[DEBUG] Will read public cloud loadbalancer %s log subscriptions for region %s for project: %s", loadbalancerID, regionName, serviceName) | ||
|
||
response := make([]string, 0) | ||
endpoint := fmt.Sprintf( | ||
"/cloud/project/%s/region/%s/loadbalancing/loadbalancer/%s/log/subscription", | ||
url.PathEscape(serviceName), | ||
url.PathEscape(regionName), | ||
url.PathEscape(loadbalancerID), | ||
) | ||
|
||
if err := config.OVHClient.Get(endpoint, &response); err != nil { | ||
return diag.Errorf("Error calling GET %s:\n\t %q", endpoint, err) | ||
} | ||
sort.Strings(response) | ||
|
||
d.SetId(hashcode.Strings(response)) | ||
d.Set("subscription_ids", response) | ||
return nil | ||
} |
1 change: 1 addition & 0 deletions
1
ovh/data_cloud_project_region_loadbalancer_log_subscriptions_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package ovh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you have to fill these