本文整理匯總了Golang中github.com/hashicorp/terraform/terraform.State類的典型用法代碼示例。如果您正苦於以下問題:Golang State類的具體用法?Golang State怎麽用?Golang State使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了State類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: testAccCheckIAMUserPolicyDestroy
func testAccCheckIAMUserPolicyDestroy(s *terraform.State) error {
iamconn := testAccProvider.Meta().(*AWSClient).iamconn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_iam_user_policy" {
continue
}
role, name := resourceAwsIamRolePolicyParseId(rs.Primary.ID)
request := &iam.GetRolePolicyInput{
PolicyName: aws.String(name),
RoleName: aws.String(role),
}
var err error
getResp, err := iamconn.GetRolePolicy(request)
if err != nil {
if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" {
// none found, that's good
return nil
}
return fmt.Errorf("Error reading IAM policy %s from role %s: %s", name, role, err)
}
if getResp != nil {
return fmt.Errorf("Found IAM Role, expected none: %s", getResp)
}
}
return nil
}
示例2: testAccCheckAWSInspectorTemplateDestroy
func testAccCheckAWSInspectorTemplateDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).inspectorconn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_inspector_assessment_template" {
continue
}
resp, err := conn.DescribeAssessmentTemplates(&inspector.DescribeAssessmentTemplatesInput{
AssessmentTemplateArns: []*string{
aws.String(rs.Primary.ID),
},
})
if err != nil {
if inspectorerr, ok := err.(awserr.Error); ok && inspectorerr.Code() == "InvalidInputException" {
return nil
} else {
return fmt.Errorf("Error finding Inspector Assessment Template: %s", err)
}
}
if len(resp.AssessmentTemplates) > 0 {
return fmt.Errorf("Found Template, expected none: %s", resp)
}
}
return nil
}
示例3: testAccCheckAWSEIPDestroy
func testAccCheckAWSEIPDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_eip" {
continue
}
req := &ec2.DescribeAddressesInput{
PublicIPs: []*string{aws.String(rs.Primary.ID)},
}
describe, err := conn.DescribeAddresses(req)
if err == nil {
if len(describe.Addresses) != 0 &&
*describe.Addresses[0].PublicIP == rs.Primary.ID {
return fmt.Errorf("EIP still exists")
}
}
// Verify the error
providerErr, ok := err.(awserr.Error)
if !ok {
return err
}
if providerErr.Code() != "InvalidAllocationID.NotFound" {
return fmt.Errorf("Unexpected error: %s", err)
}
}
return nil
}
示例4: testAccCheckVcdSNATDestroy
func testAccCheckVcdSNATDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*VCDClient)
for _, rs := range s.RootModule().Resources {
if rs.Type != "vcd_snat" {
continue
}
gatewayName := rs.Primary.Attributes["edge_gateway"]
edgeGateway, err := conn.OrgVdc.FindEdgeGateway(gatewayName)
if err != nil {
return fmt.Errorf("Could not find edge gateway")
}
var found bool
for _, v := range edgeGateway.EdgeGateway.Configuration.EdgeGatewayServiceConfiguration.NatService.NatRule {
if v.RuleType == "SNAT" &&
v.GatewayNatRule.OriginalIP == "10.10.102.0/24" &&
v.GatewayNatRule.OriginalPort == "" &&
v.GatewayNatRule.TranslatedIP == os.Getenv("VCD_EXTERNAL_IP") {
found = true
}
}
if found {
return fmt.Errorf("SNAT rule still exists.")
}
}
return nil
}
示例5: testCheckAzureRMNetworkSecurityRuleDestroy
func testCheckAzureRMNetworkSecurityRuleDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*ArmClient).secRuleClient
for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_network_security_rule" {
continue
}
sgName := rs.Primary.Attributes["network_security_group_name"]
sgrName := rs.Primary.Attributes["name"]
resourceGroup := rs.Primary.Attributes["resource_group_name"]
resp, err := conn.Get(resourceGroup, sgName, sgrName)
if err != nil {
return nil
}
if resp.StatusCode != http.StatusNotFound {
return fmt.Errorf("Network Security Rule still exists:\n%#v", resp.Properties)
}
}
return nil
}
示例6: testAccAwsOpsworksCheckVpc
func testAccAwsOpsworksCheckVpc(s *terraform.State) error {
rs, ok := s.RootModule().Resources["aws_opsworks_stack.tf-acc"]
if !ok {
return fmt.Errorf("Not found: %s", "aws_opsworks_stack.tf-acc")
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
p := rs.Primary
opsworksconn := testAccProvider.Meta().(*AWSClient).opsworksconn
describeOpts := &opsworks.DescribeStacksInput{
StackIds: []*string{aws.String(p.ID)},
}
resp, err := opsworksconn.DescribeStacks(describeOpts)
if err != nil {
return err
}
if len(resp.Stacks) == 0 {
return fmt.Errorf("No stack %s not found", p.ID)
}
if p.Attributes["vpc_id"] != *resp.Stacks[0].VpcId {
return fmt.Errorf("VPCID Got %s, expected %s", *resp.Stacks[0].VpcId, p.Attributes["vpc_id"])
}
if p.Attributes["default_subnet_id"] != *resp.Stacks[0].DefaultSubnetId {
return fmt.Errorf("VPCID Got %s, expected %s", *resp.Stacks[0].DefaultSubnetId, p.Attributes["default_subnet_id"])
}
return nil
}
示例7: testAccCheckDigitalOceanDropletDestroy
func testAccCheckDigitalOceanDropletDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*godo.Client)
for _, rs := range s.RootModule().Resources {
if rs.Type != "digitalocean_droplet" {
continue
}
id, err := strconv.Atoi(rs.Primary.ID)
if err != nil {
return err
}
// Try to find the Droplet
_, _, err = client.Droplets.Get(id)
// Wait
if err != nil && !strings.Contains(err.Error(), "404") {
return fmt.Errorf(
"Error waiting for droplet (%s) to be destroyed: %s",
rs.Primary.ID, err)
}
}
return nil
}
示例8: testAccCheckAWSSNSTopicDestroy
func testAccCheckAWSSNSTopicDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).snsconn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_sns_topic" {
continue
}
// Check if the topic exists by fetching its attributes
params := &sns.GetTopicAttributesInput{
TopicArn: aws.String(rs.Primary.ID),
}
_, err := conn.GetTopicAttributes(params)
if err == nil {
return fmt.Errorf("Topic exists when it should be destroyed!")
}
// Verify the error is an API error, not something else
_, ok := err.(awserr.Error)
if !ok {
return err
}
}
return nil
}
示例9: testAccCheckAWSSecurityGroupDestroy
func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_security_group" {
continue
}
// Retrieve our group
req := &ec2.DescribeSecurityGroupsInput{
GroupIds: []*string{aws.String(rs.Primary.ID)},
}
resp, err := conn.DescribeSecurityGroups(req)
if err == nil {
if len(resp.SecurityGroups) > 0 && *resp.SecurityGroups[0].GroupId == rs.Primary.ID {
return fmt.Errorf("Security Group (%s) still exists.", rs.Primary.ID)
}
return nil
}
ec2err, ok := err.(awserr.Error)
if !ok {
return err
}
// Confirm error code is what we want
if ec2err.Code() != "InvalidGroup.NotFound" {
return err
}
}
return nil
}
示例10: testAccCheckDBSubnetGroupDestroy
func testAccCheckDBSubnetGroupDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).rdsconn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_db_subnet_group" {
continue
}
// Try to find the resource
resp, err := conn.DescribeDBSubnetGroups(
&rds.DescribeDBSubnetGroupsInput{DBSubnetGroupName: aws.String(rs.Primary.ID)})
if err == nil {
if len(resp.DBSubnetGroups) > 0 {
return fmt.Errorf("still exist.")
}
return nil
}
// Verify the error is what we want
rdserr, ok := err.(awserr.Error)
if !ok {
return err
}
if rdserr.Code() != "DBSubnetGroupNotFoundFault" {
return err
}
}
return nil
}
示例11: testAccCheckAWSAutoscalingLifecycleHookDestroy
func testAccCheckAWSAutoscalingLifecycleHookDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).autoscalingconn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_autoscaling_group" {
continue
}
params := autoscaling.DescribeLifecycleHooksInput{
AutoScalingGroupName: aws.String(rs.Primary.Attributes["autoscaling_group_name"]),
LifecycleHookNames: []*string{aws.String(rs.Primary.ID)},
}
resp, err := conn.DescribeLifecycleHooks(¶ms)
if err == nil {
if len(resp.LifecycleHooks) != 0 &&
*resp.LifecycleHooks[0].LifecycleHookName == rs.Primary.ID {
return fmt.Errorf("Lifecycle Hook Still Exists: %s", rs.Primary.ID)
}
}
}
return nil
}
示例12: testAccCheckAzureDataDiskDestroy
func testAccCheckAzureDataDiskDestroy(s *terraform.State) error {
vmDiskClient := testAccProvider.Meta().(*Client).vmDiskClient
for _, rs := range s.RootModule().Resources {
if rs.Type != "azure_data_disk" {
continue
}
if rs.Primary.ID == "" {
return fmt.Errorf("No Disk ID is set")
}
vm := rs.Primary.Attributes["virtual_machine"]
lun, err := strconv.Atoi(rs.Primary.Attributes["lun"])
if err != nil {
return err
}
_, err = vmDiskClient.GetDataDisk(vm, vm, vm, lun)
if err == nil {
return fmt.Errorf("Data disk %s still exists", rs.Primary.ID)
}
if !management.IsResourceNotFoundError(err) {
return err
}
}
return nil
}
示例13: testAccCheckAWSDynamoDbTableDestroy
func testAccCheckAWSDynamoDbTableDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).dynamodbconn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_dynamodb_table" {
continue
}
fmt.Printf("[DEBUG] Checking if DynamoDB table %s exists", rs.Primary.ID)
// Check if queue exists by checking for its attributes
params := &dynamodb.DescribeTableInput{
TableName: aws.String(rs.Primary.ID),
}
_, err := conn.DescribeTable(params)
if err == nil {
return fmt.Errorf("DynamoDB table %s still exists. Failing!", rs.Primary.ID)
}
// Verify the error is what we want
_, ok := err.(awserr.Error)
if !ok {
return err
}
}
return nil
}
示例14: testAccCheckRouteTableDestroy
func testAccCheckRouteTableDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route_table" {
continue
}
// Try to find the resource
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{
RouteTableIDs: []string{rs.Primary.ID},
})
if err == nil {
if len(resp.RouteTables) > 0 {
return fmt.Errorf("still exist.")
}
return nil
}
// Verify the error is what we want
ec2err, ok := err.(aws.APIError)
if !ok {
return err
}
if ec2err.Code != "InvalidRouteTableID.NotFound" {
return err
}
}
return nil
}
示例15: testAccCheckAWSClusterDestroy
func testAccCheckAWSClusterDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_rds_cluster" {
continue
}
// Try to find the Group
conn := testAccProvider.Meta().(*AWSClient).rdsconn
var err error
resp, err := conn.DescribeDBClusters(
&rds.DescribeDBClustersInput{
DBClusterIdentifier: aws.String(rs.Primary.ID),
})
if err == nil {
if len(resp.DBClusters) != 0 &&
*resp.DBClusters[0].DBClusterIdentifier == rs.Primary.ID {
return fmt.Errorf("DB Cluster %s still exists", rs.Primary.ID)
}
}
// Return nil if the cluster is already destroyed
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "DBClusterNotFoundFault" {
return nil
}
}
return err
}
return nil
}