-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
80e1205
commit 3e70289
Showing
10 changed files
with
1,351 additions
and
2 deletions.
There are no files selected for viewing
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,6 @@ | ||
```release-note:new-resource | ||
`google_compute_public_advertised_prefix` | ||
``` | ||
```release-note:new-resource | ||
`google_compute_public_delegated_prefix` | ||
``` |
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
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
313 changes: 313 additions & 0 deletions
313
google-beta/resource_compute_public_advertised_prefix.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,313 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package google | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"reflect" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func ResourceComputePublicAdvertisedPrefix() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceComputePublicAdvertisedPrefixCreate, | ||
Read: resourceComputePublicAdvertisedPrefixRead, | ||
Delete: resourceComputePublicAdvertisedPrefixDelete, | ||
|
||
Importer: &schema.ResourceImporter{ | ||
State: resourceComputePublicAdvertisedPrefixImport, | ||
}, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(20 * time.Minute), | ||
Delete: schema.DefaultTimeout(20 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"dns_verification_ip": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: `The IPv4 address to be used for reverse DNS verification.`, | ||
}, | ||
"ip_cidr_range": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: `The IPv4 address range, in CIDR format, represented by this public advertised prefix.`, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: `Name of the resource. The name must be 1-63 characters long, and | ||
comply with RFC1035. Specifically, the name must be 1-63 characters | ||
long and match the regular expression '[a-z]([-a-z0-9]*[a-z0-9])?' | ||
which means the first character must be a lowercase letter, and all | ||
following characters must be a dash, lowercase letter, or digit, | ||
except the last character, which cannot be a dash.`, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
Description: `An optional description of this resource.`, | ||
}, | ||
"project": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
"self_link": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
UseJSONNumber: true, | ||
} | ||
} | ||
|
||
func resourceComputePublicAdvertisedPrefixCreate(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
userAgent, err := generateUserAgentString(d, config.UserAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
obj := make(map[string]interface{}) | ||
descriptionProp, err := expandComputePublicAdvertisedPrefixDescription(d.Get("description"), d, config) | ||
if err != nil { | ||
return err | ||
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { | ||
obj["description"] = descriptionProp | ||
} | ||
nameProp, err := expandComputePublicAdvertisedPrefixName(d.Get("name"), d, config) | ||
if err != nil { | ||
return err | ||
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { | ||
obj["name"] = nameProp | ||
} | ||
dnsVerificationIpProp, err := expandComputePublicAdvertisedPrefixDnsVerificationIp(d.Get("dns_verification_ip"), d, config) | ||
if err != nil { | ||
return err | ||
} else if v, ok := d.GetOkExists("dns_verification_ip"); !isEmptyValue(reflect.ValueOf(dnsVerificationIpProp)) && (ok || !reflect.DeepEqual(v, dnsVerificationIpProp)) { | ||
obj["dnsVerificationIp"] = dnsVerificationIpProp | ||
} | ||
ipCidrRangeProp, err := expandComputePublicAdvertisedPrefixIpCidrRange(d.Get("ip_cidr_range"), d, config) | ||
if err != nil { | ||
return err | ||
} else if v, ok := d.GetOkExists("ip_cidr_range"); !isEmptyValue(reflect.ValueOf(ipCidrRangeProp)) && (ok || !reflect.DeepEqual(v, ipCidrRangeProp)) { | ||
obj["ipCidrRange"] = ipCidrRangeProp | ||
} | ||
|
||
url, err := ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/publicAdvertisedPrefixes") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] Creating new PublicAdvertisedPrefix: %#v", obj) | ||
billingProject := "" | ||
|
||
project, err := getProject(d, config) | ||
if err != nil { | ||
return fmt.Errorf("Error fetching project for PublicAdvertisedPrefix: %s", err) | ||
} | ||
billingProject = project | ||
|
||
// err == nil indicates that the billing_project value was found | ||
if bp, err := getBillingProject(d, config); err == nil { | ||
billingProject = bp | ||
} | ||
|
||
res, err := SendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate)) | ||
if err != nil { | ||
return fmt.Errorf("Error creating PublicAdvertisedPrefix: %s", err) | ||
} | ||
|
||
// Store the ID now | ||
id, err := ReplaceVars(d, config, "projects/{{project}}/global/publicAdvertisedPrefixes/{{name}}") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
err = ComputeOperationWaitTime( | ||
config, res, project, "Creating PublicAdvertisedPrefix", userAgent, | ||
d.Timeout(schema.TimeoutCreate)) | ||
|
||
if err != nil { | ||
// The resource didn't actually create | ||
d.SetId("") | ||
return fmt.Errorf("Error waiting to create PublicAdvertisedPrefix: %s", err) | ||
} | ||
|
||
log.Printf("[DEBUG] Finished creating PublicAdvertisedPrefix %q: %#v", d.Id(), res) | ||
|
||
return resourceComputePublicAdvertisedPrefixRead(d, meta) | ||
} | ||
|
||
func resourceComputePublicAdvertisedPrefixRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
userAgent, err := generateUserAgentString(d, config.UserAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
url, err := ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/publicAdvertisedPrefixes/{{name}}") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
billingProject := "" | ||
|
||
project, err := getProject(d, config) | ||
if err != nil { | ||
return fmt.Errorf("Error fetching project for PublicAdvertisedPrefix: %s", err) | ||
} | ||
billingProject = project | ||
|
||
// err == nil indicates that the billing_project value was found | ||
if bp, err := getBillingProject(d, config); err == nil { | ||
billingProject = bp | ||
} | ||
|
||
res, err := SendRequest(config, "GET", billingProject, url, userAgent, nil) | ||
if err != nil { | ||
return handleNotFoundError(err, d, fmt.Sprintf("ComputePublicAdvertisedPrefix %q", d.Id())) | ||
} | ||
|
||
if err := d.Set("project", project); err != nil { | ||
return fmt.Errorf("Error reading PublicAdvertisedPrefix: %s", err) | ||
} | ||
|
||
if err := d.Set("description", flattenComputePublicAdvertisedPrefixDescription(res["description"], d, config)); err != nil { | ||
return fmt.Errorf("Error reading PublicAdvertisedPrefix: %s", err) | ||
} | ||
if err := d.Set("name", flattenComputePublicAdvertisedPrefixName(res["name"], d, config)); err != nil { | ||
return fmt.Errorf("Error reading PublicAdvertisedPrefix: %s", err) | ||
} | ||
if err := d.Set("dns_verification_ip", flattenComputePublicAdvertisedPrefixDnsVerificationIp(res["dnsVerificationIp"], d, config)); err != nil { | ||
return fmt.Errorf("Error reading PublicAdvertisedPrefix: %s", err) | ||
} | ||
if err := d.Set("ip_cidr_range", flattenComputePublicAdvertisedPrefixIpCidrRange(res["ipCidrRange"], d, config)); err != nil { | ||
return fmt.Errorf("Error reading PublicAdvertisedPrefix: %s", err) | ||
} | ||
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil { | ||
return fmt.Errorf("Error reading PublicAdvertisedPrefix: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceComputePublicAdvertisedPrefixDelete(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
userAgent, err := generateUserAgentString(d, config.UserAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
billingProject := "" | ||
|
||
project, err := getProject(d, config) | ||
if err != nil { | ||
return fmt.Errorf("Error fetching project for PublicAdvertisedPrefix: %s", err) | ||
} | ||
billingProject = project | ||
|
||
url, err := ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/publicAdvertisedPrefixes/{{name}}") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var obj map[string]interface{} | ||
log.Printf("[DEBUG] Deleting PublicAdvertisedPrefix %q", d.Id()) | ||
|
||
// err == nil indicates that the billing_project value was found | ||
if bp, err := getBillingProject(d, config); err == nil { | ||
billingProject = bp | ||
} | ||
|
||
res, err := SendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete)) | ||
if err != nil { | ||
return handleNotFoundError(err, d, "PublicAdvertisedPrefix") | ||
} | ||
|
||
err = ComputeOperationWaitTime( | ||
config, res, project, "Deleting PublicAdvertisedPrefix", userAgent, | ||
d.Timeout(schema.TimeoutDelete)) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] Finished deleting PublicAdvertisedPrefix %q: %#v", d.Id(), res) | ||
return nil | ||
} | ||
|
||
func resourceComputePublicAdvertisedPrefixImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { | ||
config := meta.(*Config) | ||
if err := ParseImportId([]string{ | ||
"projects/(?P<project>[^/]+)/global/publicAdvertisedPrefixes/(?P<name>[^/]+)", | ||
"(?P<project>[^/]+)/(?P<name>[^/]+)", | ||
"(?P<name>[^/]+)", | ||
}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Replace import id for the resource id | ||
id, err := ReplaceVars(d, config, "projects/{{project}}/global/publicAdvertisedPrefixes/{{name}}") | ||
if err != nil { | ||
return nil, fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
return []*schema.ResourceData{d}, nil | ||
} | ||
|
||
func flattenComputePublicAdvertisedPrefixDescription(v interface{}, d *schema.ResourceData, config *Config) interface{} { | ||
return v | ||
} | ||
|
||
func flattenComputePublicAdvertisedPrefixName(v interface{}, d *schema.ResourceData, config *Config) interface{} { | ||
return v | ||
} | ||
|
||
func flattenComputePublicAdvertisedPrefixDnsVerificationIp(v interface{}, d *schema.ResourceData, config *Config) interface{} { | ||
return v | ||
} | ||
|
||
func flattenComputePublicAdvertisedPrefixIpCidrRange(v interface{}, d *schema.ResourceData, config *Config) interface{} { | ||
return v | ||
} | ||
|
||
func expandComputePublicAdvertisedPrefixDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { | ||
return v, nil | ||
} | ||
|
||
func expandComputePublicAdvertisedPrefixName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { | ||
return v, nil | ||
} | ||
|
||
func expandComputePublicAdvertisedPrefixDnsVerificationIp(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { | ||
return v, nil | ||
} | ||
|
||
func expandComputePublicAdvertisedPrefixIpCidrRange(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { | ||
return v, nil | ||
} |
Oops, something went wrong.