本文整理匯總了Golang中github.com/hashicorp/terraform/helper/resource.StateChangeConf類的典型用法代碼示例。如果您正苦於以下問題:Golang StateChangeConf類的具體用法?Golang StateChangeConf怎麽用?Golang StateChangeConf使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了StateChangeConf類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: deleteRoute53RecordSet
func deleteRoute53RecordSet(conn *route53.Route53, input *route53.ChangeResourceRecordSetsInput) (interface{}, error) {
wait := resource.StateChangeConf{
Pending: []string{"rejected"},
Target: []string{"accepted"},
Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
resp, err := conn.ChangeResourceRecordSets(input)
if err != nil {
if r53err, ok := err.(awserr.Error); ok {
if r53err.Code() == "PriorRequestNotComplete" {
// There is some pending operation, so just retry
// in a bit.
return 42, "rejected", nil
}
if r53err.Code() == "InvalidChangeBatch" {
// This means that the record is already gone.
return resp, "accepted", nil
}
}
return 42, "failure", err
}
return resp, "accepted", nil
},
}
return wait.WaitForState()
}
示例2: resourceAwsRoute53ZoneCreate
func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*AWSClient).route53
req := &route53.CreateHostedZoneRequest{
Name: d.Get("name").(string),
Comment: "Managed by Terraform",
}
log.Printf("[DEBUG] Creating Route53 hosted zone: %s", req.Name)
resp, err := r53.CreateHostedZone(req)
if err != nil {
return err
}
// Store the zone_id
zone := route53.CleanZoneID(resp.HostedZone.ID)
d.Set("zone_id", zone)
d.SetId(zone)
// Wait until we are done initializing
wait := resource.StateChangeConf{
Delay: 30 * time.Second,
Pending: []string{"PENDING"},
Target: "INSYNC",
Timeout: 10 * time.Minute,
MinTimeout: 2 * time.Second,
Refresh: func() (result interface{}, state string, err error) {
return resourceAwsRoute53Wait(r53, resp.ChangeInfo.ID)
},
}
_, err = wait.WaitForState()
if err != nil {
return err
}
return nil
}
示例3: resourceBrightboxServerDelete
func resourceBrightboxServerDelete(
d *schema.ResourceData,
meta interface{},
) error {
client := meta.(*CompositeClient).ApiClient
log.Printf("[DEBUG] Server delete called for %s", d.Id())
err := client.DestroyServer(d.Id())
if err != nil {
return fmt.Errorf("Error deleting server: %s", err)
}
stateConf := resource.StateChangeConf{
Pending: []string{"deleting", "active", "inactive"},
Target: []string{"deleted"},
Refresh: serverStateRefresh(client, d.Id()),
Timeout: 5 * time.Minute,
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
_, err = stateConf.WaitForState()
if err != nil {
return err
}
return nil
}
示例4: resourceAwsSubnetDelete
func resourceAwsSubnetDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
log.Printf("[INFO] Deleting subnet: %s", d.Id())
req := &ec2.DeleteSubnetInput{
SubnetId: aws.String(d.Id()),
}
wait := resource.StateChangeConf{
Pending: []string{"pending"},
Target: []string{"destroyed"},
Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
_, err := conn.DeleteSubnet(req)
if err != nil {
if apiErr, ok := err.(awserr.Error); ok {
if apiErr.Code() == "InvalidSubnetID.NotFound" {
return 42, "destroyed", nil
}
}
return 42, "failure", err
}
return 42, "destroyed", nil
},
}
if _, err := wait.WaitForState(); err != nil {
return fmt.Errorf("Error deleting subnet: %s", err)
}
return nil
}
示例5: resource_aws_r53_record_create
func resource_aws_r53_record_create(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
p := meta.(*ResourceProvider)
conn := p.route53
// Merge the diff into the state so that we have all the attributes
// properly.
rs := s.MergeDiff(d)
// Get the record
rec, err := resource_aws_r53_build_record_set(rs)
if err != nil {
return rs, err
}
// Create the new records
req := &route53.ChangeResourceRecordSetsRequest{
Comment: "Managed by Terraform",
Changes: []route53.Change{
route53.Change{
Action: "UPSERT",
Record: *rec,
},
},
}
zone := rs.Attributes["zone_id"]
log.Printf("[DEBUG] Creating resource records for zone: %s, name: %s",
zone, rs.Attributes["name"])
resp, err := conn.ChangeResourceRecordSets(zone, req)
if err != nil {
return rs, err
}
// Generate an ID
rs.ID = fmt.Sprintf("%s_%s_%s", zone, rs.Attributes["name"], rs.Attributes["type"])
rs.Dependencies = []terraform.ResourceDependency{
terraform.ResourceDependency{ID: zone},
}
// Wait until we are done
wait := resource.StateChangeConf{
Delay: 30 * time.Second,
Pending: []string{"PENDING"},
Target: "INSYNC",
Timeout: 10 * time.Minute,
MinTimeout: 5 * time.Second,
Refresh: func() (result interface{}, state string, err error) {
return resource_aws_r53_wait(conn, resp.ChangeInfo.ID)
},
}
_, err = wait.WaitForState()
if err != nil {
return rs, err
}
return rs, nil
}
示例6: resourceAwsRoute53ZoneCreate
func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*AWSClient).r53conn
req := &route53.CreateHostedZoneInput{
Name: aws.String(d.Get("name").(string)),
HostedZoneConfig: &route53.HostedZoneConfig{Comment: aws.String(d.Get("comment").(string))},
CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)),
}
if v := d.Get("vpc_id"); v != "" {
req.VPC = &route53.VPC{
VPCId: aws.String(v.(string)),
VPCRegion: aws.String(meta.(*AWSClient).region),
}
if w := d.Get("vpc_region"); w != "" {
req.VPC.VPCRegion = aws.String(w.(string))
}
d.Set("vpc_region", req.VPC.VPCRegion)
}
if v, ok := d.GetOk("delegation_set_id"); ok {
req.DelegationSetId = aws.String(v.(string))
}
log.Printf("[DEBUG] Creating Route53 hosted zone: %s", *req.Name)
var err error
resp, err := r53.CreateHostedZone(req)
if err != nil {
return err
}
// Store the zone_id
zone := cleanZoneID(*resp.HostedZone.Id)
d.Set("zone_id", zone)
d.SetId(zone)
// Wait until we are done initializing
wait := resource.StateChangeConf{
Delay: 30 * time.Second,
Pending: []string{"PENDING"},
Target: []string{"INSYNC"},
Timeout: 10 * time.Minute,
MinTimeout: 2 * time.Second,
Refresh: func() (result interface{}, state string, err error) {
changeRequest := &route53.GetChangeInput{
Id: aws.String(cleanChangeID(*resp.ChangeInfo.Id)),
}
return resourceAwsGoRoute53Wait(r53, changeRequest)
},
}
_, err = wait.WaitForState()
if err != nil {
return err
}
return resourceAwsRoute53ZoneUpdate(d, meta)
}
示例7: resourceAwsRoute53RecordDelete
func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).route53
// Get the records
rec, err := resourceAwsRoute53RecordBuildSet(d)
if err != nil {
return err
}
// Create the new records
req := &route53.ChangeResourceRecordSetsRequest{
Comment: "Deleted by Terraform",
Changes: []route53.Change{
route53.Change{
Action: "DELETE",
Record: *rec,
},
},
}
zone := d.Get("zone_id").(string)
log.Printf("[DEBUG] Deleting resource records for zone: %s, name: %s",
zone, d.Get("name").(string))
wait := resource.StateChangeConf{
Pending: []string{"rejected"},
Target: "accepted",
Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
_, err := conn.ChangeResourceRecordSets(zone, req)
if err != nil {
if strings.Contains(err.Error(), "PriorRequestNotComplete") {
// There is some pending operation, so just retry
// in a bit.
return 42, "rejected", nil
}
if strings.Contains(err.Error(), "InvalidChangeBatch") {
// This means that the record is already gone.
return 42, "accepted", nil
}
return 42, "failure", err
}
return 42, "accepted", nil
},
}
if _, err := wait.WaitForState(); err != nil {
return err
}
return nil
}
示例8: resource_aws_r53_record_destroy
func resource_aws_r53_record_destroy(
s *terraform.ResourceState,
meta interface{}) error {
p := meta.(*ResourceProvider)
conn := p.route53
// Get the record
rec, err := resource_aws_r53_build_record_set(s)
if err != nil {
return err
}
// Create the new records
req := &route53.ChangeResourceRecordSetsRequest{
Comment: "Deleted by Terraform",
Changes: []route53.Change{
route53.Change{
Action: "DELETE",
Record: *rec,
},
},
}
zone := s.Attributes["zone_id"]
log.Printf("[DEBUG] Deleting resource records for zone: %s, name: %s",
zone, s.Attributes["name"])
wait := resource.StateChangeConf{
Pending: []string{"rejected"},
Target: "accepted",
Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
_, err := conn.ChangeResourceRecordSets(zone, req)
if err != nil {
if strings.Contains(err.Error(), "PriorRequestNotComplete") {
// There is some pending operation, so just retry
// in a bit.
return nil, "rejected", nil
}
return nil, "failure", err
}
return nil, "accepted", nil
},
}
if _, err := wait.WaitForState(); err != nil {
return err
}
return nil
}
示例9: updateKmsKeyRotationStatus
func updateKmsKeyRotationStatus(conn *kms.KMS, d *schema.ResourceData) error {
var err error
shouldEnableRotation := d.Get("enable_key_rotation").(bool)
if shouldEnableRotation {
log.Printf("[DEBUG] Enabling key rotation for KMS key %q", d.Id())
_, err = conn.EnableKeyRotation(&kms.EnableKeyRotationInput{
KeyId: aws.String(d.Id()),
})
} else {
log.Printf("[DEBUG] Disabling key rotation for KMS key %q", d.Id())
_, err = conn.DisableKeyRotation(&kms.DisableKeyRotationInput{
KeyId: aws.String(d.Id()),
})
}
if err != nil {
return fmt.Errorf("Failed to set key rotation for %q to %t: %q",
d.Id(), shouldEnableRotation, err.Error())
}
// Wait for propagation since KMS is eventually consistent
wait := resource.StateChangeConf{
Pending: []string{fmt.Sprintf("%t", !shouldEnableRotation)},
Target: []string{fmt.Sprintf("%t", shouldEnableRotation)},
Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second,
ContinuousTargetOccurence: 5,
Refresh: func() (interface{}, string, error) {
log.Printf("[DEBUG] Checking if KMS key %s rotation status is %t",
d.Id(), shouldEnableRotation)
resp, err := conn.GetKeyRotationStatus(&kms.GetKeyRotationStatusInput{
KeyId: aws.String(d.Id()),
})
if err != nil {
return resp, "FAILED", err
}
status := fmt.Sprintf("%t", *resp.KeyRotationEnabled)
log.Printf("[DEBUG] KMS key %s rotation status received: %s, retrying", d.Id(), status)
return resp, status, nil
},
}
_, err = wait.WaitForState()
if err != nil {
return fmt.Errorf("Failed setting KMS key rotation status to %t: %s", shouldEnableRotation, err)
}
return nil
}
示例10: updateKmsKeyStatus
func updateKmsKeyStatus(conn *kms.KMS, id string, shouldBeEnabled bool) error {
var err error
if shouldBeEnabled {
log.Printf("[DEBUG] Enabling KMS key %q", id)
_, err = conn.EnableKey(&kms.EnableKeyInput{
KeyId: aws.String(id),
})
} else {
log.Printf("[DEBUG] Disabling KMS key %q", id)
_, err = conn.DisableKey(&kms.DisableKeyInput{
KeyId: aws.String(id),
})
}
if err != nil {
return fmt.Errorf("Failed to set KMS key %q status to %t: %q",
id, shouldBeEnabled, err.Error())
}
// Wait for propagation since KMS is eventually consistent
wait := resource.StateChangeConf{
Pending: []string{fmt.Sprintf("%t", !shouldBeEnabled)},
Target: []string{fmt.Sprintf("%t", shouldBeEnabled)},
Timeout: 20 * time.Minute,
MinTimeout: 2 * time.Second,
ContinuousTargetOccurence: 10,
Refresh: func() (interface{}, string, error) {
log.Printf("[DEBUG] Checking if KMS key %s enabled status is %t",
id, shouldBeEnabled)
resp, err := conn.DescribeKey(&kms.DescribeKeyInput{
KeyId: aws.String(id),
})
if err != nil {
return resp, "FAILED", err
}
status := fmt.Sprintf("%t", *resp.KeyMetadata.Enabled)
log.Printf("[DEBUG] KMS key %s status received: %s, retrying", id, status)
return resp, status, nil
},
}
_, err = wait.WaitForState()
if err != nil {
return fmt.Errorf("Failed setting KMS key status to %t: %s", shouldBeEnabled, err)
}
return nil
}
示例11: resourceBrightboxServerCreate
func resourceBrightboxServerCreate(
d *schema.ResourceData,
meta interface{},
) error {
client := meta.(*CompositeClient).ApiClient
log.Printf("[DEBUG] Server create called")
server_opts := &brightbox.ServerOptions{
Image: d.Get("image").(string),
}
err := addUpdateableServerOptions(d, server_opts)
if err != nil {
return err
}
server_type := &server_opts.ServerType
assign_string(d, &server_type, "type")
zone := &server_opts.Zone
assign_string(d, &zone, "zone")
log.Printf("[DEBUG] Server create configuration: %#v", server_opts)
server, err := client.CreateServer(server_opts)
if err != nil {
return fmt.Errorf("Error creating server: %s", err)
}
d.SetId(server.Id)
log.Printf("[INFO] Waiting for Server (%s) to become available", d.Id())
stateConf := resource.StateChangeConf{
Pending: []string{"creating"},
Target: []string{"active", "inactive"},
Refresh: serverStateRefresh(client, server.Id),
Timeout: 5 * time.Minute,
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
active_server, err := stateConf.WaitForState()
if err != nil {
return err
}
setServerAttributes(d, active_server.(*brightbox.Server))
return nil
}
示例12: resourceContainerClusterUpdate
func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return err
}
zoneName := d.Get("zone").(string)
clusterName := d.Get("name").(string)
desiredNodeVersion := d.Get("node_version").(string)
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredNodeVersion: desiredNodeVersion,
},
}
op, err := config.clientContainer.Projects.Zones.Clusters.Update(
project, zoneName, clusterName, req).Do()
if err != nil {
return err
}
// Wait until it's updated
wait := resource.StateChangeConf{
Pending: []string{"PENDING", "RUNNING"},
Target: []string{"DONE"},
Timeout: 10 * time.Minute,
MinTimeout: 2 * time.Second,
Refresh: func() (interface{}, string, error) {
log.Printf("[DEBUG] Checking if GKE cluster %s is updated", clusterName)
resp, err := config.clientContainer.Projects.Zones.Operations.Get(
project, zoneName, op.Name).Do()
log.Printf("[DEBUG] Progress of updating GKE cluster %s: %s",
clusterName, resp.Status)
return resp, resp.Status, err
},
}
_, err = wait.WaitForState()
if err != nil {
return err
}
log.Printf("[INFO] GKE cluster %s has been updated to %s", d.Id(),
desiredNodeVersion)
return resourceContainerClusterRead(d, meta)
}
示例13: resourceAwsPlacementGroupCreate
func resourceAwsPlacementGroupCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
name := d.Get("name").(string)
input := ec2.CreatePlacementGroupInput{
GroupName: aws.String(name),
Strategy: aws.String(d.Get("strategy").(string)),
}
log.Printf("[DEBUG] Creating EC2 Placement group: %s", input)
_, err := conn.CreatePlacementGroup(&input)
if err != nil {
return err
}
wait := resource.StateChangeConf{
Pending: []string{"pending"},
Target: []string{"available"},
Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
out, err := conn.DescribePlacementGroups(&ec2.DescribePlacementGroupsInput{
GroupNames: []*string{aws.String(name)},
})
if err != nil {
return out, "", err
}
if len(out.PlacementGroups) == 0 {
return out, "", fmt.Errorf("Placement group not found (%q)", name)
}
pg := out.PlacementGroups[0]
return out, *pg.State, nil
},
}
_, err = wait.WaitForState()
if err != nil {
return err
}
log.Printf("[DEBUG] EC2 Placement group created: %q", name)
d.SetId(name)
return resourceAwsPlacementGroupRead(d, meta)
}
示例14: resourceAwsPlacementGroupDelete
func resourceAwsPlacementGroupDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
log.Printf("[DEBUG] Deleting EC2 Placement Group %q", d.Id())
_, err := conn.DeletePlacementGroup(&ec2.DeletePlacementGroupInput{
GroupName: aws.String(d.Id()),
})
if err != nil {
return err
}
wait := resource.StateChangeConf{
Pending: []string{"deleting"},
Target: []string{"deleted"},
Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
out, err := conn.DescribePlacementGroups(&ec2.DescribePlacementGroupsInput{
GroupNames: []*string{aws.String(d.Id())},
})
if err != nil {
awsErr := err.(awserr.Error)
if awsErr.Code() == "InvalidPlacementGroup.Unknown" {
return out, "deleted", nil
}
return out, "", awsErr
}
if len(out.PlacementGroups) == 0 {
return out, "deleted", nil
}
pg := out.PlacementGroups[0]
return out, *pg.State, nil
},
}
_, err = wait.WaitForState()
if err != nil {
return err
}
d.SetId("")
return nil
}
示例15: createDatabaseServer
func createDatabaseServer(d *schema.ResourceData, client *brightbox.Client) error {
log.Printf("[DEBUG] Database Server create called")
database_server_opts := getBlankDatabaseServerOpts()
err := addUpdateableDatabaseServerOptions(d, database_server_opts)
if err != nil {
return err
}
engine := &database_server_opts.Engine
assign_string(d, &engine, "database_engine")
version := &database_server_opts.Version
assign_string(d, &version, "database_version")
snapshot := &database_server_opts.Snapshot
assign_string(d, &snapshot, "snapshot")
zone := &database_server_opts.Zone
assign_string(d, &zone, "zone")
database_server_opts.AllowAccess = &allow_any
log.Printf("[DEBUG] Database Server create configuration %#v", database_server_opts)
output_database_server_options(database_server_opts)
database_server, err := client.CreateDatabaseServer(database_server_opts)
if err != nil {
return fmt.Errorf("Error creating server: %s", err)
}
log.Printf("[DEBUG] Setting Partial")
d.Partial(true)
d.SetId(database_server.Id)
if database_server.AdminPassword == "" {
log.Printf("[WARN] No password returned for Cloud SQL server %s", database_server.Id)
} else {
d.Set("admin_password", database_server.AdminPassword)
}
log.Printf("[INFO] Waiting for Database Server (%s) to become available", d.Id())
stateConf := resource.StateChangeConf{
Pending: []string{"creating"},
Target: []string{"active"},
Refresh: databaseServerStateRefresh(client, database_server.Id),
Timeout: 5 * time.Minute,
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
active_database_server, err := stateConf.WaitForState()
if err != nil {
return err
}
d.SetPartial("admin_password")
setDatabaseServerAttributes(d, active_database_server.(*brightbox.DatabaseServer))
return nil
}
開發者ID:brightbox,項目名稱:terraform-provider-brightbox,代碼行數:47,代碼來源:resource_brightbox_database_server.go