|
1 | 1 | package provider |
2 | 2 |
|
3 | | -import ( |
4 | | - "fmt" |
5 | | - "os" |
6 | | - "regexp" |
7 | | - "testing" |
8 | | - |
9 | | - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" |
10 | | - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
11 | | -) |
12 | | - |
13 | | -func TestAccResourceRedisCloudActiveActiveSubscriptionPeering_aws(t *testing.T) { |
14 | | - |
15 | | - name := acctest.RandomWithPrefix(testResourcePrefix) |
16 | | - |
17 | | - cidrRange := os.Getenv("AWS_VPC_CIDR") |
18 | | - // Choose a CIDR range for the subscription that's unlikely to overlap with any VPC CIDR |
19 | | - subCidrRange := "10.0.0.0/24" |
20 | | - |
21 | | - overlap, err := cidrRangesOverlap(subCidrRange, cidrRange) |
22 | | - if err != nil { |
23 | | - t.Fatalf("AWS_VPC_CIDR is not a valid CIDR range %s: %s", cidrRange, err) |
24 | | - } |
25 | | - if overlap { |
26 | | - subCidrRange = "172.16.0.0/24" |
27 | | - } |
28 | | - |
29 | | - peeringRegion := os.Getenv("AWS_PEERING_REGION") |
30 | | - matchesRegex(t, peeringRegion, "^[a-z]+-[a-z]+-\\d+$") |
31 | | - |
32 | | - accountId := os.Getenv("AWS_ACCOUNT_ID") |
33 | | - matchesRegex(t, accountId, "^\\d+$") |
34 | | - |
35 | | - vpcId := os.Getenv("AWS_VPC_ID") |
36 | | - matchesRegex(t, vpcId, "^vpc-[a-z\\d]+$") |
37 | | - |
38 | | - tf := fmt.Sprintf(testAccResourceRedisCloudActiveActiveSubscriptionPeeringAWS, |
39 | | - name, |
40 | | - subCidrRange, |
41 | | - peeringRegion, |
42 | | - accountId, |
43 | | - vpcId, |
44 | | - cidrRange, |
45 | | - ) |
46 | | - const resourceName = "rediscloud_active_active_subscription_peering.test" |
47 | | - |
48 | | - resource.ParallelTest(t, resource.TestCase{ |
49 | | - PreCheck: func() { testAccPreCheck(t); testAccAwsPeeringPreCheck(t); testAccAwsPreExistingCloudAccountPreCheck(t) }, |
50 | | - ProviderFactories: providerFactories, |
51 | | - CheckDestroy: testAccCheckActiveActiveSubscriptionDestroy, |
52 | | - Steps: []resource.TestStep{ |
53 | | - { |
54 | | - Config: tf, |
55 | | - Check: resource.ComposeAggregateTestCheckFunc( |
56 | | - resource.TestMatchResourceAttr(resourceName, "id", regexp.MustCompile("^\\d*/\\d*$")), |
57 | | - resource.TestCheckResourceAttrSet(resourceName, "status"), |
58 | | - resource.TestCheckResourceAttrSet(resourceName, "provider_name"), |
59 | | - resource.TestCheckResourceAttrSet(resourceName, "aws_account_id"), |
60 | | - resource.TestCheckResourceAttrSet(resourceName, "vpc_id"), |
61 | | - resource.TestCheckResourceAttr(resourceName, "vpc_cidr", cidrRange), |
62 | | - resource.TestCheckResourceAttr(resourceName, "vpc_cidrs.#", "1"), |
63 | | - resource.TestCheckResourceAttr(resourceName, "vpc_cidrs.0", cidrRange), |
64 | | - resource.TestCheckResourceAttrSet(resourceName, "source_region"), |
65 | | - resource.TestCheckResourceAttrSet(resourceName, "destination_region"), |
66 | | - resource.TestCheckResourceAttrSet(resourceName, "aws_peering_id"), |
67 | | - ), |
68 | | - }, |
69 | | - }, |
70 | | - }) |
71 | | -} |
72 | | - |
73 | | -func TestAccResourceRedisCloudActiveActiveSubscriptionPeering_gcp(t *testing.T) { |
74 | | - |
75 | | - name := acctest.RandomWithPrefix(testResourcePrefix) |
76 | | - |
77 | | - tf := fmt.Sprintf(testAccResourceRedisCloudActiveActiveSubscriptionPeeringGCP, |
78 | | - name, |
79 | | - os.Getenv("GCP_VPC_PROJECT"), |
80 | | - os.Getenv("GCP_VPC_ID"), |
81 | | - ) |
82 | | - const resourceName = "rediscloud_active_active_subscription_peering.test" |
83 | | - |
84 | | - resource.ParallelTest(t, resource.TestCase{ |
85 | | - PreCheck: func() { testAccPreCheck(t) }, |
86 | | - ProviderFactories: providerFactories, |
87 | | - CheckDestroy: testAccCheckActiveActiveSubscriptionDestroy, |
88 | | - Steps: []resource.TestStep{ |
89 | | - { |
90 | | - Config: tf, |
91 | | - Check: resource.ComposeAggregateTestCheckFunc( |
92 | | - resource.TestMatchResourceAttr(resourceName, "id", regexp.MustCompile("^\\d*/\\d*$")), |
93 | | - resource.TestCheckResourceAttr(resourceName, "provider_name", "GCP"), |
94 | | - resource.TestCheckResourceAttrSet(resourceName, "status"), |
95 | | - resource.TestCheckResourceAttrSet(resourceName, "gcp_project_id"), |
96 | | - resource.TestCheckResourceAttrSet(resourceName, "gcp_network_name"), |
97 | | - resource.TestCheckResourceAttrSet(resourceName, "gcp_redis_project_id"), |
98 | | - resource.TestCheckResourceAttrSet(resourceName, "gcp_redis_network_name"), |
99 | | - ), |
100 | | - }, |
101 | | - { |
102 | | - ResourceName: resourceName, |
103 | | - ImportState: true, |
104 | | - ImportStateVerify: true, |
105 | | - }, |
106 | | - }, |
107 | | - }) |
108 | | -} |
109 | | - |
110 | | -const testAccResourceRedisCloudActiveActiveSubscriptionPeeringAWS = ` |
111 | | -data "rediscloud_payment_method" "card" { |
112 | | - card_type = "Visa" |
113 | | -} |
114 | | -
|
115 | | -resource "rediscloud_active_active_subscription" "example" { |
116 | | - name = "%s" |
117 | | - payment_method_id = data.rediscloud_payment_method.card.id |
118 | | - cloud_provider = "AWS" |
119 | | -
|
120 | | - creation_plan { |
121 | | - memory_limit_in_gb = 1 |
122 | | - quantity = 1 |
123 | | - region { |
124 | | - region = "us-east-1" |
125 | | - networking_deployment_cidr = "192.168.0.0/24" |
126 | | - write_operations_per_second = 1000 |
127 | | - read_operations_per_second = 1000 |
128 | | - } |
129 | | - region { |
130 | | - region = "us-east-2" |
131 | | - networking_deployment_cidr = "%s" |
132 | | - write_operations_per_second = 1000 |
133 | | - read_operations_per_second = 1000 |
134 | | - } |
135 | | - } |
136 | | -} |
137 | | -
|
138 | | -resource "rediscloud_active_active_subscription_peering" "test" { |
139 | | - subscription_id = rediscloud_active_active_subscription.example.id |
140 | | - provider_name = "AWS" |
141 | | - source_region = "us-east-2" |
142 | | - destination_region = "%s" |
143 | | - aws_account_id = "%s" |
144 | | - vpc_id = "%s" |
145 | | - vpc_cidr = "%s" |
146 | | -} |
147 | | -` |
148 | | - |
149 | | -const testAccResourceRedisCloudActiveActiveSubscriptionPeeringGCP = ` |
150 | | -data "rediscloud_payment_method" "card" { |
151 | | - card_type = "Visa" |
152 | | -} |
153 | | -
|
154 | | -resource "rediscloud_active_active_subscription" "example" { |
155 | | - name = "%s" |
156 | | - payment_method_id = data.rediscloud_payment_method.card.id |
157 | | - cloud_provider = "GCP" |
158 | | - creation_plan { |
159 | | - memory_limit_in_gb = 1 |
160 | | - quantity = 1 |
161 | | - region { |
162 | | - region = "europe-west1" |
163 | | - networking_deployment_cidr = "192.168.0.0/24" |
164 | | - write_operations_per_second = 1000 |
165 | | - read_operations_per_second = 1000 |
166 | | - } |
167 | | - region { |
168 | | - region = "europe-west2" |
169 | | - networking_deployment_cidr = "192.168.1.0/24" |
170 | | - write_operations_per_second = 1000 |
171 | | - read_operations_per_second = 1000 |
172 | | - } |
173 | | - } |
174 | | -} |
175 | | -
|
176 | | -resource "rediscloud_active_active_subscription_peering" "test" { |
177 | | - subscription_id = rediscloud_active_active_subscription.example.id |
178 | | - provider_name = "GCP" |
179 | | - gcp_project_id = "%s" |
180 | | - gcp_network_name = "%s" |
181 | | -
|
182 | | - source_region = "europe-west2" |
183 | | -} |
184 | | -` |
| 3 | +// |
| 4 | +//import ( |
| 5 | +// "fmt" |
| 6 | +// "os" |
| 7 | +// "regexp" |
| 8 | +// "testing" |
| 9 | +// |
| 10 | +// "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" |
| 11 | +// "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 12 | +//) |
| 13 | +// |
| 14 | +//func TestAccResourceRedisCloudActiveActiveSubscriptionPeering_aws(t *testing.T) { |
| 15 | +// |
| 16 | +// name := acctest.RandomWithPrefix(testResourcePrefix) |
| 17 | +// |
| 18 | +// cidrRange := os.Getenv("AWS_VPC_CIDR") |
| 19 | +// // Choose a CIDR range for the subscription that's unlikely to overlap with any VPC CIDR |
| 20 | +// subCidrRange := "10.0.0.0/24" |
| 21 | +// |
| 22 | +// overlap, err := cidrRangesOverlap(subCidrRange, cidrRange) |
| 23 | +// if err != nil { |
| 24 | +// t.Fatalf("AWS_VPC_CIDR is not a valid CIDR range %s: %s", cidrRange, err) |
| 25 | +// } |
| 26 | +// if overlap { |
| 27 | +// subCidrRange = "172.16.0.0/24" |
| 28 | +// } |
| 29 | +// |
| 30 | +// peeringRegion := os.Getenv("AWS_PEERING_REGION") |
| 31 | +// matchesRegex(t, peeringRegion, "^[a-z]+-[a-z]+-\\d+$") |
| 32 | +// |
| 33 | +// accountId := os.Getenv("AWS_ACCOUNT_ID") |
| 34 | +// matchesRegex(t, accountId, "^\\d+$") |
| 35 | +// |
| 36 | +// vpcId := os.Getenv("AWS_VPC_ID") |
| 37 | +// matchesRegex(t, vpcId, "^vpc-[a-z\\d]+$") |
| 38 | +// |
| 39 | +// tf := fmt.Sprintf(testAccResourceRedisCloudActiveActiveSubscriptionPeeringAWS, |
| 40 | +// name, |
| 41 | +// subCidrRange, |
| 42 | +// peeringRegion, |
| 43 | +// accountId, |
| 44 | +// vpcId, |
| 45 | +// cidrRange, |
| 46 | +// ) |
| 47 | +// const resourceName = "rediscloud_active_active_subscription_peering.test" |
| 48 | +// |
| 49 | +// resource.ParallelTest(t, resource.TestCase{ |
| 50 | +// PreCheck: func() { testAccPreCheck(t); testAccAwsPeeringPreCheck(t); testAccAwsPreExistingCloudAccountPreCheck(t) }, |
| 51 | +// ProviderFactories: providerFactories, |
| 52 | +// CheckDestroy: testAccCheckActiveActiveSubscriptionDestroy, |
| 53 | +// Steps: []resource.TestStep{ |
| 54 | +// { |
| 55 | +// Config: tf, |
| 56 | +// Check: resource.ComposeAggregateTestCheckFunc( |
| 57 | +// resource.TestMatchResourceAttr(resourceName, "id", regexp.MustCompile("^\\d*/\\d*$")), |
| 58 | +// resource.TestCheckResourceAttrSet(resourceName, "status"), |
| 59 | +// resource.TestCheckResourceAttrSet(resourceName, "provider_name"), |
| 60 | +// resource.TestCheckResourceAttrSet(resourceName, "aws_account_id"), |
| 61 | +// resource.TestCheckResourceAttrSet(resourceName, "vpc_id"), |
| 62 | +// resource.TestCheckResourceAttr(resourceName, "vpc_cidr", cidrRange), |
| 63 | +// resource.TestCheckResourceAttr(resourceName, "vpc_cidrs.#", "1"), |
| 64 | +// resource.TestCheckResourceAttr(resourceName, "vpc_cidrs.0", cidrRange), |
| 65 | +// resource.TestCheckResourceAttrSet(resourceName, "source_region"), |
| 66 | +// resource.TestCheckResourceAttrSet(resourceName, "destination_region"), |
| 67 | +// resource.TestCheckResourceAttrSet(resourceName, "aws_peering_id"), |
| 68 | +// ), |
| 69 | +// }, |
| 70 | +// }, |
| 71 | +// }) |
| 72 | +//} |
| 73 | +// |
| 74 | +//func TestAccResourceRedisCloudActiveActiveSubscriptionPeering_gcp(t *testing.T) { |
| 75 | +// |
| 76 | +// name := acctest.RandomWithPrefix(testResourcePrefix) |
| 77 | +// |
| 78 | +// tf := fmt.Sprintf(testAccResourceRedisCloudActiveActiveSubscriptionPeeringGCP, |
| 79 | +// name, |
| 80 | +// os.Getenv("GCP_VPC_PROJECT"), |
| 81 | +// os.Getenv("GCP_VPC_ID"), |
| 82 | +// ) |
| 83 | +// const resourceName = "rediscloud_active_active_subscription_peering.test" |
| 84 | +// |
| 85 | +// resource.ParallelTest(t, resource.TestCase{ |
| 86 | +// PreCheck: func() { testAccPreCheck(t) }, |
| 87 | +// ProviderFactories: providerFactories, |
| 88 | +// CheckDestroy: testAccCheckActiveActiveSubscriptionDestroy, |
| 89 | +// Steps: []resource.TestStep{ |
| 90 | +// { |
| 91 | +// Config: tf, |
| 92 | +// Check: resource.ComposeAggregateTestCheckFunc( |
| 93 | +// resource.TestMatchResourceAttr(resourceName, "id", regexp.MustCompile("^\\d*/\\d*$")), |
| 94 | +// resource.TestCheckResourceAttr(resourceName, "provider_name", "GCP"), |
| 95 | +// resource.TestCheckResourceAttrSet(resourceName, "status"), |
| 96 | +// resource.TestCheckResourceAttrSet(resourceName, "gcp_project_id"), |
| 97 | +// resource.TestCheckResourceAttrSet(resourceName, "gcp_network_name"), |
| 98 | +// resource.TestCheckResourceAttrSet(resourceName, "gcp_redis_project_id"), |
| 99 | +// resource.TestCheckResourceAttrSet(resourceName, "gcp_redis_network_name"), |
| 100 | +// ), |
| 101 | +// }, |
| 102 | +// { |
| 103 | +// ResourceName: resourceName, |
| 104 | +// ImportState: true, |
| 105 | +// ImportStateVerify: true, |
| 106 | +// }, |
| 107 | +// }, |
| 108 | +// }) |
| 109 | +//} |
| 110 | +// |
| 111 | +//const testAccResourceRedisCloudActiveActiveSubscriptionPeeringAWS = ` |
| 112 | +//data "rediscloud_payment_method" "card" { |
| 113 | +// card_type = "Visa" |
| 114 | +//} |
| 115 | +// |
| 116 | +//resource "rediscloud_active_active_subscription" "example" { |
| 117 | +// name = "%s" |
| 118 | +// payment_method_id = data.rediscloud_payment_method.card.id |
| 119 | +// cloud_provider = "AWS" |
| 120 | +// |
| 121 | +// creation_plan { |
| 122 | +// memory_limit_in_gb = 1 |
| 123 | +// quantity = 1 |
| 124 | +// region { |
| 125 | +// region = "us-east-1" |
| 126 | +// networking_deployment_cidr = "192.168.0.0/24" |
| 127 | +// write_operations_per_second = 1000 |
| 128 | +// read_operations_per_second = 1000 |
| 129 | +// } |
| 130 | +// region { |
| 131 | +// region = "us-east-2" |
| 132 | +// networking_deployment_cidr = "%s" |
| 133 | +// write_operations_per_second = 1000 |
| 134 | +// read_operations_per_second = 1000 |
| 135 | +// } |
| 136 | +// } |
| 137 | +//} |
| 138 | +// |
| 139 | +//resource "rediscloud_active_active_subscription_peering" "test" { |
| 140 | +// subscription_id = rediscloud_active_active_subscription.example.id |
| 141 | +// provider_name = "AWS" |
| 142 | +// source_region = "us-east-2" |
| 143 | +// destination_region = "%s" |
| 144 | +// aws_account_id = "%s" |
| 145 | +// vpc_id = "%s" |
| 146 | +// vpc_cidr = "%s" |
| 147 | +//} |
| 148 | +//` |
| 149 | +// |
| 150 | +//const testAccResourceRedisCloudActiveActiveSubscriptionPeeringGCP = ` |
| 151 | +//data "rediscloud_payment_method" "card" { |
| 152 | +// card_type = "Visa" |
| 153 | +//} |
| 154 | +// |
| 155 | +//resource "rediscloud_active_active_subscription" "example" { |
| 156 | +// name = "%s" |
| 157 | +// payment_method_id = data.rediscloud_payment_method.card.id |
| 158 | +// cloud_provider = "GCP" |
| 159 | +// creation_plan { |
| 160 | +// memory_limit_in_gb = 1 |
| 161 | +// quantity = 1 |
| 162 | +// region { |
| 163 | +// region = "europe-west1" |
| 164 | +// networking_deployment_cidr = "192.168.0.0/24" |
| 165 | +// write_operations_per_second = 1000 |
| 166 | +// read_operations_per_second = 1000 |
| 167 | +// } |
| 168 | +// region { |
| 169 | +// region = "europe-west2" |
| 170 | +// networking_deployment_cidr = "192.168.1.0/24" |
| 171 | +// write_operations_per_second = 1000 |
| 172 | +// read_operations_per_second = 1000 |
| 173 | +// } |
| 174 | +// } |
| 175 | +//} |
| 176 | +// |
| 177 | +//resource "rediscloud_active_active_subscription_peering" "test" { |
| 178 | +// subscription_id = rediscloud_active_active_subscription.example.id |
| 179 | +// provider_name = "GCP" |
| 180 | +// gcp_project_id = "%s" |
| 181 | +// gcp_network_name = "%s" |
| 182 | +// |
| 183 | +// source_region = "europe-west2" |
| 184 | +//} |
| 185 | +//` |
0 commit comments